Skip to content

Fixes to modelconverter analyze#244

Merged
dtronmans merged 12 commits into
mainfrom
fix/analyze
Jun 22, 2026
Merged

Fixes to modelconverter analyze#244
dtronmans merged 12 commits into
mainfrom
fix/analyze

Conversation

@dtronmans

@dtronmans dtronmans commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Purpose

Summary of the fixes needed:

  • Stop recreating the modified ONNX multiple times: generate the temporary modified ONNX once and reuse it for collecting debug output names and comparing ONNX vs DLC.
  • Capture the raw debug tensor names that SNPE writes.
  • Create the required output directories on the device before running snpe-net-run.
  • Strip leading "/" from SNPE tensor names before joining paths (had a problem with "/" in module names).
  • Log actual SNPE stdout/stderr on failure instead of only showing a Python CalledProcessError.

Also adapted the README to include the more precise command for running modelconverter analyze

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

  • Documentation

    • CLI usage examples updated to use named flags (--dlc-model-path, --onnx-model-path, --image-dirs) instead of positional arguments.
  • Bug Fixes

    • Enhanced error handling and resource cleanup in DLC inference operations.
  • Chores

    • Dependency version constraint updates.

@dtronmans dtronmans requested a review from a team as a code owner June 9, 2026 07:04
@dtronmans dtronmans requested review from conorsim, klemen1999, kozlov721 and tersekmatija and removed request for a team June 9, 2026 07:04
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

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

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

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

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

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b90da0c4-c60d-45fa-a241-b7d0557f7601

📥 Commits

Reviewing files that changed from the base of the PR and between f3e166c and a80d77e.

📒 Files selected for processing (1)
  • modelconverter/packages/rvc4/analyze.py
📝 Walkthrough

Walkthrough

The PR refactors RVC4Analyzer in analyze.py: moves temporary ONNX file cleanup to a finally block in analyze_layer_outputs, updates _compare_to_onnx to accept an already-created Path instead of recreating it, adds a _prepare_output_dirs helper for pre-creating device output directories, integrates it into _run_dlc, and adds structured subprocess.CalledProcessError handling. The README CLI examples are updated to flag-based syntax, and setuptools<82 is pinned in constraints.txt.

Changes

RVC4 Analyzer Refactor & CLI Docs Update

Layer / File(s) Summary
analyze_layer_outputs and _compare_to_onnx refactoring
modelconverter/packages/rvc4/analyze.py
Adds posixpath/subprocess imports; wraps ONNX session creation and DLC comparison in try/finally to guarantee onnx_all_layers deletion; refactors _compare_to_onnx signature to accept onnx_all_layers: Path from caller and removes its internal unlink call.
_prepare_output_dirs helper and _run_dlc integration
modelconverter/packages/rvc4/analyze.py
Adds _prepare_output_dirs that computes and batch-creates device output directories via mkdir -p; inserts its call into _run_dlc before snpe-net-run; adds a subprocess.CalledProcessError handler that decodes and logs stdout/stderr then raises a RuntimeError.
README CLI examples and constraints pin
README.md, constraints.txt
Updates multi-input and single-input modelconverter analyze examples to named-flag syntax (--dlc-model-path, --onnx-model-path, --image-dirs); pins setuptools<82 in constraints.txt.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • tersekmatija
  • conorsim

Poem

🐇 Hoppity-hop through the diff I go,
finally blocks keep the temp files in tow,
Named flags in the README, clean and bright,
setuptools<82 pinned just right,
Error logs decoded with a bunny's care —
The analyzer hops forward, beyond compare! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fixes to modelconverter analyze' accurately describes the main purpose of the PR, which focuses on multiple bug fixes and improvements to the modelconverter analyze command across documentation, dependencies, and implementation.
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/analyze

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.

Comment thread docker/rvc4/Dockerfile Outdated
Comment thread modelconverter/packages/rvc4/analyze.py Outdated
Comment thread modelconverter/packages/rvc4/analyze.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
modelconverter/packages/rvc4/analyze.py (1)

37-37: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Reuse the existing ONNX Runtime session.

analyze_layer_outputs() already creates an InferenceSession, but _compare_to_onnx() loads the same all-layers model again. Passing the existing session avoids duplicate model initialization and memory use.

