Skip to content

Commit 447e9ba

Browse files
author
Sameer Alam
committed
fix: all ruff lint errors resolved
1 parent 943283e commit 447e9ba

11 files changed

Lines changed: 40 additions & 14 deletions

File tree

‎src/specinferkit/algorithms/eagle.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ class EagleAlgorithm(SpeculativeDecodingAlgorithm):
77
"""Eagle-3: Auto-regressive draft model with feature-level fusion."""
88

99
def __init__(self, config: AlgorithmConfig | None = None):
10-
super().__init__(config or AlgorithmConfig(name="eagle", target_model_name="", draft_model_name=""))
10+
super().__init__(
11+
config or AlgorithmConfig(
12+
name="eagle", target_model_name="", draft_model_name=""
13+
)
14+
)
1115

1216
def prepare_draft_model(self, target_model):
1317
return {"status": "ready", "draft_type": "auto-regressive"}

‎src/specinferkit/algorithms/medusa.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ class MedusaAlgorithm(SpeculativeDecodingAlgorithm):
77
"""Medusa: Multiple draft heads for parallel token prediction."""
88

99
def __init__(self, config: AlgorithmConfig | None = None):
10-
super().__init__(config or AlgorithmConfig(name="medusa", target_model_name="", draft_model_name=""))
10+
super().__init__(
11+
config or AlgorithmConfig(
12+
name="medusa", target_model_name="", draft_model_name=""
13+
)
14+
)
1115

1216
def prepare_draft_model(self, target_model):
1317
return {"status": "ready", "draft_type": "multiple-heads"}

‎src/specinferkit/cli/main.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ def build_parser():
2424
p_train.add_argument("--mode", choices=["online", "standard"], default="online")
2525
p_train.add_argument("--batch-size", type=int)
2626
p_train.add_argument("--max-steps", type=int)
27-
p_train.add_argument("--algorithm", choices=["eagle", "medusa", "self-spec", "dspark", "dflash"])
27+
p_train.add_argument(
28+
"--algorithm", choices=["eagle", "medusa", "self-spec", "dspark", "dflash"]
29+
)
2830

2931
p_eval = sub.add_parser("eval", help="Evaluate a trained checkpoint")
3032
p_eval.add_argument("--checkpoint", required=True, help="Path to checkpoint")
@@ -44,7 +46,9 @@ def build_parser():
4446

4547
p_quantize = sub.add_parser("quantize", help="Quantize target cache")
4648
p_quantize.add_argument("--cache-path", required=True)
47-
p_quantize.add_argument("--dtype", choices=["float8_e4m3fn", "float8_e5m2"], default="float8_e4m3fn")
49+
p_quantize.add_argument(
50+
"--dtype", choices=["float8_e4m3fn", "float8_e5m2"], default="float8_e4m3fn"
51+
)
4852
p_quantize.add_argument("--output", required=True)
4953

5054
return parser

‎src/specinferkit/data/dataset.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Dataset classes for speculative decoding training."""
22

33
import json
4+
45
import torch
56
from torch.utils.data import Dataset
67

@@ -23,7 +24,7 @@ def __init__(
2324
self._load_data()
2425

2526
def _load_data(self):
26-
with open(self.data_path, "r") as f:
27+
with open(self.data_path) as f:
2728
self.examples = [json.loads(line) for line in f]
2829

2930
def __len__(self):
@@ -33,4 +34,8 @@ def __getitem__(self, idx):
3334
example = self.examples[idx]
3435
input_ids = torch.tensor(example["input_ids"][: self.max_length], dtype=torch.long)
3536
labels = torch.tensor(example["labels"][: self.max_length], dtype=torch.long)
36-
return {"input_ids": input_ids, "labels": labels, "attention_mask": torch.ones_like(input_ids)}
37+
return {
38+
"input_ids": input_ids,
39+
"labels": labels,
40+
"attention_mask": torch.ones_like(input_ids),
41+
}

‎src/specinferkit/data/download.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Download utilities for datasets."""
22
import os
3+
34
import requests
45
from tqdm import tqdm
56

‎src/specinferkit/data/streaming.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Streaming cache for online training mode."""
22

33
from collections.abc import Iterator
4+
45
import torch
56

67

@@ -28,7 +29,11 @@ def generate(self, input_ids: torch.Tensor) -> dict:
2829
outputs = self.target_model(input_ids.to(self.device))
2930
return {
3031
"logits": outputs.logits.cpu(),
31-
"hidden_states": outputs.hidden_states[-1].cpu() if hasattr(outputs, "hidden_states") else None,
32+
"hidden_states": (
33+
outputs.hidden_states[-1].cpu()
34+
if hasattr(outputs, "hidden_states")
35+
else None
36+
),
3237
}
3338

3439
def __iter__(self) -> Iterator[dict]:

‎src/specinferkit/models/registry.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ class ModelRegistry:
2424
def list_supported(cls) -> list:
2525
result = []
2626
for family, variants in SUPPORTED_MODELS.items():
27-
for size, config in variants.items():
27+
for size in variants:
2828
result.append(f"{family}-{size}")
2929
return result
3030

3131
@classmethod
3232
def get_config(cls, model_name: str) -> dict:
3333
for family, variants in SUPPORTED_MODELS.items():
34-
for size, config in variants.items():
34+
for size, _config in variants.items():
3535
if f"{family}-{size}" == model_name:
3636
return {"family": family, "size": size, **config}
3737
raise ValueError(f"Unknown model: {model_name}. Supported: {cls.list_supported()}")

‎src/specinferkit/quantization/fp8.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class FP8Quantizer:
2020
def __init__(self, config: QuantizationConfig | None = None):
2121
self.config = config or QuantizationConfig()
2222
if self.config.dtype not in self.SUPPORTED_DTYPES:
23-
raise ValueError(f"Unsupported dtype: {self.config.dtype}. Options: {self.SUPPORTED_DTYPES}")
23+
raise ValueError(
24+
f"Unsupported dtype: {self.config.dtype}. Options: {self.SUPPORTED_DTYPES}"
25+
)
2426

2527
def quantize(self, tensor):
2628
return {"data": tensor, "scale": 1.0, "dtype": self.config.dtype}
@@ -32,5 +34,5 @@ def dequantize(self, quantized):
3234
def quantize_cache(cache_path: str, dtype: str, output: str):
3335
print(f"[INFO] Quantizing cache at {cache_path} to {dtype}")
3436
print(f"[INFO] Output: {output}")
35-
print(f"[INFO] Estimated storage reduction: 50%")
36-
print(f"[INFO] Quantization complete.")
37+
print("[INFO] Estimated storage reduction: 50%")
38+
print("[INFO] Quantization complete.")

‎src/specinferkit/serving/server.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""FastAPI-based inference server with speculative decoding."""
22

33
import uvicorn
4-
from fastapi import FastAPI, HTTPException
4+
from fastapi import FastAPI
55
from pydantic import BaseModel
66

77

‎src/specinferkit/utils/config.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def load_config(path: str) -> dict:
77
"""Load a YAML configuration file."""
8-
with open(path, "r") as f:
8+
with open(path) as f:
99
return yaml.safe_load(f)
1010

1111

0 commit comments

Comments
 (0)