Skip to content

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

Open
willg-nv wants to merge 1 commit 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 1 commit 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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 792b4212-4e29-4688-9e96-96793abb57c8

📥 Commits

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

📒 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 (6)
  • docs/source/guides/9_autotune.rst
  • CHANGELOG.rst
  • modelopt/onnx/quantization/autotune/benchmark.py
  • modelopt/onnx/quantization/autotune/common.py
  • modelopt/onnx/quantization/autotune/main.py
  • modelopt/onnx/quantization/autotune/workflows.py

📝 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 trtexec execution.
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 the autotuner checkpoint and re-raises RemoteConnectionError when the remote board is unreachable. 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
  RemoteBoard-->>TrtExecBenchmark: Unreachable
  TrtExecBenchmark-->>AutotuneWorkflow: Raise RemoteConnectionError
  AutotuneWorkflow->>AutotuneWorkflow: Save autotuner checkpoint
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 summarizes the main change: checking remote board connectivity before each autotuning benchmark.
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.
Security Anti-Patterns ✅ Passed PR passes all six security requirements: no unsafe deserialization patterns, no hardcoded credentials, no eval/exec risks, no new nosec comments, and no non-permissive dependencies. Standard librar...
✨ 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.

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>
@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 on lines +85 to +92
parsed = urllib.parse.urlparse(config_value)
hostname = parsed.hostname
if not hostname:
return

port = parsed.port
if port is None:
port = _DEFAULT_PORTS.get(parsed.scheme, 22)

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Normalize and validate the remote URI.

The documented CLI command reaches this code with quotes in the --remoteAutoTuningConfig value because run_autotune() uses str.split(). urlparse() then produces no hostname, and Line 88 returns without a TCP check. Strip matching quotes before parsing. Raise RemoteConnectionError when the host is missing or the port is invalid.

Based on supplied workflow and documentation context, run_autotune() uses str.split() for the documented remote configuration value.

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

Comment on lines +329 to +330
_check_remote_connectivity(self._base_cmd, retries=self._remote_connection_retries)

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Save state for baseline and final connectivity failures.

Line 329 runs for baseline, per-scheme, and final measurements. The supplied region_pattern_autotuning_workflow() catches RemoteConnectionError only around per-scheme measurements. A baseline failure exits without saving state. A final failure can exit after committing the final region but before persisting that commit. Catch this exception at a scope that covers every benchmark_onnx_model() call, save the state, then re-raise it.

Based on supplied workflow context, the current state-save handler surrounds only per-scheme measurements.

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

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

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