Skip to content

Commit b2e18bc

Browse files
committed
style: apply ruff format
Normalizes formatting (blank lines, wrapping) in 8 files that predated CI format-checking. No logic changes.
1 parent 4e3727e commit b2e18bc

8 files changed

Lines changed: 57 additions & 40 deletions

File tree

coreai_torch/_compression/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def repeat_tensor_as(tensor: torch.Tensor, target_shape: torch.Size) -> torch.Te
9999
)
100100
return repeated_tensor
101101

102+
102103
def wrap_for_parametrization(
103104
compression_module_class: type[torch.nn.Module],
104105
) -> type[torch.nn.Module]:

docs/coreai-core/tutorials/construct-a-graph.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
" ) -> Annotated[Value, output_spec]:\n",
175175
" return ops.add(x, x)\n",
176176
"\n",
177+
"\n",
177178
"module.verify()\n",
178179
"print(\"Module verified.\")"
179180
]

docs/coreai-core/tutorials/run-an-aimodel.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@
125125
" ) -> Annotated[Value, TensorSpec(shape=[2, 3], dtype=np.float32, name=\"y\")]:\n",
126126
" return ops.add(x, x)\n",
127127
"\n",
128+
"\n",
128129
"AIProgram(module).save_asset(asset_path)\n",
129130
"print(f\"created {asset_path}\")"
130131
]

