Skip to content

Commit

Permalink
Fix AttributeError in huggingface.py When 'model_type' is Missing (#1489
Browse files Browse the repository at this point in the history
)

* model_type attribute error

Getting attribute error when using a model without a 'model_type'

* fix w/ and w/out the 'model_type' specification

* use getattr(), also fix other config.model_type reference

* Update huggingface.py

---------

Co-authored-by: Hailey Schoelkopf <[email protected]>
  • Loading branch information
richwardle and haileyschoelkopf committed Feb 27, 2024
1 parent a08eb87 commit cc771ec
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lm_eval/models/huggingface.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def __init__(
elif self.tokenizer.eos_token:
self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
else:
if self.config.model_type == "qwen":
if getattr(self.config, "model_type", None) == "qwen":
# Qwen's trust_remote_code tokenizer does not allow for adding special tokens
self.tokenizer.pad_token = "<|endoftext|>"
elif (
Expand All @@ -268,11 +268,11 @@ def __init__(

# TODO: override this for Gemma
self.add_bos_token = add_bos_token
if self.config.model_type == "gemma":
if getattr(self.config, "model_type", None) == "gemma":
self.add_bos_token = True
eval_logger.info(
"Model is of type 'gemma', will use a BOS token as Gemma underperforms without it."
f"Model type is '{self.config.model_type}', a BOS token will be used as Gemma underperforms without it."
)
self.add_bos_token = True

self._max_length = max_length

Expand Down

0 comments on commit cc771ec

Please sign in to comment.