Skip to content

Commit 8bcd801

Browse files
Pipeline failure fixes : Fixing Lint failures on test, example and base file
1 parent d8d9ca0 commit 8bcd801

3 files changed

Lines changed: 33 additions & 71 deletions

File tree

examples/benchmarks/pytorch_deterministic_example.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,33 @@
3737
]
3838

3939
DEFAULT_PARAMS = {
40-
"bert-large": "--batch_size 1 --seq_len 128 --num_warmup 1 --num_steps 300 --precision float32 "
40+
"bert-large":
41+
"--batch_size 1 --seq_len 128 --num_warmup 1 --num_steps 300 --precision float32 "
4142
"--model_action train --deterministic --deterministic_seed 42 --check_frequency 20",
42-
"gpt2-small": "--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 128 --precision float32 "
43+
"gpt2-small":
44+
"--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 128 --precision float32 "
4345
"--model_action train --deterministic --deterministic_seed 42 --check_frequency 20",
44-
"llama2-7b": "--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 512 --precision float32 --model_action train "
46+
"llama2-7b":
47+
"--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 512 --precision float32 --model_action train "
4548
"--deterministic --deterministic_seed 42 --check_frequency 20",
46-
"mixtral-8x7b": "--hidden_size=4096 --num_hidden_layers=32 --num_attention_heads=32 --intermediate_size=14336 "
49+
"mixtral-8x7b":
50+
"--hidden_size=4096 --num_hidden_layers=32 --num_attention_heads=32 --intermediate_size=14336 "
4751
"--num_key_value_heads=8 --max_position_embeddings=32768 --router_aux_loss_coef=0.02 "
4852
"--deterministic --deterministic_seed 42 --check_frequency 20",
49-
"resnet101": "--batch_size 192 --precision float32 float32 --num_warmup 64 --num_steps 512 --sample_count 8192 "
53+
"resnet101":
54+
"--batch_size 192 --precision float32 float32 --num_warmup 64 --num_steps 512 --sample_count 8192 "
5055
"--pin_memory --model_action train --deterministic --deterministic_seed 42 --check_frequency 20",
51-
"lstm": "--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 256 --precision float16 "
56+
"lstm":
57+
"--batch_size 1 --num_steps 300 --num_warmup 1 --seq_len 256 --precision float16 "
5258
"--model_action train --deterministic --deterministic_seed 42 --check_frequency 20",
5359
}
5460

5561

