Skip to content

Hotfix for no dependency config loading#387

Open
kozlov721 wants to merge 2 commits into
mainfrom
fix/per-class-metrics
Open

Hotfix for no dependency config loading#387
kozlov721 wants to merge 2 commits into
mainfrom
fix/per-class-metrics

Conversation

@kozlov721
Copy link
Copy Markdown
Collaborator

@kozlov721 kozlov721 commented May 27, 2026

Purpose

Falls back to disabled per-class metrics in case of an error instead of crashing.
This solves crashing no-dependency config loading in HubAI.

Specification

None / not applicable

Dependencies & Potential Impact

None / not applicable

Deployment Plan

None / not applicable

Testing & Validation

None / not applicable

AI Usage

Assisted-by: AGENT_NAME:MODEL_VERSION [TOOL1] [TOOL2]

Submitted code was reviewed by a human: YES/NO

The author is taking the responsibility for the contribution: YES/NO

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling in metrics generation to gracefully manage exceptions without disrupting the application flow.

Review Change Stack

@kozlov721 kozlov721 requested a review from a team as a code owner May 27, 2026 07:41
@kozlov721 kozlov721 requested review from conorsim, klemen1999 and tersekmatija and removed request for a team May 27, 2026 07:41
@github-actions github-actions Bot added the fix Fixing a bug label May 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@kozlov721, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 minutes and 48 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1dbe7b18-8def-43e7-83e6-0e40b809d2fc

📥 Commits

Reviewing files that changed from the base of the PR and between e29a98e and 614d5b0.

📒 Files selected for processing (1)
  • luxonis_train/config/predefined_models/base_predefined_model.py
📝 Walkthrough

Walkthrough

The PR modifies base_predefined_model.py to add exception suppression in the SimplePredefinedModel._generate_metrics method. The import of suppress from contextlib is added, and the entire metrics construction logic is wrapped in a context manager that silences any exceptions raised during metric generation.

Changes

Metrics Generation Exception Handling

Layer / File(s) Summary
Suppress exceptions in metrics generation
luxonis_train/config/predefined_models/base_predefined_model.py
Import suppress from contextlib and wrap the metric-building flow (task lookup, per-metric parameter overrides, per-class override application, and warning emission) in with suppress(Exception): to catch and suppress all exceptions during metrics generation instead of propagating them.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Quiet metrics, whisper soft,
Exceptions caught and gently loft,
With suppress we silence strain,
No errors echo, calm domain!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title describes a hotfix for config loading, but the actual change wraps metric generation in exception suppression to prevent crashes—a different concern than config loading itself. Revise the title to accurately reflect the core change, such as 'Suppress metric generation errors to prevent crashes during config loading' or 'Fallback to disabled per-class metrics on generation errors'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/per-class-metrics

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
luxonis_train/config/predefined_models/base_predefined_model.py (1)

222-252: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Suppressed exceptions still lead to a crash via None return.

If any exception occurs in this block, it is swallowed and _generate_metrics() returns None implicitly, which later breaks at metrics + [...] in nodes with TypeError. Return a safe fallback list when override resolution fails.

Proposed fix
-        with suppress(Exception):
-            task = NODES.get(self._head).task
-            metrics = []
-            applied_per_class_override = False
-
-            for metric in self._metrics:
-                metric_params = dict(self._metrics_params)
-                metric_cls = METRICS.get(metric)
-                aliases = metric_cls.get_predefined_model_params_aliases(task)
-                param_name = aliases.get("per_class_metrics")
-                if param_name is not None:
-                    metric_params[param_name] = self._per_class_metrics
-                    applied_per_class_override = True
-
-                metrics.append(
-                    MetricModuleConfig(
-                        name=metric,
-                        params=metric_params,
-                        is_main_metric=metric == self._main_metric,
-                    )
-                )
-
-            if self._metrics and not applied_per_class_override:
-                logger.warning(
-                    "Ignoring `per_class_metrics` for predefined model metrics "
-                    f"{self._metrics} because none of them support a per-class "
-                    "override."
-                )
-
-            return metrics
+        try:
+            task = NODES.get(self._head).task
+            metrics = []
+            applied_per_class_override = False
+
+            for metric in self._metrics:
+                metric_params = dict(self._metrics_params)
+                metric_cls = METRICS.get(metric)
+                aliases = metric_cls.get_predefined_model_params_aliases(task)
+                param_name = aliases.get("per_class_metrics")
+                if param_name is not None:
+                    metric_params[param_name] = self._per_class_metrics
+                    applied_per_class_override = True
+
+                metrics.append(
+                    MetricModuleConfig(
+                        name=metric,
+                        params=metric_params,
+                        is_main_metric=metric == self._main_metric,
+                    )
+                )
+
+            if self._metrics and not applied_per_class_override:
+                logger.warning(
+                    "Ignoring `per_class_metrics` for predefined model metrics "
+                    f"{self._metrics} because none of them support a per-class "
+                    "override."
+                )
+            return metrics
+        except Exception as exc:
+            logger.warning(
+                "Failed to apply `per_class_metrics` override; falling back to "
+                f"default metric params. Reason: {exc}"
+            )
+            return [
+                MetricModuleConfig(
+                    name=metric,
+                    params=self._metrics_params,
+                    is_main_metric=metric == self._main_metric,
+                )
+                for metric in self._metrics
+            ]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@luxonis_train/config/predefined_models/base_predefined_model.py` around lines
222 - 252, The try/suppress block in _generate_metrics (the shown code that
reads NODES.get(self._head).task, iterates self._metrics, uses METRICS.get and
builds MetricModuleConfig) swallows exceptions and allows the function to
implicitly return None, causing downstream TypeError; change the suppression to
catch Exception explicitly, log the error, and return a safe fallback list
(e.g., an empty list or a default MetricModuleConfig list) so callers combining
metrics (metrics + [...]) always receive a list; ensure you reference the same
symbols (NODES, METRICS, MetricModuleConfig, self._metrics,
self._metrics_params, self._per_class_metrics, self._main_metric) when
implementing the fallback and logging.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@luxonis_train/config/predefined_models/base_predefined_model.py`:
- Around line 222-252: The try/suppress block in _generate_metrics (the shown
code that reads NODES.get(self._head).task, iterates self._metrics, uses
METRICS.get and builds MetricModuleConfig) swallows exceptions and allows the
function to implicitly return None, causing downstream TypeError; change the
suppression to catch Exception explicitly, log the error, and return a safe
fallback list (e.g., an empty list or a default MetricModuleConfig list) so
callers combining metrics (metrics + [...]) always receive a list; ensure you
reference the same symbols (NODES, METRICS, MetricModuleConfig, self._metrics,
self._metrics_params, self._per_class_metrics, self._main_metric) when
implementing the fallback and logging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe7785eb-1059-4e0b-98d9-00dde0c9291a

📥 Commits

Reviewing files that changed from the base of the PR and between 4cb0f5a and e29a98e.

📒 Files selected for processing (1)
  • luxonis_train/config/predefined_models/base_predefined_model.py

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

Labels

fix Fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant