Skip to content

fix(autotune): pre-check remote board connectivity before benchmark - #2078

Open
willg-nv wants to merge 4 commits into
NVIDIA:mainfrom
willg-nv:fix/remote-autotune-connectivity-precheck
Open

fix(autotune): pre-check remote board connectivity before benchmark#2078
willg-nv wants to merge 4 commits into
NVIDIA:mainfrom
willg-nv:fix/remote-autotune-connectivity-precheck

Conversation

@willg-nv

@willg-nv willg-nv commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

fix(autotune): pre-check remote board connectivity before benchmark

Summary

When using --remoteAutoTuningConfig, a lost connection to the remote board
causes trtexec to fail. The failure gets recorded as error: true in
autotune_states.yaml, permanently skipping those schemes on restart. This is
incorrect — the error is transient (network issue), not a property of the
scheme itself.

This PR adds a TCP connectivity pre-check before each trtexec invocation. If
the board is unreachable after configurable retries, the autotuner saves state
and exits cleanly instead of poisoning the state file.

Changes

  • common.py: Add RemoteConnectionError exception (subclass of AutotunerError)
  • benchmark.py: Add _check_remote_connectivity() and _try_connect() helpers;
    call pre-check in TrtExecBenchmark.run() before launching trtexec
  • workflows.py: Catch RemoteConnectionError in per-scheme loop, save state
    before re-raising
  • __main__.py: Add --remote_connection_retries CLI argument (default: 3)
  • CHANGELOG.rst: Add bug fix entry

Behavior

Scenario Before After
No remote autotune unchanged unchanged
Board unreachable before trtexec trtexec fails → scheme marked error: true pre-check fails → state saved → clean exit
Board reachable, trtexec succeeds latency recorded latency recorded
Board drops mid-trtexec trtexec fails → scheme marked error: true same (pre-check passed, trtexec failure recorded)

New CLI option

--remote_connection_retries N
    Number of TCP connection attempts to the remote board before aborting.
    Only relevant when --remoteAutoTuningConfig is present in trtexec args.
    Default: 3

Summary by CodeRabbit

  • Bug Fixes
    • Improved remote ONNX autotuning reliability by checking board connectivity before benchmarks run.
    • Added configurable connection retries, with three retries by default.
    • Autotuning now saves its progress and exits cleanly when the remote board is unavailable, preventing schemes from being incorrectly marked as failed.

@willg-nv
willg-nv requested review from a team as code owners August 5, 2026 10:52
@willg-nv
willg-nv requested a review from ajrasane August 5, 2026 10:52
@copy-pr-bot

copy-pr-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

ONNX Autotune checks remote board connectivity before each trtexec call, retries connections with a configurable count, and saves autotuner state when the board is unreachable.

Changes

Remote autotuning connection handling

Layer / File(s) Summary
Remote board connectivity validation
modelopt/onnx/quantization/autotune/common.py, modelopt/onnx/quantization/autotune/benchmark.py
Adds RemoteConnectionError. Parses remote configuration, retries TCP connections, and validates connectivity before and after trtexec failures.
Retry configuration wiring
modelopt/onnx/quantization/autotune/__main__.py, modelopt/onnx/quantization/autotune/workflows.py
Adds --remote_connection_retries with a default of 3, validates the range, and forwards the value to TrtExecBenchmark.
Remote failure checkpoint handling
modelopt/onnx/quantization/autotune/workflows.py, CHANGELOG.rst, docs/source/guides/9_autotune.rst
Saves autotuner state and re-raises RemoteConnectionError during baseline, region-scheme, and final-model profiling. Documents retry and resume behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant AutotuneWorkflow
  participant TrtExecBenchmark
  participant RemoteBoard
  participant trtexec
  CLI->>AutotuneWorkflow: Pass remote_connection_retries
  AutotuneWorkflow->>TrtExecBenchmark: Initialize benchmark
  TrtExecBenchmark->>RemoteBoard: Retry TCP connection
  RemoteBoard-->>TrtExecBenchmark: Connection result
  TrtExecBenchmark->>trtexec: Run benchmark after successful check
  trtexec-->>TrtExecBenchmark: Benchmark result or failure
  TrtExecBenchmark->>RemoteBoard: Recheck connectivity after failure
  RemoteBoard-->>TrtExecBenchmark: Unreachable
  TrtExecBenchmark-->>AutotuneWorkflow: Raise RemoteConnectionError
  AutotuneWorkflow->>AutotuneWorkflow: Save autotuner state
Loading

Suggested reviewers: ajrasane

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: checking remote board connectivity before autotune benchmarks.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Security Anti-Patterns ✅ Passed The PR adds no prohibited deserialization, remote-code, eval/exec, or # nosec patterns; it also changes no dependency manifests. The existing # nosec line is unchanged.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@willg-nv
willg-nv force-pushed the fix/remote-autotune-connectivity-precheck branch from f95be17 to 7ad4729 Compare August 5, 2026 10:56

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

🤖 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 `@modelopt/onnx/quantization/autotune/__main__.py`:
- Around line 318-324: Validate the remote_connection_retries argument at the
CLI boundary where trt_group defines it, rejecting values below 1 and values
above a documented finite maximum. Add the allowed upper limit to the argument
help text and ensure the validated value is what _try_connect uses, preventing
zero-attempt behavior and excessive retry delays.

In `@modelopt/onnx/quantization/autotune/workflows.py`:
- Around line 338-345: Update benchmark_onnx_model so its generic exception
handling does not swallow RemoteConnectionError: add a dedicated handler that
re-raises it before the fallback handler. Preserve the existing float("inf")
behavior for other benchmark failures, allowing the workflow handler around
benchmark_onnx_model to save state and exit on remote connection loss.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 3e201cba-baed-4f7c-b784-5ba792d08bd9

📥 Commits

Reviewing files that changed from the base of the PR and between 7afbfbc and f95be17.

📒 Files selected for processing (5)
  • CHANGELOG.rst
  • modelopt/onnx/quantization/autotune/__main__.py
  • modelopt/onnx/quantization/autotune/benchmark.py
  • modelopt/onnx/quantization/autotune/common.py
  • modelopt/onnx/quantization/autotune/workflows.py

Comment thread modelopt/onnx/quantization/autotune/__main__.py
Comment thread modelopt/onnx/quantization/autotune/workflows.py
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@willg-nv
willg-nv force-pushed the fix/remote-autotune-connectivity-precheck branch from 7ad4729 to 3eee981 Compare August 5, 2026 11:01

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (1)
modelopt/onnx/quantization/autotune/benchmark.py (1)

230-247: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Validate remote_connection_retries at the public API boundary.

A value of 0 or less makes _try_connect() execute no attempts and return None. The benchmark then treats the remote board as reachable. A very large value can block the workflow for repeated five-second connection timeouts and retry delays. Reject values below 1 and enforce a documented upper bound before storing this value.

As per path instructions, validate remote host/port and retry inputs, and enforce sensible timeouts and limits.

🤖 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 `@modelopt/onnx/quantization/autotune/benchmark.py` around lines 230 - 247,
Validate remote_connection_retries in the benchmark constructor before assigning
it to _remote_connection_retries: reject values below 1 and values above a
documented sensible maximum, using the project’s existing validation/error
conventions. Update the parameter documentation to state the accepted range,
while preserving the retry behavior for valid values.

Source: Path instructions

🤖 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 `@modelopt/onnx/quantization/autotune/benchmark.py`:
- Around line 329-330: Update region_pattern_autotuning_workflow so
RemoteConnectionError handling surrounds every benchmark_onnx_model call,
including baseline and final measurements; save the current autotuning state in
that handler before re-raising the exception, while preserving existing
per-scheme behavior.
- Around line 85-92: Update the remote URI handling in run_autotune() around
urllib.parse.urlparse to strip matching surrounding quotes from config_value
before parsing, then validate the parsed host and port. Raise
RemoteConnectionError when the hostname is missing or accessing the port
identifies an invalid port, while preserving the existing default-port lookup
for valid URIs.

---

Outside diff comments:
In `@modelopt/onnx/quantization/autotune/benchmark.py`:
- Around line 230-247: Validate remote_connection_retries in the benchmark
constructor before assigning it to _remote_connection_retries: reject values
below 1 and values above a documented sensible maximum, using the project’s
existing validation/error conventions. Update the parameter documentation to
state the accepted range, while preserving the retry behavior for valid values.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ffdbc6f1-6b9f-4123-86d2-8e22b53519ae

📥 Commits

Reviewing files that changed from the base of the PR and between 7afbfbc and 7ad4729.

📒 Files selected for processing (6)
  • CHANGELOG.rst
  • docs/source/guides/9_autotune.rst
  • modelopt/onnx/quantization/autotune/__main__.py
  • modelopt/onnx/quantization/autotune/benchmark.py
  • modelopt/onnx/quantization/autotune/common.py
  • modelopt/onnx/quantization/autotune/workflows.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • modelopt/onnx/quantization/autotune/common.py
  • modelopt/onnx/quantization/autotune/main.py
  • CHANGELOG.rst
  • modelopt/onnx/quantization/autotune/workflows.py

Comment thread modelopt/onnx/quantization/autotune/benchmark.py
Comment thread modelopt/onnx/quantization/autotune/benchmark.py
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Comment thread modelopt/onnx/quantization/autotune/benchmark.py
Comment thread modelopt/onnx/quantization/autotune/benchmark.py

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

Caution

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

⚠️ Outside diff range comments (2)
modelopt/onnx/quantization/autotune/benchmark.py (2)

73-83: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Reject a remote configuration flag with no value.

If trtexec_args ends with --remoteAutoTuningConfig, Line 78 does not set config_value and Line 82 returns. The malformed flag remains in _base_cmd. trtexec can then fail, and _benchmark_failed() can classify it as a scheme failure instead of preserving autotuner state.

