Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+invalid-escape-sequences.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `SyntaxWarning: invalid escape sequence '\*'` emitted when `coreai_opt.quantization.config` is compiled on Python 3.12+ (and a `SyntaxError` under `python -W error`).
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ select = [
"RUF100", # remove unused noqa pragmas
"TC004", # catch runtime imports in TYPE_CHECKING blocks
"UP", # apply pyupgrade modernization rules
"W605", # invalid escape sequences (SyntaxWarning since Python 3.12)
]
ignore = [
"ANN401", # allow type `Any`.
Expand Down
4 changes: 2 additions & 2 deletions src/coreai_opt/quantization/config/quantization_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __init__(self, execution_mode: object) -> None:


class OpQuantizerConfig(OpCompressionConfig[QuantizationSpec]):
"""
r"""
Configuration class for quantization at the operation level.

This class specifies quantization settings for inputs, outputs, and state
Expand Down Expand Up @@ -271,7 +271,7 @@ def get_default_state_spec(cls) -> dict[str, QuantizationSpec | None]:

@final
class ModuleQuantizerConfig(ModuleCompressionConfig[OpQuantizerConfig, QuantizationSpec]):
"""
r"""
Configuration class for quantization at the module level.

This class manages quantization settings for an entire module, including:
Expand Down
8 changes: 4 additions & 4 deletions tests/quantization/test_annotation_pattern_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3414,7 +3414,7 @@ def test_none_configs(self, config, expected):
QuantizerConfig(
global_config=None,
module_name_configs={
"inner_module\.linear_out.*": ModuleQuantizerConfig(
r"inner_module\.linear_out.*": ModuleQuantizerConfig(
op_state_spec=None,
module_state_spec={"weight": default_weight_quantization_spec()},
)
Expand Down Expand Up @@ -3508,7 +3508,7 @@ def test_module_level_setting_precedence(self):
)
},
module_name_configs={
"inner_module\.linear_out1": ModuleQuantizerConfig(
r"inner_module\.linear_out1": ModuleQuantizerConfig(
op_input_spec=None,
op_output_spec=None,
op_state_spec=None,
Expand Down Expand Up @@ -4156,7 +4156,7 @@ def test_shared_param_precedence(
)
},
),
"Only integer indices or '\*' are supported",
r"Only integer indices or '\*' are supported",
),
(
QuantizerConfig(
Expand All @@ -4167,7 +4167,7 @@ def test_shared_param_precedence(
)
},
),
"Only integer indices or '\*' are supported",
r"Only integer indices or '\*' are supported",
),
(
QuantizerConfig(
Expand Down
25 changes: 25 additions & 0 deletions tests/test_source_compiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2026 Apple Inc.
#
# Use of this source code is governed by a BSD-3-Clause license that can
# be found in the LICENSE file or at https://opensource.org/licenses/BSD-3-Clause

"""Check that the package source compiles without warnings."""

import warnings
from pathlib import Path

import pytest

import coreai_opt

_SRC_ROOT = Path(coreai_opt.__file__).parent
_SOURCE_FILES = sorted(_SRC_ROOT.rglob("*.py"))


@pytest.mark.parametrize("path", _SOURCE_FILES, ids=lambda p: str(p.relative_to(_SRC_ROOT.parent)))
def test_source_compiles_without_warnings(path: Path) -> None:
# Things like invalid escape sequences only warn at compile time, and the
# warning is lost once a .pyc is cached, so compile from source directly.
with warnings.catch_warnings():
warnings.simplefilter("error")
compile(path.read_text(encoding="utf-8"), str(path), "exec")