♻️ Proposed refactor
-            self._compare_to_onnx(onnx_all_layers, input_matcher, dlc_matcher)
+            self._compare_to_onnx(session, input_matcher, dlc_matcher)
     def _compare_to_onnx(
         self,
-        onnx_all_layers: Path,
+        session: rt.InferenceSession,
         input_matcher: dict[str, dict[str, str]],
         dlc_matcher: dict[str, Path],
     ) -> None:
         logger.info("Comparing ONNX and DLC layer outputs.")
-        session = rt.InferenceSession(onnx_all_layers)
         output_names = [layer.name for layer in session.get_outputs()]

Also applies to: 52-52, 228-234

🤖 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 `@modelconverter/packages/rvc4/analyze.py` at line 37, The `_compare_to_onnx()`
function creates a duplicate InferenceSession at the
`rt.InferenceSession(onnx_all_layers)` call, even though
`analyze_layer_outputs()` already creates a session for the same model. Refactor
`_compare_to_onnx()` to accept the existing InferenceSession as a parameter
instead of initializing a new one internally, then update all calls to
`_compare_to_onnx()` in `analyze_layer_outputs()` to pass the session that was
already created. This eliminates redundant model loading and memory allocation.
🤖 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.

Inline comments:
In `@constraints.txt`:
- Line 1: The constraints.txt file is defined but not enforced during
installation, allowing setuptools to potentially exceed the version 82 limit. To
fix this, add the `-c constraints.txt` constraint flag to all pip install
commands across Dockerfiles and CI workflow files to ensure the constraint is
applied whenever dependencies are installed. This will enforce the setuptools
version limit specified in constraints.txt during the build and installation
process.

In `@modelconverter/packages/rvc4/analyze.py`:
- Around line 2-4: The `output_name` variable is derived from model tensor names
and is being used unsafely in shell commands. The current approach of only
stripping leading slashes still allows path traversal via `..` sequences, and
unquoted paths with spaces or special characters can cause command injection in
mkdir or similar commands. Import shlex module at the top of the file, then
locate all places where `output_name` or similar tensor-derived paths are used
in subprocess calls or shell command construction (around lines 2-4 imports and
also in the section around lines 156-166), and wrap these path variables with
shlex.quote() before using them in any shell command string to properly escape
special characters and prevent traversal attacks.
- Around line 44-47: The snpe-net-run command in the _run_dlc() call includes
debug-specific flags and parameters (--debug, --userbuffer_floatN_output, and
related options) that require self._debug_output_paths to be initialized, but
_run_dlc() is shared across multiple methods including analyze_layer_cycles()
which never sets this debug state, causing failures. Remove or conditionally
apply these debug-specific options from the snpe-net-run command invocations so
that _run_dlc() functions without requiring debug output paths to be set. Ensure
this fix is applied to all affected snpe-net-run calls referenced in the
comment.

---

Nitpick comments:
In `@modelconverter/packages/rvc4/analyze.py`:
- Line 37: The `_compare_to_onnx()` function creates a duplicate
InferenceSession at the `rt.InferenceSession(onnx_all_layers)` call, even though
`analyze_layer_outputs()` already creates a session for the same model. Refactor
`_compare_to_onnx()` to accept the existing InferenceSession as a parameter
instead of initializing a new one internally, then update all calls to
`_compare_to_onnx()` in `analyze_layer_outputs()` to pass the session that was
already created. This eliminates redundant model loading and memory allocation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d7f37822-b691-4023-873f-c05dd11d23bd

📥 Commits

Reviewing files that changed from the base of the PR and between 6da1965 and f3e166c.

📒 Files selected for processing (3)
  • README.md
  • constraints.txt
  • modelconverter/packages/rvc4/analyze.py

Comment thread constraints.txt Outdated
Comment thread modelconverter/packages/rvc4/analyze.py
Comment thread modelconverter/packages/rvc4/analyze.py
@dtronmans dtronmans merged commit e91b2bc into main Jun 22, 2026
5 checks passed
@dtronmans dtronmans deleted the fix/analyze branch June 22, 2026 14:38
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.

2 participants