chore: fix lint, format, type errors
- ruff format: 2 files reformatted - ruff check: fix import sort in scripts/infer_pytorch.py - ty: suppress tree_flatten arg-type (MLX stub imprecision) and optional torch import Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f73aabf5af
commit
f30ab9255b
@ -15,10 +15,10 @@ from pathlib import Path
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
from PIL import Image
|
||||
|
||||
# Reuse the GreenFormer and loading logic from dump script
|
||||
from dump_pytorch_reference import IMG_SIZE, GreenFormer, load_checkpoint
|
||||
from PIL import Image
|
||||
|
||||
IMAGENET_MEAN = torch.tensor([0.485, 0.456, 0.406]).reshape(1, 3, 1, 1)
|
||||
IMAGENET_STD = torch.tensor([0.229, 0.224, 0.225]).reshape(1, 3, 1, 1)
|
||||
@ -94,7 +94,7 @@ def main() -> None:
|
||||
# Composite over green
|
||||
alpha_f = alpha_np.astype(np.float32) / 255.0
|
||||
green = np.array([0, 177, 64], dtype=np.float32)
|
||||
comp_np = (fg_np.astype(np.float32) * alpha_f[..., None] + green * (1 - alpha_f[..., None]))
|
||||
comp_np = fg_np.astype(np.float32) * alpha_f[..., None] + green * (1 - alpha_f[..., None])
|
||||
comp_np = comp_np.clip(0, 255).astype(np.uint8)
|
||||
|
||||
# Save
|
||||
|
||||
@ -116,9 +116,7 @@ def list_assets(release: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
return release.get("assets", [])
|
||||
|
||||
|
||||
def find_asset(
|
||||
release: dict[str, Any], asset_name: str | None = None
|
||||
) -> dict[str, Any]:
|
||||
def find_asset(release: dict[str, Any], asset_name: str | None = None) -> dict[str, Any]:
|
||||
"""Find a specific asset in a release, or infer from platform."""
|
||||
assets = list_assets(release)
|
||||
target = asset_name or default_asset_name()
|
||||
@ -275,9 +273,7 @@ def download_asset(
|
||||
)
|
||||
_console.print("[green]Checksum OK[/green]")
|
||||
else:
|
||||
_console.print(
|
||||
"[yellow]No checksum file found — skipping verification[/yellow]"
|
||||
)
|
||||
_console.print("[yellow]No checksum file found — skipping verification[/yellow]")
|
||||
|
||||
# atomic rename
|
||||
partial_path.rename(final_path)
|
||||
|
||||
@ -23,7 +23,7 @@ EXPECTED_KEY_COUNT = 365
|
||||
|
||||
def _torch_available() -> bool:
|
||||
try:
|
||||
import torch # noqa: F401
|
||||
import torch # noqa: F401 # type: ignore[import-not-found]
|
||||
|
||||
return True
|
||||
except ImportError:
|
||||
|
||||
@ -247,7 +247,7 @@ def test_fused_decode_matches_unfused() -> None:
|
||||
mx.eval(model_unfused.parameters()) # noqa: S307
|
||||
|
||||
model_fused = GreenFormer(img_size=SMALL_IMG_SIZE, fused_decode=True)
|
||||
model_fused.load_weights(tree_flatten(model_unfused.parameters()))
|
||||
model_fused.load_weights(tree_flatten(model_unfused.parameters())) # type: ignore[arg-type]
|
||||
mx.eval(model_fused.parameters()) # noqa: S307
|
||||
|
||||
out_u = model_unfused(x)
|
||||
@ -276,7 +276,7 @@ def test_fp32_default_unchanged() -> None:
|
||||
# Same weights via flattened tree
|
||||
from mlx.utils import tree_flatten
|
||||
|
||||
model_explicit.load_weights(tree_flatten(model_default.parameters()))
|
||||
model_explicit.load_weights(tree_flatten(model_default.parameters())) # type: ignore[arg-type]
|
||||
mx.eval(model_explicit.parameters()) # noqa: S307
|
||||
|
||||
out_default = model_default(x)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user