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

Fix llama2 generation config #468

Merged
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions swift/llm/utils/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,13 @@ def get_model_tokenizer(
generation_config_path) and generation_config is None:
model.generation_config = GenerationConfig.from_pretrained(
model_dir)
generation_config = getattr(model, 'generation_config', None)
# fix llama2 bug
if (generation_config is not None
and 0 < generation_config.temperature < 1
and generation_config.do_sample is False):
model.generation_config.do_sample = True
logger.warning('Setting model.generation_config.do_sample: True')
return model, tokenizer


Expand Down
3 changes: 2 additions & 1 deletion swift/llm/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,12 @@ def get_max_model_len(config: PretrainedConfig) -> Optional[int]:
INF = int(1e9)
max_model_len = INF
possible_keys = [
'seq_len', # qwen, chatglm
'seq_length', # qwen, chatglm
'max_position_embeddings', # qwen1.5, llama2
'n_positions', # polylm, phi-2
'model_max_length', # baichuan2
# others
'seq_len',
'max_seq_len',
'max_sequence_length',
'max_seq_length',
Expand Down
Loading