Skip to content

Commit

Permalink
Make checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
Tcc0403 committed Feb 1, 2025
1 parent be52cfd commit ffc2c06
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions test/convergence/test_mini_models_with_logits.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@
try:
# Qwen2-VL is only available in transformers>4.44.2
from transformers.models.qwen2_vl.configuration_qwen2_vl import Qwen2VLConfig
from transformers.models.qwen2_vl.modeling_qwen2_vl import (
Qwen2VLForConditionalGeneration,
)
from transformers.models.qwen2_vl.modeling_qwen2_vl import Qwen2VLForConditionalGeneration

QWEN2_VL_AVAILABLE = True
except ImportError:
Expand Down Expand Up @@ -436,9 +434,7 @@ def run_mini_model(

model = create_model(model_name).to(dtype).to(device)
train_dataset = load_from_disk(DEFAULT_DATASET_PATH)
loader = DataLoader(
train_dataset, batch_size=16, shuffle=False, collate_fn=simple_collate_fn
)
loader = DataLoader(train_dataset, batch_size=16, shuffle=False, collate_fn=simple_collate_fn)
loader_iter = iter(loader)
optimizer = torch.optim.AdamW(model.parameters(), lr=lr)

Expand Down Expand Up @@ -473,9 +469,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
pytest.param(
"mini_mllama",
Expand Down Expand Up @@ -505,9 +499,7 @@ def run_mini_model(
1e-2,
1e-2,
marks=[
pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
pytest.mark.skipif(
not MLLAMA_AVAILABLE,
reason="Mllama not available in this version of transformers",
Expand All @@ -526,9 +518,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
pytest.param(
"mini_qwen2_vl",
Expand Down Expand Up @@ -558,9 +548,7 @@ def run_mini_model(
1e-2,
1e-2,
marks=[
pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
pytest.mark.skipif(
not QWEN2_VL_AVAILABLE,
reason="Qwen2-VL not available in this version of transformers",
Expand All @@ -579,9 +567,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
("mini_mistral", 32, 1e-4, torch.float32, 1e-8, 1e-5, 5e-3, 1e-5, 5e-3, 1e-5),
pytest.param(
Expand All @@ -595,9 +581,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
# TODO: mixtral is flaky so disable the test for now
# ("mini_mixtral", 32, 1e-4, torch.float32, 5e-4, 1e-4, 5e-3, 1e-5, 1e-2, 1e-5),
Expand Down Expand Up @@ -629,9 +613,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
("mini_gemma1.1", 32, 1e-4, torch.float32, 1e-8, 1e-4, 5e-3, 1e-5, 5e-3, 1e-5),
pytest.param(
Expand All @@ -645,9 +627,7 @@ def run_mini_model(
1e-2,
1e-2,
1e-2,
marks=pytest.mark.skipif(
not supports_bfloat16(), reason="bfloat16 not supported on this GPU"
),
marks=pytest.mark.skipif(not supports_bfloat16(), reason="bfloat16 not supported on this GPU"),
),
("mini_gemma2", 32, 1e-4, torch.float32, 1e-8, 1e-4, 5e-3, 1e-5, 5e-3, 1e-5),
# TODO: Gemma2 test for bf16 is not passing within the tolerance range, might be casting issue, need to investigate
Expand Down Expand Up @@ -682,13 +662,9 @@ def test_mini_model(
):
# Non-liger models should be initialized and tested first to avoid the module being overridden

expected_output = run_mini_model(
model_name=model_name, num_steps=num_steps, dtype=dtype, lr=lr
)
expected_output = run_mini_model(model_name=model_name, num_steps=num_steps, dtype=dtype, lr=lr)

actual_output = run_mini_model(
model_name=model_name, num_steps=num_steps, dtype=dtype, lr=lr, with_liger=True
)
actual_output = run_mini_model(model_name=model_name, num_steps=num_steps, dtype=dtype, lr=lr, with_liger=True)

# Compare every step of the loss
assert_verbose_allclose(
Expand All @@ -714,6 +690,4 @@ def test_mini_model(
actual_output["model"].named_parameters(),
strict=False,
):
assert_verbose_allclose(
expected_param[1], actual_param[1], atol=param_atol, rtol=param_rtol
)
assert_verbose_allclose(expected_param[1], actual_param[1], atol=param_atol, rtol=param_rtol)

0 comments on commit ffc2c06

Please sign in to comment.