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 overriding of rope_scaling config #644

Merged
merged 8 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions llmfoundry/models/hf/hf_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(self, om_model_config: Union[DictConfig,
)

attr = getattr(config, k)
# attempt to disallow typos in nested configs
if isinstance(attr, Mapping):
vchiley marked this conversation as resolved.
Show resolved Hide resolved
extra_keys = [
_k for _k in v.keys() if _k not in attr.keys()
Expand All @@ -120,6 +121,10 @@ def __init__(self, om_model_config: Union[DictConfig,
f'Expected (a subset of) keys: {list(attr.keys())}.'
)
getattr(config, k).update(v)
# necessary case to allow for rope_scaling to be overriden in llama config
elif attr is None and isinstance(v, Mapping):
setattr(config, k, {})
getattr(config, k).update(v)
else:
setattr(config, k, v)

Expand Down
25 changes: 25 additions & 0 deletions tests/test_hf_config.py
dakinggg marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,28 @@ def test_hf_config_override(
assert getattr(hf_model.config, k)[_k] == _v
else:
assert getattr(hf_model.config, k) == v


def test_rope_scaling_override():
model_cfg = {
'name': 'hf_causal_lm',
'pretrained_model_name_or_path': 'meta-llama/Llama-2-7b-hf',
'config_overrides': {
'num_hidden_layers': 2,
'hidden_size': 32,
'intermediate_size': 64,
'rope_scaling': {
'type': 'dynamic',
'factor': 0.5
}
},
'use_auth_token': True,
'pretrained': False,
'init_device': 'cpu',
}
model_cfg = om.create(model_cfg)

model = COMPOSER_MODEL_REGISTRY[model_cfg.name](model_cfg, tokenizer=None)
# This would error if the config isn't parsed into a proper dictionary
model.get_metadata()
assert model.config.rope_scaling == {'type': 'dynamic', 'factor': 0.5}
Loading