docs/getting-started/quickstart.ipynb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"metadata": {},
6969
"outputs": [],
7070
"source": [
71-
"\n",
7271
"example_input = (torch.randn(1, 10),)\n",
7372
"exported = torch.export.export(model, args=example_input)"
7473
]
@@ -239,8 +238,6 @@
239238
"metadata": {},
240239
"outputs": [],
241240
"source": [
242-
"\n",
243-
"\n",
244241
"async def run():\n",
245242
" with tempfile.TemporaryDirectory() as tmpdir:\n",
246243
" asset = coreai_program.save_asset(Path(tmpdir) / \"mobilenet_v2_example.aimodel\")\n",

docs/guides/composite-ops.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@
9797
"metadata": {},
9898
"outputs": [],
9999
"source": [
100-
"\n",
101-
"\n",
102100
"class RMSNorm(nn.Module):\n",
103101
" \"\"\"Convenience wrapper that owns the learnable scale parameter.\"\"\"\n",
104102
"\n",

docs/guides/externalization.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
" inv_rms = torch.rsqrt((x_f32 * x_f32).mean(self.axes, keepdim=True) + self.eps)\n",
100100
" return (input * inv_rms).to(input.dtype) * scale\n",
101101
"\n",
102+
"\n",
102103
"model = RMSNormComposite().eval()\n",
103104
"sample = (torch.randn(10), torch.randn(10))"
104105
]

tests/compression/test_compression.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# We add "./tests/coreai" path, in order to use some existing utils
3030
sys.path.append(str(Path(__file__).parents[2]))
3131

32+
3233
def _scale_shape(
3334
input_shape: tuple[int, ...],
3435
axis: int,
@@ -56,6 +57,7 @@ async def lower_to_coreai(
5657
converter = TorchConverter().add_exported_program(coreaten_program)
5758
return converter.to_coreai()
5859

60+
5961
async def _validate_execution(
6062
coreai_program: AIProgram,
6163
torch_out: torch.Tensor,
@@ -81,6 +83,7 @@ async def _validate_execution(
8183
atol=atol,
8284
)
8385

86+
8487
@pytest.mark.parametrize(
8588
"nbits",
8689
[4, 8],
@@ -1055,9 +1058,7 @@ def test_ir(
10551058
"" if granularity == "per_tensor" else f"{activation_shape[axis]}x"
10561059
)
10571060

1058-
msg = (
1059-
"TODO: reshape on consts such as offset and scale is not const eliminated"
1060-
)
1061+
msg = "TODO: reshape on consts such as offset and scale is not const eliminated"
10611062
pytest.xfail(reason=msg)
10621063
truth = f"""
10631064
// CHECK-LABEL: coreai.graph @main

tests/test_externalize.py

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,10 +3032,12 @@ def forward(
30323032

30333033
@pytest.mark.ir
30343034
@pytest.mark.flaky(reruns=3)
3035-
@pytest.mark.skip(reason=(
3036-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3037-
"these tests or use an alternative way to generate quantized weights"
3038-
))
3035+
@pytest.mark.skip(
3036+
reason=(
3037+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3038+
"these tests or use an alternative way to generate quantized weights"
3039+
)
3040+
)
30393041
def test_externalize_rms_norm_with_quantized_linears_ir() -> None:
30403042
"""IR check: Quantized (int4) weights retain si4 dtype when externalization re-exports the model."""
30413043

@@ -3109,10 +3111,12 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
31093111

31103112

31113113
@pytest.mark.flaky(reruns=3)
3112-
@pytest.mark.skip(reason=(
3113-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3114-
"these tests or use an alternative way to generate quantized weights"
3115-
))
3114+
@pytest.mark.skip(
3115+
reason=(
3116+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3117+
"these tests or use an alternative way to generate quantized weights"
3118+
)
3119+
)
31163120
async def test_externalize_rms_norm_with_quantized_linears() -> None:
31173121
"""Quantized (int4) weights retain si4 dtype when externalization re-exports the model.
31183122
@@ -3176,10 +3180,12 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
31763180

31773181
@pytest.mark.ir
31783182
@pytest.mark.flaky(reruns=3)
3179-
@pytest.mark.skip(reason=(
3180-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3181-
"these tests or use an alternative way to generate quantized weights"
3182-
))
3183+
@pytest.mark.skip(
3184+
reason=(
3185+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3186+
"these tests or use an alternative way to generate quantized weights"
3187+
)
3188+
)
31833189
def test_externalize_gather_mm_with_quantized_rhs_ir() -> None:
31843190
"""IR check: Quantized expert weight flows as rhs into an externalized GatherMM composite."""
31853191
num_experts = 4
@@ -3263,10 +3269,12 @@ def forward(self, x: torch.Tensor, indices: torch.Tensor) -> torch.Tensor:
32633269

32643270

32653271
@pytest.mark.flaky(reruns=3)
3266-
@pytest.mark.skip(reason=(
3267-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3268-
"these tests or use an alternative way to generate quantized weights"
3269-
))
3272+
@pytest.mark.skip(
3273+
reason=(
3274+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3275+
"these tests or use an alternative way to generate quantized weights"
3276+
)
3277+
)
32703278
async def test_externalize_gather_mm_with_quantized_rhs() -> None:
32713279
"""Quantized expert weight flows as rhs into an externalized GatherMM composite.
32723280
@@ -3345,10 +3353,12 @@ def forward(self, x: torch.Tensor, indices: torch.Tensor) -> torch.Tensor:
33453353

33463354
@pytest.mark.ir
33473355
@pytest.mark.flaky(reruns=3)
3348-
@pytest.mark.skip(reason=(
3349-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3350-
"these tests or use an alternative way to generate quantized weights"
3351-
))
3356+
@pytest.mark.skip(
3357+
reason=(
3358+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3359+
"these tests or use an alternative way to generate quantized weights"
3360+
)
3361+
)
33523362
def test_externalize_multiple_composites_with_quantized_weights_ir() -> None:
33533363
"""IR check: Multiple composite ops (RMSNorm + SDPA) externalized with quantized linears."""
33543364
head_dim = 16
@@ -3433,10 +3443,12 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
34333443

34343444

34353445
@pytest.mark.flaky(reruns=3)
3436-
@pytest.mark.skip(reason=(
3437-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3438-
"these tests or use an alternative way to generate quantized weights"
3439-
))
3446+
@pytest.mark.skip(
3447+
reason=(
3448+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3449+
"these tests or use an alternative way to generate quantized weights"
3450+
)
3451+
)
34403452
async def test_externalize_multiple_composites_with_quantized_weights() -> None:
34413453
"""Multiple composite ops (RMSNorm + SDPA) externalized with quantized linears.
34423454
@@ -3512,10 +3524,12 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
35123524

35133525

35143526
@pytest.mark.ir
3515-
@pytest.mark.skip(reason=(
3516-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3517-
"these tests or use an alternative way to generate quantized weights"
3518-
))
3527+
@pytest.mark.skip(
3528+
reason=(
3529+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3530+
"these tests or use an alternative way to generate quantized weights"
3531+
)
3532+
)
35193533
def test_externalize_gather_mm_combined_with_rms_norm_ir() -> None:
35203534
"""IR check: GatherMM + RMSNorm both externalized alongside quantized weights."""
35213535
num_experts = 4
@@ -3590,10 +3604,13 @@ def forward(self, x: torch.Tensor, indices: torch.Tensor) -> torch.Tensor:
35903604
"""
35913605
filecheck_pattern(ir, check_file=pattern)
35923606

3593-
@pytest.mark.skip(reason=(
3594-
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3595-
"these tests or use an alternative way to generate quantized weights"
3596-
))
3607+
3608+
@pytest.mark.skip(
3609+
reason=(
3610+
"transform_with_custom_compression_ops has been deprecated. Consider removing "
3611+
"these tests or use an alternative way to generate quantized weights"
3612+
)
3613+
)
35973614
async def test_externalize_gather_mm_combined_with_rms_norm() -> None:
35983615
"""GatherMM + RMSNorm both externalized alongside quantized weights.
35993616

0 commit comments

Comments
 (0)