5662
def main():
57-
parser = argparse.ArgumentParser(
58-
description="Unified PyTorch deterministic training example."
59-
)
60-
parser.add_argument(
61-
"--model", type=str, choices=MODEL_CHOICES, required=True, help="Model to run."
62-
)
63-
parser.add_argument(
64-
"--generate-log", action="store_true", help="Enable fingerprint log generation."
65-
)
66-
parser.add_argument(
67-
"--log-path", type=str, default=None, help="Path to save fingerprint log."
68-
)
63+
parser = argparse.ArgumentParser(description="Unified PyTorch deterministic training example.")
64+
parser.add_argument("--model", type=str, choices=MODEL_CHOICES, required=True, help="Model to run.")
65+
parser.add_argument("--generate-log", action="store_true", help="Enable fingerprint log generation.")
66+
parser.add_argument("--log-path", type=str, default=None, help="Path to save fingerprint log.")
6967
parser.add_argument(
7068
"--compare-log",
7169
type=str,
@@ -92,9 +90,7 @@ def main():
9290
parameters += f" --compare-log {args.compare_log}"
9391

9492
print(f"Running {args.model} with parameters: {parameters}")
95-
context = BenchmarkRegistry.create_benchmark_context(
96-
args.model, parameters=parameters, framework=Framework.PYTORCH
97-
)
93+
context = BenchmarkRegistry.create_benchmark_context(args.model, parameters=parameters, framework=Framework.PYTORCH)
9894
benchmark = BenchmarkRegistry.launch_benchmark(context)
9995
print(f"Benchmark finished. Return code: {benchmark.return_code}")
10096
if hasattr(benchmark, "_model_run_metadata"):

superbench/benchmarks/model_benchmarks/pytorch_base.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def _assign_model_run_metadata(self, precision, extra_keys=None):
9999
# Common metadata keys
100100
metadata = {
101101
"model_name": self._name,
102-
"precision": (
103-
precision.value if hasattr(precision, "value") else str(precision)
104-
),
102+
"precision": (precision.value if hasattr(precision, "value") else str(precision)),
105103
"seed": getattr(self._args, "deterministic_seed", None),
106104
"batch_size": getattr(self._args, "batch_size", None),
107105
"seq_len": getattr(self._args, "seq_len", None),
@@ -126,9 +124,7 @@ def _assign_model_run_metadata(self, precision, extra_keys=None):
126124
self._model_run_metadata = metadata
127125
return None
128126

129-
def record_determinism_fingerprint(
130-
self, curr_step, loss, logits, periodic, check_frequency
131-
):
127+
def record_determinism_fingerprint(self, curr_step, loss, logits, periodic, check_frequency):
132128
"""Centralized logic for recording per-step loss and periodic fingerprints for deterministic runs.
133129
134130
Args:
@@ -144,9 +140,7 @@ def record_determinism_fingerprint(
144140
except Exception:
145141
v = None
146142
# Periodic fingerprint logging
147-
if getattr(self._args, "deterministic", False) and (
148-
curr_step % check_frequency == 0
149-
):
143+
if getattr(self._args, "deterministic", False) and (curr_step % check_frequency == 0):
150144
# 1) Loss fingerprint (only at fingerprinting frequency)
151145
try:
152146
if "loss" in periodic and v is not None:
@@ -160,8 +154,7 @@ def record_determinism_fingerprint(
160154
if logits is not None:
161155
act_mean = (
162156
float(logits[0].detach().float().mean().item())
163-
if hasattr(logits[0], "detach")
164-
else float(logits[0])
157+
if hasattr(logits[0], "detach") else float(logits[0])
165158
)
166159
logger.info(f"ActMean at step {curr_step}: {act_mean}")
167160
periodic["act_mean"].append(act_mean)
@@ -286,9 +279,7 @@ def _preprocess(self):
286279
has_cmp = getattr(self._args, "compare_log", None)
287280
if not has_gen and not has_cmp:
288281
setattr(self._args, "generate_log", True)
289-
logger.info(
290-
"Deterministic run detected with no log options; defaulting to --generate-log."
291-
)
282+
logger.info("Deterministic run detected with no log options; defaulting to --generate-log.")
292283
except Exception:
293284
# Never fail preprocessing due to optional defaulting
294285
pass
@@ -611,19 +602,11 @@ def _process_info(self, model_action, precision, info):
611602
"float64": "fp64",
612603
"bfloat16": "bf16",
613604
}
614-
prec_value = (
615-
precision.value if hasattr(precision, "value") else str(precision)
616-
)
605+
prec_value = (precision.value if hasattr(precision, "value") else str(precision))
617606
prefix = precision_metric.get(prec_value, prec_value)
618607
metric_loss = f"{prefix}_{model_action}_loss"
619-
if (
620-
"loss" in info
621-
and isinstance(info["loss"], list)
622-
and len(info["loss"]) > 0
623-
):
624-
self._result.add_raw_data(
625-
metric_loss, info["loss"], self._args.log_raw_data
626-
)
608+
if ("loss" in info and isinstance(info["loss"], list) and len(info["loss"]) > 0):
609+
self._result.add_raw_data(metric_loss, info["loss"], self._args.log_raw_data)
627610
except Exception as e:
628611
logger.error(
629612
f"Exception in _process_info: {e}\n"

tests/benchmarks/model_benchmarks/test_pytorch_determinism_all.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import pytest
1010
from superbench.benchmarks import BenchmarkRegistry, Platform, Framework, ReturnCode
1111

12-
1312
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
1413

1514

@@ -92,9 +91,7 @@ def test_pytorch_model_determinism(model_name, params):
9291

9392
# Run with compare-log for success
9493
extra_args = f"--compare-log {log_path} --check_frequency 10"
95-
benchmark_compare, _ = run_deterministic_benchmark(
96-
model_name, params, log_path, extra_args
97-
)
94+
benchmark_compare, _ = run_deterministic_benchmark(model_name, params, log_path, extra_args)
9895
assert benchmark_compare and benchmark_compare.return_code == ReturnCode.SUCCESS
9996

10097
os.remove(log_path)
@@ -138,33 +135,19 @@ def test_pytorch_model_nondeterministoc_default(model_name, params):
138135
)
139136

140137
benchmark = BenchmarkRegistry.launch_benchmark(context)
141-
assert (
142-
benchmark and benchmark.return_code == ReturnCode.SUCCESS
143-
), "Benchmark did not run successfully."
138+
assert (benchmark and benchmark.return_code == ReturnCode.SUCCESS), "Benchmark did not run successfully."
144139
args = benchmark._args
145140
assert args.deterministic is False, "Expected deterministic to be False by default."
146-
assert (
147-
getattr(args, "generate_log", False) is False
148-
), "Expected generate_log to be False by default."
149-
assert (
150-
getattr(args, "log_path", None) is None
151-
), "Expected log_path to be None by default."
152-
assert (
153-
getattr(args, "compare_log", None) is None
154-
), "Expected compare_log to be None by default."
155-
assert (
156-
getattr(args, "check_frequency", None) == 100
157-
), "Expected check_frequency to be 100 by default."
141+
assert (getattr(args, "generate_log", False) is False), "Expected generate_log to be False by default."
142+
assert (getattr(args, "log_path", None) is None), "Expected log_path to be None by default."
143+
assert (getattr(args, "compare_log", None) is None), "Expected compare_log to be None by default."
144+
assert (getattr(args, "check_frequency", None) == 100), "Expected check_frequency to be 100 by default."
158145

159146
# Periodic fingerprints exist but are empty when not deterministic
160-
assert hasattr(
161-
benchmark, "_model_run_periodic"
162-
), "Benchmark missing _model_run_periodic attribute."
147+
assert hasattr(benchmark, "_model_run_periodic"), "Benchmark missing _model_run_periodic attribute."
163148
periodic = benchmark._model_run_periodic
164149
assert isinstance(periodic, dict), "_model_run_periodic should be a dict."
165150
for key in ("loss", "act_mean", "step"):
166151
assert key in periodic, f"Key '{key}' missing in _model_run_periodic."
167-
assert (
168-
len(periodic[key]) == 0
169-
), f"Expected empty list for periodic['{key}'], got {periodic[key]}."
152+
assert (len(periodic[key]) == 0), f"Expected empty list for periodic['{key}'], got {periodic[key]}."
170153
pass

0 commit comments

Comments
 (0)