Skip to content

Commit 4683db9

Browse files
committed
address comments
1 parent e6fcf3a commit 4683db9

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

src/maxtext/checkpoint_conversion/to_maxtext.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def _merged_getter(key):
822822
def main(
823823
args: Sequence[str],
824824
lazy_load_tensors: bool = False,
825-
eager_load_method: str = "transformers",
825+
eager_load_method: str = "safetensors",
826826
hf_model_path: str | None = None,
827827
revision: str | None = None,
828828
save_dtype: str = "bfloat16",
@@ -909,9 +909,9 @@ def main(
909909
# (e.g., Multi-Token Prediction weights (`layers.61`) in DeepSeek-V3).
910910
#
911911
# Recommendation:
912-
# - Use 'transformers' as the default for backward compatibility of mapping.
913-
# - 'safetensors' is an interchangeable and valid alternative for most models,
914-
# and is strictly required if the model or specific weights lack Transformers support.
912+
# - Use 'safetensors' as the default. Since transformers 5.8.0, model initialization
913+
# changed and the 'transformers' method may produce different key structures.
914+
# - Use 'transformers' only if explicitly needed for backward-compatible key mapping.
915915
if eager_load_method == "transformers":
916916
max_logging.log("Eager load with Transformers backend, from_pretrained with auto dtype")
917917
# For auto mode, loaded dtype is the same as `dtype` specified in config.json (or `torch_dtype` for older version)

tests/integration/checkpoint_conversion_test.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,29 @@ def test_qwen3_30b_a3b_roundtrip_conversion(self):
3232
model_name = "qwen3-30b-a3b"
3333
base_num_decoder_layers = 2
3434
with tempfile.TemporaryDirectory() as tmpdir:
35-
cmd = [
35+
to_mt_cmd = [
3636
sys.executable,
3737
"-m",
3838
"maxtext.checkpoint_conversion.to_maxtext",
39-
"src/maxtext/configs/base.yml",
4039
f"model_name={model_name}",
4140
f"base_output_directory={tmpdir}",
4241
f"base_num_decoder_layers={base_num_decoder_layers}",
4342
"override_model_config=True",
4443
"scan_layers=False",
45-
"weight_dtype=bfloat16",
4644
"hardware=cpu",
4745
"skip_jax_distributed_system=True",
4846
"checkpoint_storage_use_ocdbt=False",
4947
"checkpoint_storage_use_zarr3=False",
48+
"--save_dtype=bfloat16",
5049
"--lazy_load_tensors=True",
5150
]
5251
env = os.environ.copy()
5352
env["JAX_PLATFORMS"] = "cpu"
5453
env["HF_HOME"] = tmpdir
5554

56-
print("Running checkpoint conversion command:", " ".join(cmd))
55+
print("Running checkpoint conversion command:", " ".join(to_mt_cmd))
5756
# Inherit stdout and stderr from the parent process to stream logs in real time
58-
subprocess.run(cmd, env=env, check=True)
57+
subprocess.run(to_mt_cmd, env=env, check=True)
5958

6059
# Verify output directory exists and contains items
6160
# Output structure: tmpdir/0/items
@@ -65,7 +64,7 @@ def test_qwen3_30b_a3b_roundtrip_conversion(self):
6564

6665
# Roundtrip conversion back to HuggingFace format
6766
expected_hf_dir = os.path.join(tmpdir, "hf_safetensor", "qwen3-30b-a3b")
68-
hf_cmd = [
67+
to_hf_cmd = [
6968
sys.executable,
7069
"-m",
7170
"maxtext.checkpoint_conversion.to_huggingface",
@@ -80,8 +79,8 @@ def test_qwen3_30b_a3b_roundtrip_conversion(self):
8079
"skip_jax_distributed_system=True",
8180
"--override_model_architecture=True",
8281
]
83-
print("Running roundtrip checkpoint conversion command (to HF):", " ".join(hf_cmd))
84-
subprocess.run(hf_cmd, env=env, check=True)
82+
print("Running roundtrip checkpoint conversion command (to HF):", " ".join(to_hf_cmd))
83+
subprocess.run(to_hf_cmd, env=env, check=True)
8584

8685
# Verify HF output directory exists and contains safetensors/config files
8786
self.assertTrue(

0 commit comments

Comments
 (0)