Skip to content

Conversation

@ashwinvaidya17
Copy link
Contributor

@ashwinvaidya17 ashwinvaidya17 commented Jan 12, 2026

📝 Description

  • Reduces startup time from 13s to7s.
  • The main challenge is that torch import and lightning.pytorch imports are heavy. Lazy loading would mean changing a lot of files. This PR does some minor refactor.
  • Also, we don't need anomalib[full]. Having all the loggers in the environment also contributes to the long startup
  • Squeezed in a fix for max_epochs as well

To test

python -X importtime -c "import sys; sys.path.insert(0, 'src'); import main" 2> import.log && tuna import.log

✨ 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.

For more information about code review checklists, see the Code Review Checklist.

Copilot AI review requested due to automatic review settings January 12, 2026 12:21
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 reduces application startup time from ~13s to ~7s by optimizing imports and dependency management. The main approach is to move heavy imports (torch, lightning.pytorch, numpy, anomalib) into TYPE_CHECKING blocks to defer their loading until runtime when needed, and switching from anomalib[full] to anomalib[openvino] with tensorboard to reduce unnecessary dependencies.

Changes:

  • Moved heavy imports into TYPE_CHECKING blocks across multiple files
  • Switched from anomalib[full] to anomalib[openvino] + tensorboard in pyproject.toml
  • Fixed max_epochs handling to properly handle None values from UI

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
application/backend/pyproject.toml Changed dependency from anomalib[full] to anomalib[openvino] + tensorboard to reduce startup overhead
application/backend/src/services/training_service.py Fixed max_epochs to handle None values from UI using walrus operator
application/backend/src/services/dispatchers/*.py Moved numpy and anomalib imports to TYPE_CHECKING blocks, updated copyright years
src/anomalib/deploy/inferencers/*.py Moved imports to TYPE_CHECKING blocks and removed string quotes from type hints
src/anomalib/data/datamodules/base/image.py Moved imports to TYPE_CHECKING and changed to more specific lightning import path
src/anomalib/data/dataclasses/generic.py Moved Iterator and Callable imports to TYPE_CHECKING block
application/backend/src/entities/stream_data.py Moved numpy and anomalib imports to TYPE_CHECKING block, updated copyright
application/backend/src/pydantic_models/model.py Added blank line after copyright header

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

ashwinvaidya17 and others added 2 commits January 12, 2026 13:23
Signed-off-by: Ashwin Vaidya <[email protected]>
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Ashwin Vaidya <[email protected]>
Copilot AI review requested due to automatic review settings January 12, 2026 12:25
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 10 out of 11 changed files in this pull request and generated no new comments.


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

Copilot AI review requested due to automatic review settings January 13, 2026 14:53
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 10 out of 11 changed files in this pull request and generated 1 comment.


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

from anomalib.data import NumpyImageBatch as PredictionResult


def numpy_to_base64(image: np.ndarray, fmt: str = ".jpg") -> str:
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The function uses np.ndarray as a type annotation but numpy is now only imported in the TYPE_CHECKING block. This will cause a NameError at runtime. Either import numpy unconditionally or use a string literal for the type annotation: image: 'np.ndarray'.

Copilot uses AI. Check for mistakes.
Signed-off-by: Ashwin Vaidya <[email protected]>
Copilot AI review requested due to automatic review settings January 13, 2026 15:26
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 11 out of 12 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.github/workflows/geti-inspect.yaml:1

  • The copyright year includes 2026, which is in the future. The current date is January 13, 2026, so the copyright should only include years up to 2026 if work was actually done in 2026. If this work was completed in 2025, the copyright should remain as 2025 only.
name: Geti Inspect UI checks

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

Signed-off-by: Ashwin Vaidya <[email protected]>
Signed-off-by: Ashwin Vaidya <[email protected]>
Copilot AI review requested due to automatic review settings January 13, 2026 16:31
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 10 out of 11 changed files in this pull request and generated no new comments.


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

Signed-off-by: Ashwin Vaidya <[email protected]>
Signed-off-by: Ashwin Vaidya <[email protected]>
Copilot AI review requested due to automatic review settings January 13, 2026 17:37
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 11 out of 12 changed files in this pull request and generated no new comments.


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

Signed-off-by: Ashwin Vaidya <[email protected]>
Signed-off-by: Ashwin Vaidya <[email protected]>
Copilot AI review requested due to automatic review settings January 13, 2026 17:48
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 11 out of 12 changed files in this pull request and generated 1 comment.


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

snapshot_id = UUID(snapshot_id_) if snapshot_id_ else None
max_epochs = job.payload.get("max_epochs", 200)

snapshot_id = UUID(snapshot_id_str) if (snapshot_id_str := job.payload.get("dataset_snapshot_id")) else None
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

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

The variable name 'snapshot_id_str' is ambiguous. Consider renaming it to 'dataset_snapshot_id_str' to better reflect that it comes from the dataset_snapshot_id payload field.

Suggested change
snapshot_id = UUID(snapshot_id_str) if (snapshot_id_str := job.payload.get("dataset_snapshot_id")) else None
snapshot_id = UUID(dataset_snapshot_id_str) if (dataset_snapshot_id_str := job.payload.get("dataset_snapshot_id")) else None

Copilot uses AI. Check for mistakes.
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.

1 participant