Skip to content

[TRTLLM-13141][feat] Add backend-agnostic SourceIdentity gate for weight sharing#14878

Merged
chienchunhung merged 8 commits into
NVIDIA:mainfrom
chienchunhung:feat/source-identity-weight-sharing
Jun 12, 2026
Merged

[TRTLLM-13141][feat] Add backend-agnostic SourceIdentity gate for weight sharing#14878
chienchunhung merged 8 commits into
NVIDIA:mainfrom
chienchunhung:feat/source-identity-weight-sharing

Conversation

@chienchunhung

@chienchunhung chienchunhung commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features

    • Added weight-sharing compatibility verification system with source identity tracking for distributed weight-loading scenarios (MX checkpoints, GMS storage).
    • Introduces pre-transfer compatibility checks to validate safe weight sharing across configurations before attempting transfers.
  • Tests

    • Added comprehensive test coverage for weight-sharing compatibility system, identity fingerprinting, matching behavior, and policy enforcement.

Description

This PR introduces a backend-agnostic SourceIdentity — a serializable, layered fingerprint of every configuration choice that affects how a model's weights are laid out in memory — and wires it into the two weight-sharing receiver paths so a consumer can verify layout compatibility before consuming shared weights.

Motivation. Weight-sharing receivers (MX peer-to-peer transfer, GMS read-only materialize) currently consume pre-laid-out weights without validating that the producer ("source") and consumer agree on the layout-affecting configuration (model/arch/dtype, quantization, kernel backends/fusion, and parallel layout). A mismatch can silently produce incorrect results. This adds a single, shared compatibility gate.

What's added (tensorrt_llm/_torch/weight_sharing/):

  • SourceIdentity: a frozen dataclass split into a global fingerprint (model, quant, backend, parallel sizes — must match across all ranks) and a per-rank shard fingerprint (this rank's TP/PP/EP/CP slice). Built once from ModelConfig + Mapping via SourceIdentity.from_model_config(...). Fully serializable (to_dict/from_dict/to_json/from_json) so a publisher can store it and a receiver can reconstruct it.
  • check_source_identity(local, source, policy) with three policies:
    • WARN_FALLBACK (default): warn and fall back to non-shared loading on mismatch.
    • STRICT: raise SourceIdentityMismatchError on mismatch.
    • ENFORCE: share regardless (caller explicitly trusts the source, e.g. enforced cross-run sharing).
  • A format_version guard so incompatible fingerprint projections never match.

Integration points:

  • ModelLoader (pyexecutor/model_loader.py): builds the receiver's local SourceIdentity once, early, and threads it through the weight-load path as the single authority for all downstream gates.
  • MX checkpoint loader (models/checkpoints/mx/checkpoint_loader.py): a pre-transfer P2P gate — on mismatch it skips the transfer before any RDMA work starts and falls back to disk (no bandwidth/slot/buffer wasted), using WARN_FALLBACK.
  • GMS RO path (memory/gpu_memory_backend.py): a pre-materialize gate — GMS has no disk-fallback path, so a mismatch raises under STRICT.

Scope / follow-ups. The publisher-side identity fetch is intentionally stubbed behind single seams (MXCheckpointLoader._fetch_source_identity, GMSBackend.get_source_identity), both currently returning None (gate is inert; existing disk fallback still guards correctness). They are tracked by SOURCE-IDENTITY/MX-2 and SOURCE-IDENTITY/GMS, to be wired once upstream exposes a metadata channel to carry the serialized identity.
This PR is not an API change — it adds an internal _torch utility and gate logic; no public LlmArgs/API signatures change. Runtime behavior is unchanged until the publisher seams are wired, except that an explicit, verifiable mismatch now falls back (MX) or raises (GMS) instead of silently proceeding.

Test Coverage

New unit tests under tests/unittest/_torch/weight_sharing/ (mock-based — no real model, GPU, or RDMA; shared fakes in _source_identity_fakes.py to avoid duplication):

  • test_source_identity.py — fingerprint logic: identical-config match; per-field mismatch detection (backend, quant, parallel-size, shard); compare_global/compare_shard selectivity; enforced sharing skips global; serialization round-trip; all three check_source_identity policies; format_version mismatch never matches.
  • test_mx_source_identity_gate.py — drives the real MXCheckpointLoader._source_identity_compatible gate: proceeds on match, falls back on mismatch, proceeds when no local identity (legacy callers), proceeds when the publisher identity is unavailable, the fetch seam returns None by contract, and load_weights consumes the source_identity kwarg without leaking it into the disk-fallback signature.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51753 [ run ] triggered by Bot. Commit: 6320aea Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51753 [ run ] completed with state SUCCESS. Commit: 6320aea
/LLM/main/L0_MergeRequest_PR pipeline #41126 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51886 [ run ] triggered by Bot. Commit: 8c155e7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51886 [ run ] completed with state SUCCESS. Commit: 8c155e7
/LLM/main/L0_MergeRequest_PR pipeline #41242 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

…ght sharing

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
… layout

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung
chienchunhung force-pushed the feat/source-identity-weight-sharing branch from 8c155e7 to 0b8f30c Compare June 3, 2026 23:43
…aths

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51952 [ run ] triggered by Bot. Commit: d6cd918 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #51952 [ run ] completed with state FAILURE. Commit: d6cd918
/LLM/main/L0_MergeRequest_PR pipeline #41302 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>
@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52145 [ run ] triggered by Bot. Commit: dd8fba9 Link to invocation

@chienchunhung
chienchunhung marked this pull request as ready for review June 4, 2026 21:22
@chienchunhung
chienchunhung requested review from a team as code owners June 4, 2026 21:22
@chienchunhung
chienchunhung requested a review from symphonylyh June 4, 2026 21:22
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a backend-agnostic weight-sharing source identity system that fingerprints configurations and realized tensor layouts to gate whether receivers can safely consume shared weights from writers. The system is integrated into MX and GMS checkpoint loading paths with comprehensive test coverage.

Changes

Weight-Sharing Source Identity System

Layer / File(s) Summary
Core Source Identity Fingerprinting System
tensorrt_llm/_torch/weight_sharing/source_identity.py
Implements layered fingerprinting with stable SHA-256 hashing of global config (architecture, quantization, backend, parallelism) and per-rank tensor layouts; provides SourceIdentity dataclass with matching/serialization and check_weight_sharing_compatibility API with configurable policies (WARN_FALLBACK, STRICT, ENFORCE).
Weight-Sharing Module Public API
tensorrt_llm/_torch/weight_sharing/__init__.py
Establishes backend-agnostic public API surface by re-exporting identity types, compatibility checking, decision/policy enums via __all__.
GPU Memory Backend Protocol and GMS Adapter Updates
tensorrt_llm/_torch/memory/gpu_memory_backend.py
Extends GPUMemoryBackend protocol with get_source_identity() method; adds get_source_identity() stub to GMSBackend; refreshes docstrings clarifying RO/RW lifecycle, allocation scoping, stray-parameter migration, and GMS teardown semantics.
MX Checkpoint Loader Source Identity Gate
tensorrt_llm/_torch/models/checkpoints/mx/checkpoint_loader.py
Integrates source identity compatibility gating into MXCheckpointLoader.load_weights via _source_identity_compatible and _fetch_source_identity helpers; stores receiver identity from kwargs and gates MX P2P transfer before upstream loading, falling back to disk on gate failure.
Model Loader Source Identity Construction and Gating
tensorrt_llm/_torch/pyexecutor/model_loader.py
Constructs _source_identity from finalized module and config when gated by _needs_source_identity for GMS/MX paths; passes identity into AUTO-path checkpoint loaders; adds strict pre-materialization _check_gms_source_identity gate for GMS RO path.
Test Infrastructure: Fakes and Existing Test Updates
tests/unittest/_torch/weight_sharing/_source_identity_fakes.py, tests/unittest/_torch/pyexecutor/test_model_loader_mx.py
Provides lightweight fake model/config/mapping objects and identity factories for testing; updates existing MX test mock to include config.mapping attribute.
GMS Source Identity Gate Integration Tests
tests/unittest/_torch/weight_sharing/test_gms_source_identity_gate.py
Tests ModelLoader._check_gms_source_identity gate behavior: passes on matching identity, raises on mismatch or unavailable writer identity; validates _needs_source_identity gating.
MX Source Identity Gate Integration Tests
tests/unittest/_torch/weight_sharing/test_mx_source_identity_gate.py
Tests MXCheckpointLoader gate via _source_identity_compatible with matching/mismatched/missing identities; verifies load_weights kwarg handling and disk-fallback behavior.
Source Identity Core Unit Tests
tests/unittest/_torch/weight_sharing/test_source_identity.py
Comprehensive unit tests for SourceIdentity fingerprinting and check_weight_sharing_compatibility: matching across configs, rank defaulting, mismatch attribution, shard vs global comparisons, serialization, and all policy behaviors with error handling.

Sequence Diagram(s)

sequenceDiagram
  participant ML as ModelLoader
  participant MC as Module Construction
  participant SIC as _needs_source_identity
  participant SIB as _source_identity Build
  participant CL as CheckpointLoader
  participant GG as _check_gms_source_identity
  participant GB as GMSBackend
  
  ML->>MC: construct module
  ML->>SIC: check if needed (GMS/MX)
  alt Gate triggered
    SIC-->>ML: True
    ML->>SIB: build from config+module
    SIB-->>ML: source_identity
  end
  
  ML->>CL: load_weights(source_identity=...)
  
  alt GMS RO Path
    ML->>GG: _check_gms_source_identity()
    GG->>GB: get_source_identity()
    GB-->>GG: writer identity
    GG->>GG: check_weight_sharing_compatibility()
    alt Compatible
      GG-->>ML: proceed
    else Incompatible
      GG-->>ML: raise SourceIdentityMismatchError
    end
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested labels

Community want to contribute

Suggested reviewers

  • pcastonguay
  • tijyojwad
  • brb-nv
  • QiJune
  • moraxu
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.29% 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
Title check ✅ Passed The PR title clearly and specifically identifies the main feature being added: a backend-agnostic SourceIdentity gate for weight sharing, with proper JIRA ticket and feature type.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering motivation, implementation details, integration points, scope/follow-ups, test coverage, and all checklist items with the required checkbox marked.
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

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

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52365 [ run ] completed with state SUCCESS. Commit: dd8fba9
/LLM/main/L0_MergeRequest_PR pipeline #41663 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52424 [ run ] triggered by Bot. Commit: dd8fba9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52424 [ run ] completed with state FAILURE. Commit: dd8fba9
/LLM/main/L0_MergeRequest_PR pipeline #41719 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52605 [ run ] triggered by Bot. Commit: dd8fba9 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #52605 [ run ] completed with state SUCCESS. Commit: dd8fba9
/LLM/main/L0_MergeRequest_PR pipeline #41887 completed with status: 'SUCCESS'

CI Report

Link to invocation

@KavinKrishnan

Copy link
Copy Markdown

lgtm

@galletas1712 galletas1712 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm!

@Funatiq Funatiq left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Lgtm

Comment thread tests/unittest/_torch/weight_sharing/test_source_identity.py
Signed-off-by: Chien-Chun Hung <2679986+chienchunhung@users.noreply.github.com>

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "A10-PyTorch-1,A10-PyTorch-2"

@chienchunhung
chienchunhung requested a review from Funatiq June 11, 2026 17:09

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "A10-PyTorch-1,A10-PyTorch-2"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53623 [ run ] triggered by Bot. Commit: 2a46f1b Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53623 [ run ] completed with state SUCCESS. Commit: 2a46f1b
/LLM/main/L0_MergeRequest_PR pipeline #42768 (Partly Tested) completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

@chienchunhung

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53680 [ run ] triggered by Bot. Commit: 2a46f1b Link to invocation

@chienchunhung
chienchunhung enabled auto-merge (squash) June 11, 2026 22:54
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #53680 [ run ] completed with state SUCCESS. Commit: 2a46f1b
/LLM/main/L0_MergeRequest_PR pipeline #42817 completed with status: 'SUCCESS'

CI Report

Link to invocation

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.

6 participants