Raise RemoteConnectionError when the flag has no following value.

As per path instructions, validate untrusted connection parameters and preserve remote failure handling.

Proposed fix
-        elif arg == "--remoteAutoTuningConfig" and i + 1 < len(trtexec_args):
-            config_value = trtexec_args[i + 1]
-            break
+        elif arg == "--remoteAutoTuningConfig":
+            if i + 1 >= len(trtexec_args):
+                raise RemoteConnectionError(
+                    "--remoteAutoTuningConfig requires a remote URI value"
+                )
+            config_value = trtexec_args[i + 1]
+            break
🤖 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 `@modelopt/onnx/quantization/autotune/benchmark.py` around lines 73 - 83,
Update the remote configuration argument parsing in the benchmark setup to raise
RemoteConnectionError when --remoteAutoTuningConfig appears without a following
value, rather than returning and leaving the malformed flag in _base_cmd.
Preserve existing handling for inline and separate valid values and ensure the
error follows the existing remote failure path.

Source: Path instructions


237-254: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Validate remote_connection_retries in TrtExecBenchmark.

_try_connect performs zero attempts for values below 1 and accepts values above 10. Enforce 1 <= remote_connection_retries <= 10 for direct API callers, not only in the CLI.

🤖 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 `@modelopt/onnx/quantization/autotune/benchmark.py` around lines 237 - 254,
Validate remote_connection_retries in TrtExecBenchmark.__init__ before assigning
it to _remote_connection_retries, requiring an integer value from 1 through 10
inclusive. Reject values outside this range for direct API callers while
preserving the existing retry behavior for valid inputs.

Source: Path instructions

🤖 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 `@modelopt/onnx/quantization/autotune/benchmark.py`:
- Around line 89-97: Update the remote URI validation errors around parsed.port
and the hostname check to avoid including config_value, which may contain
credentials. Build messages using only the URI scheme, hostname, and port, while
preserving the existing RemoteConnectionError types and exception chaining for
invalid ports.

In `@modelopt/onnx/quantization/autotune/workflows.py`:
- Around line 298-303: Update all three exception handlers around the baseline,
tuning, and final benchmark flows to log the saved checkpoint path after
autotuner.save_state(str(state_path)) succeeds and before re-raising. Use
state_path in the message so users can locate the resume checkpoint, while
preserving the existing save-and-reraise behavior.

---

Outside diff comments:
In `@modelopt/onnx/quantization/autotune/benchmark.py`:
- Around line 73-83: Update the remote configuration argument parsing in the
benchmark setup to raise RemoteConnectionError when --remoteAutoTuningConfig
appears without a following value, rather than returning and leaving the
malformed flag in _base_cmd. Preserve existing handling for inline and separate
valid values and ensure the error follows the existing remote failure path.
- Around line 237-254: Validate remote_connection_retries in
TrtExecBenchmark.__init__ before assigning it to _remote_connection_retries,
requiring an integer value from 1 through 10 inclusive. Reject values outside
this range for direct API callers while preserving the existing retry behavior
for valid inputs.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c53cc04b-6637-47ba-8028-ea8992e5e0dd

📥 Commits

Reviewing files that changed from the base of the PR and between 3eee981 and 05a8474.

📒 Files selected for processing (2)
  • modelopt/onnx/quantization/autotune/benchmark.py
  • modelopt/onnx/quantization/autotune/workflows.py

Comment thread modelopt/onnx/quantization/autotune/benchmark.py
Comment thread modelopt/onnx/quantization/autotune/workflows.py
Comment thread modelopt/onnx/quantization/autotune/workflows.py Outdated
willg-nv and others added 4 commits August 7, 2026 08:05
When using --remoteAutoTuningConfig, test TCP connectivity to the remote
board before each trtexec invocation. If unreachable after configurable
retries (--remote_connection_retries, default 3), save state and exit
cleanly instead of running trtexec which would fail and permanently mark
schemes as errored in autotune_states.yaml.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Will Guo <willg@nvidia.com>
- Strip matching surrounding quotes from config_value before urlparse
  (handles embedded quotes from --remoteAutoTuningConfig=\"...\")
- Raise RemoteConnectionError on missing hostname or invalid port
  instead of silently returning
- Add _benchmark_failed() to re-check connectivity after trtexec failure;
  raises RemoteConnectionError if board dropped mid-execution so the
  scheme is not incorrectly recorded as inf
- Wrap baseline and final benchmark_onnx_model calls with
  RemoteConnectionError handling that saves autotuner state before
  re-raising

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Will Guo <willg@nvidia.com>
…sume

The parser doesn't have a --resume option; state is detected automatically
on re-run. Update the user-facing message accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Will Guo <willg@nvidia.com>
@willg-nv
willg-nv force-pushed the fix/remote-autotune-connectivity-precheck branch from a219970 to c045c3d Compare August 7, 2026 08:05
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