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
17 changes: 13 additions & 4 deletions tests/regression/torch/speculative/test_dflash.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
"dflash.dflash_architecture_config.num_hidden_layers=2",
]

# Steps, not epochs: accelerate runs one process per GPU, so an epoch is 500 steps on 1 GPU, 250 on 2.
_TRAIN_STEPS = 500
_RESUME_STEPS = 20


@pytest.fixture(scope="session")
def qwen3_model_name():
Expand All @@ -80,8 +84,8 @@ def test_dflash_training(qwen3_model_name, dflash_output_dir):
overrides = [
f"model.model_name_or_path={qwen3_model_name}",
f"training.output_dir={output_dir}",
"training.num_train_epochs=3",
"training.save_steps=500",
f"training.max_steps={_TRAIN_STEPS}",
f"training.save_steps={_TRAIN_STEPS}",
*_DFLASH_OVERRIDES,
]

Expand All @@ -108,7 +112,7 @@ def test_dflash_training(qwen3_model_name, dflash_output_dir):
first_loss = float(logs[0]["loss"])
final_loss = float(logs[-1]["loss"])
assert final_loss < first_loss, f"Loss did not decrease: {first_loss:.3f} -> {final_loss:.3f}"
# Sanity: final loss should be reasonable (baseline: ~1.1 on L40)
# Sanity: final loss should be reasonable (baseline: ~1.8 at step 500 on L40)
assert final_loss < 3.0, f"Final loss {final_loss:.3f} too high (expected < 3.0)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we observe loss to be ~1.8, do we want to tighten the assertion to 2.5 instead of 3?



Expand All @@ -118,7 +122,7 @@ def test_dflash_resume(qwen3_model_name, dflash_output_dir):
overrides = [
f"model.model_name_or_path={qwen3_model_name}",
f"training.output_dir={output_dir}",
"training.num_train_epochs=4",
f"training.max_steps={_TRAIN_STEPS + _RESUME_STEPS}",
"training.save_steps=5000",
*_DFLASH_OVERRIDES,
]
Expand All @@ -128,6 +132,11 @@ def test_dflash_resume(qwen3_model_name, dflash_output_dir):
"speculative_decoding",
)

with open(os.path.join(output_dir, "trainer_state.json")) as f:
state = json.load(f)
assert state["global_step"] == _TRAIN_STEPS + _RESUME_STEPS, state["global_step"]
assert any(h["step"] > _TRAIN_STEPS for h in state["log_history"]), "no log entry after resume"


def test_dflash_export(dflash_output_dir):
"""Export DFlash checkpoint to deployment format."""
Expand Down
Loading