Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gracefully fail loading models #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,29 @@ def load_models() -> Dict[str, Tuple[PreTrainedModel, PreTrainedTokenizer, Model
models = {}
for family in config.MODEL_FAMILIES.values():
for model_config in family:
backend_config = model_config.backend

logger.info(f"Loading tokenizer for {backend_config.repository}")
tokenizer = AutoTokenizer.from_pretrained(backend_config.repository, add_bos_token=False, use_fast=False)

logger.info(
f"Loading model {backend_config.repository} with adapter {backend_config.adapter} in {config.TORCH_DTYPE}"
)
# We set use_fast=False since LlamaTokenizerFast takes a long time to init
model = AutoDistributedModelForCausalLM.from_pretrained(
backend_config.repository,
active_adapter=backend_config.adapter,
torch_dtype=config.TORCH_DTYPE,
initial_peers=config.INITIAL_PEERS,
max_retries=3,
)
model = model.to(config.DEVICE)

for key in [backend_config.key] + list(backend_config.aliases):
models[key] = model, tokenizer, backend_config
try:
backend_config = model_config.backend

logger.info(f"Loading tokenizer for {backend_config.repository}")
tokenizer = AutoTokenizer.from_pretrained(backend_config.repository, add_bos_token=False, use_fast=False)

logger.info(
f"Loading model {backend_config.repository} with adapter {backend_config.adapter} in {config.TORCH_DTYPE}"
)
# We set use_fast=False since LlamaTokenizerFast takes a long time to init
model = AutoDistributedModelForCausalLM.from_pretrained(
backend_config.repository,
active_adapter=backend_config.adapter,
torch_dtype=config.TORCH_DTYPE,
initial_peers=config.INITIAL_PEERS,
max_retries=3,
)
model = model.to(config.DEVICE)

for key in [backend_config.key] + list(backend_config.aliases):
models[key] = model, tokenizer, backend_config
except Exception as e:
logger.error(f"Failed to load model {model_config.backend.repository} due to {e}")
return models


Expand Down