Skip to content

Conversation

@Rickypanta0
Copy link

@Rickypanta0 Rickypanta0 commented Nov 13, 2025

📝 Description

This PR addresses issue #2959 by upgrading the project's minimum Python version from Python 3.10 to Python 3.13. It addresses dependency constraints, updates CI configurations, and applies necessary fixes to code and tests to ensure compatibility with the updated environment.

Key Changes & Rationale:

  1. CI/CD Upgrade: Updated GitHub Actions (pre_merge.yml) and documentation to use Python 3.13.
  2. Dependency Resolution:
    • Updated pyproject.toml and uv.lock to support Python 3.13.
    • Restricted cu118 and cu121 extras to python_version < '3.13', as PyTorch does not provide wheels for these CUDA versions on Python 3.13 (which defaults to CUDA 12.4).
  3. ONNX Export Fix:
    • Switched torch.onnx.export to use the legacy JIT exporter (dynamo=False) in export_mixin.py.
    • Reason: The new Dynamo exporter enforces stricter graph tracing and currently fails with GuardOnDataDependentSymNode due to data-dependent control flow in post_processor.py (specifically isnan() checks). The legacy exporter handles this correctly.
  4. Test Adjustments:
    • Relaxed tolerance in test_inference_similarity (from 1e-3 to 5-e3).
    • Reason: Minor floating-point precision differences were observed between Torch and OpenVINO inference with the updated library versions.

✨ Changes

Select what type of change your PR is:

  • 🚀 New feature (non-breaking change which adds functionality)
  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • 🔄 Refactor (non-breaking change which refactors the code base)
  • ⚡ Performance improvements
  • 🎨 Style changes (code style/formatting)
  • 🧪 Tests (adding/modifying tests)
  • 📚 Documentation update
  • 📦 Build system changes
  • 🚧 CI/CD configuration
  • 🔧 Chore (general maintenance)
  • 🔒 Security update
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)

✅ Checklist

Before you submit your pull request, please make sure you have completed the following steps:

  • 📚 I have made the necessary updates to the documentation (if applicable).
  • 🧪 I have written tests that support my changes and prove that my fix is effective or my feature works (if applicable).
  • 🏷️ My PR title follows conventional commit format.

@Rickypanta0 Rickypanta0 force-pushed the chore/ci/upgrade-python-3-13 branch 4 times, most recently from 87bbf95 to aee7d36 Compare November 13, 2025 13:55
@Rickypanta0 Rickypanta0 changed the title Chore/ci/upgrade python 3 13 🔧 chore(ci): upgrade python 3.13 Nov 19, 2025
Copilot AI review requested due to automatic review settings November 23, 2025 14:03
Copilot finished reviewing on behalf of Rickypanta0 November 23, 2025 14:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR upgrades the project's minimum Python version from 3.10 to 3.13, ensuring compatibility with the latest Python release. The changes include CI/CD updates, dependency constraint adjustments, code modernization to use Python 3.13 features, and compatibility fixes for ONNX export and tests.

  • Migrates string-based enums from class Name(str, Enum) to class Name(StrEnum) pattern
  • Simplifies Generator type hints from Generator[T, None, None] to Generator[T]
  • Adds dynamo=False to ONNX export to use legacy JIT exporter due to Dynamo compatibility issues

Reviewed changes

