Skip to content
Merged
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
18 changes: 17 additions & 1 deletion slime/backends/megatron_utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ def equal(x, y):
if hasattr(hf_config, "text_config"):
hf_config = hf_config.text_config

# Some models store rope_theta inside rope_parameters dict rather than
# as a top-level attribute. Prefer the dict value when available so
# the validation doesn't compare against a stale class default.
rope_params = getattr(hf_config, "rope_parameters", None)
if isinstance(rope_params, dict) and "rope_theta" in rope_params:
_hf_rope_theta = rope_params["rope_theta"]
else:
_hf_rope_theta = getattr(hf_config, "rope_theta", None)

for hf_config_name, megatron_config_name, compare_fn in [
("hidden_size", "hidden_size", equal),
("num_attention_heads", "num_attention_heads", equal),
("num_hidden_layers", "num_layers", equal),
("intermediate_size", "ffn_hidden_size", equal),
("tie_word_embeddings", "untie_embeddings_and_output_weights", lambda x, y: not x == y),
("rms_norm_eps", "norm_epsilon", equal),
("rope_theta", "rotary_base", equal),
]:
if hasattr(hf_config, hf_config_name):
if not compare_fn(getattr(hf_config, hf_config_name), getattr(args, megatron_config_name)):
Expand All @@ -56,6 +64,14 @@ def equal(x, y):
f"{megatron_config_name} {getattr(args, megatron_config_name)}, please check the config."
)

# Validate rope_theta separately using the resolved value
if _hf_rope_theta is not None:
if not equal(_hf_rope_theta, getattr(args, "rotary_base", None)):
errors.append(
f"rope_theta in hf config {_hf_rope_theta} is not equal to "
f"rotary_base {getattr(args, 'rotary_base', None)}, please check the config."
)

if len(errors) > 0:
raise AssertionError("hf_validate_args failed: " + "; ".join(errors))

Expand Down