Skip to content

Commit 115823c

Browse files
justinchubyCopilot
andcommitted
Apply ruff format to satisfy the RUFF-FORMAT lint gate
The CI Lint job runs lintrunner with two linters: RUFF (ruff check) and RUFF-FORMAT (ruff format --check). Only ruff check was run previously, so three long dict/call literals in the preflight modules and streaming test were left un-wrapped past the 95-column formatter width. Wrap them via `ruff format` (ruff 0.16.2, --config=pyproject.toml). Pure formatting; no behavior change. The rebase-touched __main__.py was already format-clean. Co-authored-by: Copilot <[email protected]>
1 parent e452dab commit 115823c

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

‎src/mobius/integrations/_weight_loading_stream_test.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def _save_sharded(
7272
if not shard_names:
7373
continue
7474
fn = f"model-{i + 1:05d}-of-{n_shards:05d}.safetensors"
75-
safetensors.torch.save_file(
76-
{n: state[n] for n in shard_names}, str(directory / fn)
77-
)
75+
safetensors.torch.save_file({n: state[n] for n in shard_names}, str(directory / fn))
7876
for n in shard_names:
7977
weight_map[n] = fn
8078
(directory / "model.safetensors.index.json").write_text(
@@ -102,9 +100,7 @@ def test_single_file_streams_and_roundtrips(self, tmp_path, monkeypatch):
102100
def _no_hub(*_a, **_k):
103101
raise AssertionError("streaming a local dir must not call the Hub")
104102

105-
monkeypatch.setattr(
106-
"mobius.integrations._weight_loading.hf_hub_download", _no_hub
107-
)
103+
monkeypatch.setattr("mobius.integrations._weight_loading.hf_hub_download", _no_hub)
108104
model = _fresh_model()
109105
state = _make_checkpoint_state(model)
110106
_save_single(state, tmp_path)
@@ -172,9 +168,7 @@ def test_missing_weight_tolerated_when_not_passthrough(self, tmp_path):
172168
del state[dropped]
173169
_save_single(state, tmp_path)
174170

175-
assigned = stream_safetensors_to_model(
176-
model, str(tmp_path), require_passthrough=False
177-
)
171+
assigned = stream_safetensors_to_model(model, str(tmp_path), require_passthrough=False)
178172
assert dropped not in assigned
179173

180174
def test_fp8_checkpoint_refuses_rather_than_dropping_scale(self, tmp_path):

‎src/mobius/preflight.py‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ def estimate_budget(
395395
# The weights loaded at runtime are the weights that were exported, so the
396396
# exported artifact size is the right default VRAM footprint (an int4-qmoe
397397
# export loads int4, not the bf16 source).
398-
vram_base = output_bytes if target_dtype_bytes is None else int(param_count * target_dtype_bytes)
398+
vram_base = (
399+
output_bytes if target_dtype_bytes is None else int(param_count * target_dtype_bytes)
400+
)
399401
vram_weights = int(vram_base * (1 + vram_headroom_frac))
400402

401403
return Budget(
@@ -434,9 +436,7 @@ def _free_bytes(path: pathlib.Path) -> int:
434436
def _same_device(a: pathlib.Path, b: pathlib.Path) -> bool:
435437
"""True when two paths resolve to the same filesystem (shared free space)."""
436438
try:
437-
return (
438-
os.stat(_existing_ancestor(a)).st_dev == os.stat(_existing_ancestor(b)).st_dev
439-
)
439+
return os.stat(_existing_ancestor(a)).st_dev == os.stat(_existing_ancestor(b)).st_dev
440440
except OSError:
441441
return False
442442

@@ -469,9 +469,7 @@ def _available_ram_bytes() -> int | None:
469469
return None
470470

471471

472-
def check_disk(
473-
kind: str, path: pathlib.Path, required: int, margin_frac: float
474-
) -> SpaceCheck:
472+
def check_disk(kind: str, path: pathlib.Path, required: int, margin_frac: float) -> SpaceCheck:
475473
free = _free_bytes(path)
476474
ok = free * (1 - margin_frac) >= required
477475
return SpaceCheck(
@@ -637,9 +635,7 @@ def run_preflight(
637635
checks.append(
638636
check_disk("disk:download", download_path, download_required, margin_frac)
639637
)
640-
checks.append(
641-
check_disk("disk:output", output_path, budget.output_bytes, margin_frac)
642-
)
638+
checks.append(check_disk("disk:output", output_path, budget.output_bytes, margin_frac))
643639
checks.append(check_ram(budget.peak_ram_bytes, margin_frac))
644640

645641
for chk in checks:

‎src/mobius/preflight_test.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ def _write_sharded(tmp_path: pathlib.Path, n_shards: int = 2) -> None:
4545
)
4646
weight_map[f"w{i}"] = fn
4747
(tmp_path / "model.safetensors.index.json").write_text(
48-
json.dumps({"metadata": {"total_size": n_shards * 1024 * 1024 * 2}, "weight_map": weight_map})
48+
json.dumps(
49+
{"metadata": {"total_size": n_shards * 1024 * 1024 * 2}, "weight_map": weight_map}
50+
)
4951
)
5052

5153

@@ -98,7 +100,10 @@ def test_local_missing_raises(self, tmp_path):
98100
resolve_source(str(tmp_path))
99101

100102
def test_hub_resolves_shards_and_sizes(self, tmp_path, monkeypatch):
101-
weight_map = {"w0": "model-00001-of-00002.safetensors", "w1": "model-00002-of-00002.safetensors"}
103+
weight_map = {
104+
"w0": "model-00001-of-00002.safetensors",
105+
"w1": "model-00002-of-00002.safetensors",
106+
}
102107
_fake_hub(tmp_path, monkeypatch, weight_map)
103108
info = types.SimpleNamespace(
104109
sha="deadbeef",
@@ -323,7 +328,12 @@ def test_identity_drift_refuses(self, tmp_path, monkeypatch):
323328
monkeypatch.setattr(preflight, "_available_ram_bytes", lambda: 10**15)
324329
state_file = tmp_path / "state.json"
325330
state_file.write_text(
326-
json.dumps({"commit_sha": "OLDSHA", "validated_shards": ["model-00001-of-00001.safetensors"]})
331+
json.dumps(
332+
{
333+
"commit_sha": "OLDSHA",
334+
"validated_shards": ["model-00001-of-00001.safetensors"],
335+
}
336+
)
327337
)
328338
info = types.SimpleNamespace(
329339
sha="NEWSHA",

0 commit comments

Comments
 (0)