Copilot reviewed 44 out of 45 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
.github/workflows/pre_merge.yml Updated CI to test Python 3.13 alongside 3.10
pyproject.toml Added Python 3.13 classifier, updated PyTorch dependency constraints, reorganized ruff configuration
docs/source/snippets/install/source.txt Updated installation instructions to support Python >=3.10
docs/source/markdown/guides/developer/contributing.md Updated development environment setup to support Python >=3.10
src/anomalib/models/components/base/export_mixin.py Added dynamo=False to torch.onnx.export for legacy JIT exporter
src/anomalib/data/utils/download.py Removed Python version check for tar.extract filter parameter
src/anomalib/data/dataclasses/torch/base.py Moved TypeVar declaration after InferenceBatch class
src/anomalib/data/dataclasses/numpy/depth.py Added missing dataclass decorator and type annotations
Multiple enum files Migrated from (str, Enum) pattern to StrEnum
Multiple generator files Simplified Generator type hints by removing None type parameters
tests/unit/deploy/test_inferencer.py Relaxed tolerance from 1e-3 to 3e-3 for floating-point comparison

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pyproject.toml Outdated
cu118 = [
"torch>=2.4.0,<=2.8.0",
"torchvision>=0.19.0",
"torch>=2.4.0,<=2.5.1 ; python_version < '3.13'",
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upper bound constraint <=2.5.1 for cu118 seems overly restrictive and inconsistent with the other CUDA extras. If PyTorch 2.5.1 is the last version supporting CUDA 11.8 on Python 3.12, this is correct. However, if newer versions exist that also support CUDA 11.8 on Python < 3.13, consider using an open upper bound like torch>=2.4.0 ; python_version < '3.13' to avoid unnecessary version locks.

Suggested change
"torch>=2.4.0,<=2.5.1 ; python_version < '3.13'",
"torch>=2.4.0 ; python_version < '3.13'",

Copilot uses AI. Check for mistakes.
pyproject.toml Outdated
cu121 = [
"torch>=2.4.0,<=2.8.0",
"torchvision>=0.19.0",
"torch>=2.4.0 ; python_version < '3.13'",
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cu121 extra has no upper bound for torch, which differs from cu118 that has <=2.5.1. This inconsistency may be intentional if CUDA 12.1 wheels continue to be built for Python < 3.13, but consider documenting why these constraints differ or making them consistent if both CUDA versions have the same support lifecycle.

Suggested change
"torch>=2.4.0 ; python_version < '3.13'",
"torch>=2.4.0,<=2.5.1 ; python_version < '3.13'",

Copilot uses AI. Check for mistakes.
# PyTorch dependency groups
cpu = [
"torch>=2.4.0,<=2.8.0",
"torch>=2.4.0",
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the upper bound <=2.8.0 for the cpu extra creates potential compatibility risks. If PyTorch 3.0+ introduces breaking changes, users could encounter issues. Consider retaining an upper bound (e.g., <3.0) or adding a comment explaining why the constraint was relaxed.

Suggested change
"torch>=2.4.0",
"torch>=2.4.0,<3.0",

Copilot uses AI. Check for mistakes.
>>> item.depth.shape
(224, 224)
"""

Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The new imports on lines 29 and 31 are only used for the item_class type annotation on line 93. Consider adding these imports closer to where they're used, or add a comment explaining they're specifically for the ClassVar annotation added for Python 3.13 compatibility.

Suggested change
# The following imports are only used for the `item_class` type annotation in NumpyDepthBatch
# and are required for Python 3.13 compatibility with ClassVar.

Copilot uses AI. Check for mistakes.
pred_mask: torch.Tensor | None = None


NumpyT = TypeVar("NumpyT")
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Moving NumpyT after InferenceBatch appears to be for ordering purposes, but it creates a gap between related type definitions. Consider adding a comment explaining why this TypeVar is defined here rather than at the top with other type-related imports, especially since it's used by the ToNumpyMixin class below.

Copilot uses AI. Check for mistakes.
pyproject.toml Outdated

ignore = [
# pydocstyle
"COM812",
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new COM812 ignore rule (missing trailing commas) is added without explanation. Consider adding a comment explaining why this specific rule is being ignored, especially since it appears in the middle of other documented rule ignores. This helps maintainers understand the rationale.

Suggested change
"COM812",
"COM812", # Missing trailing comma (ignored due to project style preference)

Copilot uses AI. Check for mistakes.
# Use of virtual environment is highy recommended
# Using conda
yes | conda create -n anomalib_env python=3.10
yes | conda create -n anomalib_env python>=3.10
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conda create command syntax python>=3.10 is incorrect. Conda expects python=3.10 or python=3.13 but does not support constraint operators like >= in the package specification. This should be changed to a specific version like python=3.13 or python=3.10.

Suggested change
yes | conda create -n anomalib_env python>=3.10
yes | conda create -n anomalib_env python=3.10

Copilot uses AI. Check for mistakes.

```bash
conda create -n anomalib_dev python=3.10
conda create -n anomalib_dev python>=3.10
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conda create command syntax python>=3.10 is incorrect. Conda does not support constraint operators like >= in package specifications. Use a specific version like python=3.13 or python=3.10 instead.

Suggested change
conda create -n anomalib_dev python>=3.10
conda create -n anomalib_dev python=3.10

Copilot uses AI. Check for mistakes.
@Rickypanta0 Rickypanta0 force-pushed the chore/ci/upgrade-python-3-13 branch 2 times, most recently from 0ac0b74 to 7985e04 Compare November 23, 2025 14:14
- Update pyproject.toml to require python >= 3.13
- Update tox.ini to test py313
- Remove legacy CUDA dependencies (11.8, 12.1) incompatible with PyTorch 2.5+
- Fix numpy array formatting issue in inferencer tests for Py3.13 compatibility

Signed-off-by: Rickypanta0 <rickypanta.dev@gmail.com>
Copilot AI review requested due to automatic review settings November 23, 2025 14:32
@Rickypanta0 Rickypanta0 force-pushed the chore/ci/upgrade-python-3-13 branch from 7985e04 to 204426f Compare November 23, 2025 14:32
Copilot finished reviewing on behalf of Rickypanta0 November 23, 2025 14:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 82 out of 83 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -1,6 +1,6 @@
# Use of virtual environment is highy recommended
Copy link

Copilot AI Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: "highy" should be "highly".

Suggested change
# Use of virtual environment is highy recommended
# Use of virtual environment is highly recommended

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@samet-akcay samet-akcay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your contribution @Rickypanta0. I've added some comments.

#
# Required Inputs:
# - python-version: Python version for building (default: "3.10")
# - python-version: Python version for building (default: "3.11")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

# uses: ./.github/workflows/_reusable-artifact-builder.yaml
# with:
# python-version: "3.10"
# python-version: "3.11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

description: "Python version for building"
type: string
default: "3.10"
default: "3.11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here?

# with:
# version: "v1.2.3"
# python-version: "3.10"
# python-version: "3.11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

# with:
# version: "v1.2.3-rc1"
# python-version: "3.10"
# python-version: "3.11"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here. It would be great to have consistency

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, would you prefer these examples/defaults to reflect the minimum supported version (reverting to 3.10, as it was) or the latest target version ?

"""

item_class = NumpyDepthItem
item_class: ClassVar[Callable] = NumpyDepthItem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these changes related to python version as well?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, is indirectly related. Upgrading to 3.13, the pre-commit hooks fails with mypy with incompatibility error. I adopted for the fix instaed of suppressing it with # type: ignore[misc]. Here is the error log raised from the upgrade:

`mypy.....................................................................Failed

hook id: mypy
exit code: 1
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_DepthInputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_ImageInputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "NumpyBatch" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_GenericBatch" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "UpdateMixin" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_OutputFields" [misc]
src/anomalib/data/dataclasses/numpy/depth.py:68: error: Definition of "replace" in base class "BatchIterateMixin" is incompatible with definition in base class "_InputFields" [misc]
Found 7 errors in 1 file (checked 396 source files)`


@dataclass
class ToNumpyMixin(Generic[NumpyT]):
class ToNumpyMixin(Generic[NumpyT]): # noqa: UP046
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above? Do we need to change all this when we change the python version?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is triggered by the upgrade. Since the target is now compatible with py 3.12+. However i found that the new syntax for the bounded generics are less readable in my opinion, compared with the current implementation. I decided to suppress the errors with # noqa: UP046 to mantain readability.

readme = "README.md"
description = "anomalib - Anomaly Detection Library"
requires-python = ">=3.10"
requires-python = ">=3.13"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with some of the community comments that switching to Python 3.13 directly might break the compatibility. We should therefore stick to 3.10 for a while based on this schedule

Image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undestood, i will revert the compatibility to >=3.10 to keep backward compatibility while ensuring the CI/CD pipeline test against 3.13.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🔼 Upgrade the minimum python requirement to 3.13

2 participants