Skip to content

[#11032][None] AutoDeploy support for GLM 4.7 flash - #11150

Closed
bmarimuthu-nv wants to merge 20 commits into
NVIDIA:mainfrom
nv-auto-deploy:bala/glm4.7-flash-standalone
Closed

[#11032][None] AutoDeploy support for GLM 4.7 flash#11150
bmarimuthu-nv wants to merge 20 commits into
NVIDIA:mainfrom
nv-auto-deploy:bala/glm4.7-flash-standalone

Conversation

@bmarimuthu-nv

@bmarimuthu-nv bmarimuthu-nv commented Jan 30, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for DeepSeekV3, GLM-4.7-Flash, and GLM4-MoE-Lite models for deployment.
    • Introduced improved multi-head latent attention backends with FlashInfer and Torch implementations.
    • Added new cookbook demonstrating GLM-4.7-Flash deployment with TensorRT-LLM.
  • Documentation

    • Added GLM-4.7-Flash deployment example notebook with environment setup, server configuration, and client usage samples.
  • Bug Fixes

    • Updated attention backend configurations for improved cache handling and resource management.

fixes:
#11032
#11113

Description

Test Coverage

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)

  • 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

/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...

Provide a user friendly way for developers to interact with a Jenkins server.

Run /bot [-h|--help] to print this help message.

See details below for each supported subcommand.

Details

run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]

Launch build/test pipelines. All previously running jobs will be killed.

--reuse-test (optional)pipeline-id (OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.

--disable-reuse-test (OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.

--disable-fail-fast (OPTIONAL) : Disable fail fast on build/tests/infra failures.

--skip-test (OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.

--stage-list "A10-PyTorch-1, xxx" (OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.

--gpu-type "A30, H100_PCIe" (OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.

--test-backend "pytorch, cpp" (OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.

--only-multi-gpu-test (OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.

--disable-multi-gpu-test (OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.

--add-multi-gpu-test (OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.

--post-merge (OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.

--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" (OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".

--detailed-log (OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.

--debug (OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in the stage-list parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.

For guidance on mapping tests to stage names, see docs/source/reference/ci-overview.md
and the scripts/test_to_stage_mapping.py helper.

kill

kill

Kill all running builds associated with pull request.

skip

skip --comment COMMENT

Skip testing for latest commit on pull request. --comment "Reason for skipping build/test" is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

reuse-pipeline

reuse-pipeline

Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.

Comment thread tensorrt_llm/_torch/auto_deploy/config/default.yaml Outdated

@lucaslie lucaslie Feb 3, 2026

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.

this should be configured as --args.yaml-extra not as --yaml-extra

Comment thread examples/auto_deploy/.gitignore
Comment thread examples/auto_deploy/deepseek_mini.yaml
Comment thread examples/auto_deploy/cookbooks/glm_4.7_flash_trtllm_cookbook.ipynb Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/config/default.yaml
Comment thread tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/shim/interface.py
Comment thread tensorrt_llm/_torch/auto_deploy/transform/interface.py Outdated
Comment thread tensorrt_llm/_torch/auto_deploy/transform/optimizer.py
Comment thread tensorrt_llm/_torch/auto_deploy/utils/logger.py
Comment thread tensorrt_llm/bench/benchmark/__init__.py Outdated
lucaslie and others added 13 commits February 3, 2026 17:35
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
@suyoggupta

Copy link
Copy Markdown
Collaborator

@bmarimuthu-nv : is this ready for review? can it be moved out of draft and cleaned up?

@bmarimuthu-nv
bmarimuthu-nv marked this pull request as ready for review February 4, 2026 21:12
@bmarimuthu-nv
bmarimuthu-nv requested review from a team as code owners February 4, 2026 21:12
@suyoggupta suyoggupta changed the title Bala/glm4.7 flash standalone [#11032][None] AutoDeploy support for GLM 4.7 flash Feb 4, 2026
@coderabbitai

coderabbitai Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR restructures MLA (Multi-Head Latent Attention) from a single monolithic implementation into a modular backend architecture with multiple execution paths (torch, torch_backend, flashinfer). It introduces new model implementations for DeepSeekV3 and GLM4 MoE Lite, removes the patching mechanism, expands logging/debugging utilities, and adds comprehensive test coverage for the new backends.

Changes

Cohort / File(s) Summary
MLA Backend Refactoring & Organization
tensorrt_llm/_torch/auto_deploy/custom_ops/mla.py, tensorrt_llm/_torch/auto_deploy/custom_ops/mla/__init__.py
Removed monolithic MLA implementation (258 lines) and created modular MLA package with unified exports for MultiHeadLatentAttention, FlashInferMLAAttention, torch_mla, and related backends.
MLA Custom Operations Implementation
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_mla.py, tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py, tensorrt_llm/_torch/auto_deploy/custom_ops/mla/flashinfer_mla.py
Introduces three independent MLA backend implementations: torch_mla (source op with KV expansion), torch_backend_mla (cached op with absorption), and flashinfer_mla (paged cache with planner-based prefill/decode). Flashinfer backend is particularly dense with planning logic, metadata handling, and ragged/paged attention patterns.
Resource Handler & Paging Support
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py, tensorrt_llm/_torch/auto_deploy/shim/interface.py
Adds ContiguousPagedResourceHandler class for contiguous paged memory allocation and updates PagedResourceHandler initialization. Integrates contiguous paged resource tracking into KVCacheManager initialization logic.
Model Implementations
tensorrt_llm/_torch/auto_deploy/models/custom/modeling_deepseek.py, tensorrt_llm/_torch/auto_deploy/models/custom/modeling_glm4_moe_lite.py
Introduces complete export-ready DeepSeekV3ForCausalLM (655 lines) and Glm4MoeLiteForCausalLM (841 lines) with custom components (MLP, MoE, attention, embeddings) integrated with auto_deploy custom ops.
Model Registry & Cleanup
tensorrt_llm/_torch/auto_deploy/models/custom/__init__.py, tensorrt_llm/_torch/auto_deploy/models/patches/deepseek.py, tensorrt_llm/_torch/auto_deploy/models/quant_config_reader.py
Replaces Eagle3DrafterForCausalLM exports with DeepSeekV3ForCausalLM and Glm4MoeLiteForCausalLM. Removes entire 185-line patching module for DeepSeek. Updates quantization exclusions.
Infrastructure & Utilities
tensorrt_llm/_torch/auto_deploy/utils/logger.py, tensorrt_llm/_torch/auto_deploy/export/export.py, tensorrt_llm/_torch/auto_deploy/transform/interface.py, tensorrt_llm/_torch/auto_deploy/transform/optimizer.py
Expands logger with debug dumping capabilities (graph metadata extraction, SSA formatting, debug artifact persistence). Adds module-hierarchy-based node renaming in export. Integrates graph dump calls in transform lifecycle.
Legacy Operations Cleanup
tensorrt_llm/_torch/auto_deploy/custom_ops/torch_attention.py, tensorrt_llm/_torch/auto_deploy/custom_ops/torch_backend_attention.py
Removes 297 lines of legacy MLA/update_kv_cache implementations. Introduces internal _update_kv_cache helper in torch_backend_attention to replace removed public function.
Test Suite Additions
tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_torch_mla_op.py, tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_flashinfer_mla_op.py
Adds 780 and 1536 lines of test coverage for torch MLA and flashinfer MLA backends respectively, including reference implementations, cache validation, and multi-phase workflows.
Model Tests & Cleanup
tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_deepseek_custom.py, tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_glm4_moe_lite_modeling.py, tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_deepseek_patches.py
Adds 494 and 652 lines of component and numerical equivalence tests for custom models. Removes 110-line patching test module.
Configuration & Examples
docs/source/torch/auto_deploy/advanced/workflow.md, examples/auto_deploy/model_registry/configs/glm-4.7-flash.yaml, examples/auto_deploy/deepseek_mini.yaml, examples/auto_deploy/.gitignore, examples/auto_deploy/cookbooks/glm_4.7_flash_trtllm_cookbook.ipynb
Updates MLA backend reference in documentation. Adds GLM-4.7-Flash configuration and DeepSeek mini configuration. Unignores deepseek_mini.yaml. Adds comprehensive GLM-4.7-Flash deployment cookbook with setup, server, and client examples.
Integration Tests
tests/integration/defs/accuracy/test_llm_api_autodeploy.py, tensorrt_llm/bench/benchmark/__init__.py, tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_update_kv_cache.py
Adds TestGLM4Flash accuracy test class. Triggers custom model registration import for autodeploy backend. Updates KV cache test to use relocated _update_kv_cache function.
Default Configuration Update
tensorrt_llm/_torch/auto_deploy/config/default.yaml
Migrates insert_cached_mla_attention backend from MultiHeadLatentAttention to flashinfer_mla with requires_shape_prop flag.
Documentation Cleanup
tensorrt_llm/_torch/auto_deploy/custom_ops/README.md
Removes operator catalog table (35 lines) from custom ops README.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is almost entirely the template placeholder text with no actual description of changes, objectives, test coverage, or completion of the checklist items. Fill in the Description section explaining what changes are made and why, list relevant test coverage, complete the PR Checklist items, and ensure compliance with coding guidelines and documentation requirements.
Docstring Coverage ⚠️ Warning Docstring coverage is 60.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Bala/glm4.7 flash standalone' is vague and does not clearly describe the main change. It appears to reference a branch name rather than summarizing the actual implementation. Revise the title to clearly describe the primary change (e.g., '[feat] Add GLM-4.7-Flash standalone model and FlashInfer MLA backend' or similar) following the repository's PR title template.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@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: 14

Caution

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

⚠️ Outside diff range comments (2)
tensorrt_llm/_torch/auto_deploy/models/quant_config_reader.py (1)

1-7: ⚠️ Potential issue | 🟠 Major

Add the standard NVIDIA copyright header.

This source file is missing the required NVIDIA copyright header with the latest modification year. Please add the repo’s standard header before the module docstring.

tensorrt_llm/_torch/auto_deploy/shim/interface.py (1)

323-330: ⚠️ Potential issue | 🟠 Major

Guard CachedSequenceInterface.to() against unallocated contiguous caches.
Contiguous paged resources are stored as None until after KVCacheManager creation. If .to() is called earlier, it will attempt None.to(...) and raise. Also, the current to() path discards the returned tensor.

🛠️ Suggested fix
 def to(self, *args, **kwargs) -> None:
     self.info.to(*args, **kwargs)
     # Only move locally-allocated caches (paged/state caches are managed by cache managers)
     for name, cache in self._caches.items():
-        if name not in self._paged_cache_order and name not in self._state_resource_order:
-            cache.to(*args, **kwargs)
+        if (
+            name not in self._paged_cache_order
+            and name not in self._state_resource_order
+            and name not in self._contiguous_paged_cache_order
+        ):
+            if cache is not None:
+                self._caches[name] = cache.to(*args, **kwargs)
🤖 Fix all issues with AI agents
In `@docs/source/torch/auto_deploy/advanced/workflow.md`:
- Around line 18-20: The example config uses "insert_cached_mla_attention":
{"backend": "torch_mla"} while the current default is "flashinfer_mla"; update
the example or add a clarifying note: either change "torch_mla" to
"flashinfer_mla" for consistency, or add a comment next to
insert_cached_mla_attention (and optionally insert_cached_attention) explaining
both supported backends ("torch_mla" vs "flashinfer_mla") and when to pick each
one, and ensure compile_model/backends still align with the chosen MLA backend.

In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/__init__.py`:
- Around line 1-13: Add the missing NVIDIA copyright header to the top of the
module (above the module docstring) following the project's standard header
format (include organization name, year range, and any SPDX identifier if used).
Update tensorrt_llm._torch.auto_deploy.custom_ops.mla.__init__ (the file that
exports MultiHeadLatentAttention, FlashInferMLAAttention, torch_mla,
torch_backend_mla_with_cache, flashinfer_mla_with_cache) by inserting the
canonical NVIDIA header block as the very first lines of the file so the
existing docstring and imports remain unchanged.

In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/flashinfer_mla.py`:
- Line 1: Add the required NVIDIA copyright header to the top of
flashinfer_mla.py: insert the standard NVIDIA file header comment (including
"Copyright (c) <year>, NVIDIA CORPORATION. All rights reserved." with the year
being the latest meaningful modification) before the module docstring in
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/flashinfer_mla.py so the
file-level header precedes the existing triple-quoted module docstring and
complies with project coding guidelines.

In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py`:
- Line 1: The file lacks the required NVIDIA copyright header; add the standard
NVIDIA copyright comment block (including the year of latest meaningful
modification) at the very top of
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py before the
existing module docstring ("""Custom ops for MultiHead Latent Attention (MLA)
with FlashInfer-compatible cache."""), ensuring the header follows the project's
canonical format and includes the correct year.

In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_mla.py`:
- Line 1: The file torch_mla.py is missing the required NVIDIA copyright header;
prepend the standard NVIDIA copyright header block (including "Copyright (c)
<year>, NVIDIA CORPORATION. All rights reserved." with the year set to the
latest meaningful modification) at the top of torch_mla.py before the module
docstring ("""Torch reference implementation for Multi-head Latent Attention
(MLA).""") so the file complies with the TensorRT-LLM source file guidelines.

In `@tensorrt_llm/_torch/auto_deploy/custom_ops/torch_backend_attention.py`:
- Around line 26-47: The function _update_kv_cache mutates k_cache and v_cache
in-place but is annotated to return torch.Tensor; change the signature to return
None (-> None) to reflect in-place behavior, and ensure there are no return
statements in _update_kv_cache so type checkers and callers treat it as a void
function.

In `@tensorrt_llm/_torch/auto_deploy/models/custom/__init__.py`:
- Around line 1-4: Add the required NVIDIA copyright header at the top of this
source file (above the imports) so the file that defines/exports
DeepSeekV3ForCausalLM, Glm4MoeLiteForCausalLM, NemotronFlashForCausalLM,
NemotronFlashPreTrainedTokenizerFast, and NemotronHForCausalLM includes the
company header text; insert the standard multi-line header block exactly as used
in other project files and ensure it precedes all code and imports.

In `@tensorrt_llm/_torch/auto_deploy/models/custom/modeling_deepseek.py`:
- Line 1: Update the file header in modeling_deepseek.py to reflect the correct
year: change the copyright line that currently says "Copyright (c) 2025, NVIDIA
CORPORATION. All rights reserved." to use 2026 instead; ensure the updated
header remains otherwise unchanged and matches the format used across other
TensorRT-LLM source files.

In `@tensorrt_llm/_torch/auto_deploy/models/custom/modeling_glm4_moe_lite.py`:
- Around line 1-2: Update the file header year from 2025 to 2026 by editing the
top copyright comment; specifically change the line beginning with "Copyright
(c) 2025, NVIDIA CORPORATION. All rights reserved." to use 2026 so the file
(modeling_glm4_moe_lite.py) reflects the latest modification year.

In `@tensorrt_llm/_torch/auto_deploy/shim/interface.py`:
- Around line 346-352: Contiguous paged caches in _contiguous_paged_cache_order
are left at the old shape after resize_kv_cache_manager() recreates
_kv_cache_manager, causing shape mismatches; update the code so that after
_kv_cache_manager is resized/recreated you recompute num_pages =
self._kv_cache_manager.blocks_in_primary_pool and page_size =
self._kv_cache_manager.tokens_per_block and then reallocate each contiguous
cache by calling handler.allocate(self.info, num_pages, page_size) and storing
the result back into self._caches[name] (optionally releasing or overwriting the
old cache first) to ensure caches match the new KVCacheManager shape.

In `@tensorrt_llm/_torch/auto_deploy/transform/optimizer.py`:
- Around line 73-77: Remove the commented-out debug block (the lines referencing
t_name == "compile_model", run_comparison, and breakpoint) from
tensorrt_llm/_torch/auto_deploy/transform/optimizer.py to eliminate debugging
artifacts and fix the formatting error; if you want to preserve the debug
capability instead of deleting it, wrap the logic in a conditional gated by an
environment variable (similar to AD_DUMP_GRAPHS_DIR), e.g., check os.environ and
only call run_comparison(mod, cm, self.factory, output_dir=...) when enabled,
ensuring no leftover commented code or stray breakpoint() calls remain.

In `@tensorrt_llm/_torch/auto_deploy/utils/logger.py`:
- Around line 1-11: The project imports dill and safetensors in
tensorrt_llm._torch.auto_deploy.utils.logger (the symbols dill and
safetensors.torch.save_file / safetensors_save), but these packages aren't
declared as install-time dependencies; update the project's dependency metadata
(e.g., requirements.txt, setup.py install_requires, or pyproject.toml
[project.dependencies]) to include dill and safetensors (use the appropriate
package names on PyPI) and pin or specify compatible version ranges, then run
dependency install to validate imports succeed.

In `@tests/integration/defs/accuracy/test_llm_api_autodeploy.py`:
- Around line 359-392: The disable_overlap_scheduler flag in
TestGLM4Flash.get_default_kwargs is set to False but differs from the model
registry's configuration; update get_default_kwargs to match the registry flag
(set "disable_overlap_scheduler": True) to keep behavior consistent, or
explicitly document the intentional mismatch by adding a clear comment in the
TestGLM4Flash class and in get_default_kwargs noting why tests require False
while the deployed model uses True; refer to the TestGLM4Flash class and
get_default_kwargs to locate the change and to the "disable_overlap_scheduler"
key to update or document.

In
`@tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_glm4_moe_lite_modeling.py`:
- Around line 485-523: Remove the debug print statements in the numerical
equivalence test: delete or gate all prints that reference hf_state_dict,
custom_state_dict, custom_moe, hf_gate_up, converted_gate_0, and loaded_gate_0
(the blocks printing shapes, slices, and the "=== ..." headers). Keep the actual
assertions and the call to _convert_hf_moe_state_dict_to_custom and
custom_moe.load_state_dict as-is; if logging is desired for debugging, wrap the
prints behind an explicit debug flag (e.g., a module-level DEBUG or an env var)
so CI runs remain quiet.
🧹 Nitpick comments (9)
examples/auto_deploy/deepseek_mini.yaml (1)

1-2: Clarify the config path in the run command.

If users run from repo root, the current comment may be ambiguous. Consider using the explicit relative path for the YAML.

💡 Suggested comment tweak
-# python build_and_run_ad.py --model "deepseek-ai/DeepSeek-R1" --args.yaml-extra "deepseek_mini.yaml"
+# python build_and_run_ad.py --model "deepseek-ai/DeepSeek-R1" --args.yaml-extra "examples/auto_deploy/deepseek_mini.yaml"
tensorrt_llm/_torch/auto_deploy/utils/logger.py (1)

317-353: Broad exception handling is acceptable for debug utilities, but consider logging exception types.

The except Exception clauses (Lines 321, 333, 352) are flagged by static analysis, but in debug/dump utilities, this pattern is reasonable—failing to dump artifacts shouldn't crash the main pipeline.

However, logging only {e} may lose valuable context. Consider including the exception type for easier debugging:

💡 Optional: Include exception type in warning messages
         except Exception as e:
-            self.warning(f"Failed to dump GraphModule: {e}")
+            self.warning(f"Failed to dump GraphModule: {type(e).__name__}: {e}")

Apply similarly to lines 333-334 and 352-353.

tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)

1028-1067: Align ContiguousPagedResourceHandler.allocate with the ResourceHandler contract.
This override adds required parameters (num_pages, page_size), so any code treating handlers polymorphically as ResourceHandler could call allocate(sequence_info) and crash. Consider keeping allocate(sequence_info) as the contract and exposing a separate method (or optional kwargs) for the contiguous path.

tensorrt_llm/_torch/auto_deploy/models/custom/modeling_glm4_moe_lite.py (1)

19-30: Prefer module imports to preserve namespace.
This file imports individual symbols from several modules (e.g., from transformers import AutoConfig, PretrainedConfig). The codebase guideline asks to keep module namespaces instead (e.g., import transformers and use transformers.AutoConfig).

As per coding guidelines: Always maintain the namespace when importing Python modules, even if only one class or function from a module is used.

tensorrt_llm/bench/benchmark/__init__.py (1)

71-75: Remove the unused noqa (RUF100).
Ruff flags the # noqa: F401 as unused because F401 isn’t enabled. Either drop it or enable F401 if you want to enforce unused‑import checks.

🧹 Suggested cleanup
-            import tensorrt_llm._torch.auto_deploy.models.custom  # noqa: F401
+            import tensorrt_llm._torch.auto_deploy.models.custom
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/__init__.py (1)

15-21: Consider sorting __all__ alphabetically.

Ruff (RUF022) suggests applying isort-style sorting to __all__. This is a minor style improvement.

Suggested fix
 __all__ = [
+    "FlashInferMLAAttention",
     "MultiHeadLatentAttention",
-    "FlashInferMLAAttention",
-    "torch_mla",
-    "torch_backend_mla_with_cache",
     "flashinfer_mla_with_cache",
+    "torch_backend_mla_with_cache",
+    "torch_mla",
 ]
examples/auto_deploy/model_registry/configs/glm-4.7-flash.yaml (1)

11-12: Remove duplicate commented attn_page_size entry.

There are two commented attn_page_size lines with different values (512 and 64). This appears to be leftover from experimentation. Consider removing one to avoid confusion.

Suggested fix
   # max_seq_len: 512
-  # attn_page_size: 512
   # attn_page_size: 64
   # attn_backend: flashinfer
examples/auto_deploy/cookbooks/glm_4.7_flash_trtllm_cookbook.ipynb (1)

151-158: Prefer --config over --extra_llm_api_options.

Per coding guidelines, prefer using --config over --extra_llm_api_options when documenting CLI commands for TensorRT-LLM tools.

Suggested fix
 "trtllm-serve \"zai-org/GLM-4.7-Flash\" \\\n",
 "  --host 0.0.0.0 \\\n",
 "  --port 8000 \\\n",
 "  --backend _autodeploy \\\n",
 "  --trust_remote_code \\\n",
-"  --extra_llm_api_options glm4.7_flash.yaml\n",
+"  --config glm4.7_flash.yaml\n",
tests/unittest/_torch/auto_deploy/unit/singlegpu/custom_ops/test_flashinfer_mla_op.py (1)

192-192: Add explicit strict= parameter to zip().

Per Ruff B905, using zip() without an explicit strict= parameter can mask length mismatches. Since input_positions and seq_lengths should have the same length, use strict=True.

Suggested fix
-    kv_lengths = [pos + seq_len for pos, seq_len in zip(input_positions, seq_lengths)]
+    kv_lengths = [pos + seq_len for pos, seq_len in zip(input_positions, seq_lengths, strict=True)]

Comment on lines 18 to 20
"insert_cached_attention": {"backend": "flashinfer"}, # or "triton"
"insert_cached_mla_attention": {"backend": "MultiHeadLatentAttention"},
"insert_cached_mla_attention": {"backend": "torch_mla"},
"compile_model": {"backend": "torch-compile"},

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.

⚠️ Potential issue | 🟡 Minor

Clarify backend choice in the example.
The default config now sets flashinfer_mla, while this example uses torch_mla. Consider noting both options (or aligning to the default) to reduce confusion for users following the workflow.

🤖 Prompt for AI Agents
In `@docs/source/torch/auto_deploy/advanced/workflow.md` around lines 18 - 20, The
example config uses "insert_cached_mla_attention": {"backend": "torch_mla"}
while the current default is "flashinfer_mla"; update the example or add a
clarifying note: either change "torch_mla" to "flashinfer_mla" for consistency,
or add a comment next to insert_cached_mla_attention (and optionally
insert_cached_attention) explaining both supported backends ("torch_mla" vs
"flashinfer_mla") and when to pick each one, and ensure compile_model/backends
still align with the chosen MLA backend.

Comment on lines +1 to +13
"""MLA (Multi-head Latent Attention) custom ops.

Exports:
- MultiHeadLatentAttention: Attention descriptor for MLA (registered as "torch_mla")
- FlashInferMLAAttention: Attention descriptor for FlashInfer MLA (registered as "flashinfer_mla")
- torch_mla: Source op for MLA attention
- torch_backend_mla_with_cache: Cached backend op with FlashInfer-compatible cache
- flashinfer_mla_with_cache: Cached backend op using FlashInfer MLA kernels
"""

from .flashinfer_mla import FlashInferMLAAttention, flashinfer_mla_with_cache
from .torch_backend_mla import MultiHeadLatentAttention, torch_backend_mla_with_cache
from .torch_mla import torch_mla

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.

⚠️ Potential issue | 🟡 Minor

Missing NVIDIA copyright header.

This source file is missing the required NVIDIA copyright header.

Suggested fix
+# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 """MLA (Multi-head Latent Attention) custom ops.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""MLA (Multi-head Latent Attention) custom ops.
Exports:
- MultiHeadLatentAttention: Attention descriptor for MLA (registered as "torch_mla")
- FlashInferMLAAttention: Attention descriptor for FlashInfer MLA (registered as "flashinfer_mla")
- torch_mla: Source op for MLA attention
- torch_backend_mla_with_cache: Cached backend op with FlashInfer-compatible cache
- flashinfer_mla_with_cache: Cached backend op using FlashInfer MLA kernels
"""
from .flashinfer_mla import FlashInferMLAAttention, flashinfer_mla_with_cache
from .torch_backend_mla import MultiHeadLatentAttention, torch_backend_mla_with_cache
from .torch_mla import torch_mla
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""MLA (Multi-head Latent Attention) custom ops.
Exports:
- MultiHeadLatentAttention: Attention descriptor for MLA (registered as "torch_mla")
- FlashInferMLAAttention: Attention descriptor for FlashInfer MLA (registered as "flashinfer_mla")
- torch_mla: Source op for MLA attention
- torch_backend_mla_with_cache: Cached backend op with FlashInfer-compatible cache
- flashinfer_mla_with_cache: Cached backend op using FlashInfer MLA kernels
"""
from .flashinfer_mla import FlashInferMLAAttention, flashinfer_mla_with_cache
from .torch_backend_mla import MultiHeadLatentAttention, torch_backend_mla_with_cache
from .torch_mla import torch_mla
🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/__init__.py` around lines 1 -
13, Add the missing NVIDIA copyright header to the top of the module (above the
module docstring) following the project's standard header format (include
organization name, year range, and any SPDX identifier if used). Update
tensorrt_llm._torch.auto_deploy.custom_ops.mla.__init__ (the file that exports
MultiHeadLatentAttention, FlashInferMLAAttention, torch_mla,
torch_backend_mla_with_cache, flashinfer_mla_with_cache) by inserting the
canonical NVIDIA header block as the very first lines of the file so the
existing docstring and imports remain unchanged.

@@ -0,0 +1,954 @@
"""FlashInfer-based MLA (Multi-head Latent Attention) backend with paged caching.

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.

⚠️ Potential issue | 🟠 Major

Add the required NVIDIA copyright header.

🔧 Proposed fix
+# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
+
 """FlashInfer-based MLA (Multi-head Latent Attention) backend with paged caching.

As per coding guidelines, all TensorRT-LLM source files should contain an NVIDIA copyright header with the year of latest meaningful modification.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""FlashInfer-based MLA (Multi-head Latent Attention) backend with paged caching.
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
"""FlashInfer-based MLA (Multi-head Latent Attention) backend with paged caching.
🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/flashinfer_mla.py` at line 1,
Add the required NVIDIA copyright header to the top of flashinfer_mla.py: insert
the standard NVIDIA file header comment (including "Copyright (c) <year>, NVIDIA
CORPORATION. All rights reserved." with the year being the latest meaningful
modification) before the module docstring in
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/flashinfer_mla.py so the
file-level header precedes the existing triple-quoted module docstring and
complies with project coding guidelines.

@@ -0,0 +1,518 @@
"""Custom ops for MultiHead Latent Attention (MLA) with FlashInfer-compatible cache.

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.

⚠️ Potential issue | 🟠 Major

Add the required NVIDIA copyright header.

🔧 Proposed fix
+# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
+
 """Custom ops for MultiHead Latent Attention (MLA) with FlashInfer-compatible cache.

As per coding guidelines, all TensorRT-LLM source files should contain an NVIDIA copyright header with the year of latest meaningful modification.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"""Custom ops for MultiHead Latent Attention (MLA) with FlashInfer-compatible cache.
# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
"""Custom ops for MultiHead Latent Attention (MLA) with FlashInfer-compatible cache.
🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py` at line
1, The file lacks the required NVIDIA copyright header; add the standard NVIDIA
copyright comment block (including the year of latest meaningful modification)
at the very top of
tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_backend_mla.py before the
existing module docstring ("""Custom ops for MultiHead Latent Attention (MLA)
with FlashInfer-compatible cache."""), ensuring the header follows the project's
canonical format and includes the correct year.

@@ -0,0 +1,157 @@
"""Torch reference implementation for Multi-head Latent Attention (MLA).

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.

⚠️ Potential issue | 🟠 Major

Add the required NVIDIA copyright header.

🔧 Proposed fix
+# Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved.
+
 """Torch reference implementation for Multi-head Latent Attention (MLA).

As per coding guidelines, all TensorRT-LLM source files should contain an NVIDIA copyright header with the year of latest meaningful modification.

🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/custom_ops/mla/torch_mla.py` at line 1, The
file torch_mla.py is missing the required NVIDIA copyright header; prepend the
standard NVIDIA copyright header block (including "Copyright (c) <year>, NVIDIA
CORPORATION. All rights reserved." with the year set to the latest meaningful
modification) at the top of torch_mla.py before the module docstring ("""Torch
reference implementation for Multi-head Latent Attention (MLA).""") so the file
complies with the TensorRT-LLM source file guidelines.

Comment on lines +346 to +352
# Allocate contiguous paged caches (after KVCacheManager so we know page count)
if self._contiguous_paged_cache_order:
num_pages = self._kv_cache_manager.blocks_in_primary_pool
page_size = self._kv_cache_manager.tokens_per_block
for name, handler in self._contiguous_paged_cache_order.items():
self._caches[name] = handler.allocate(self.info, num_pages, page_size)

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.

⚠️ Potential issue | 🟠 Major

Reallocate contiguous paged caches after KVCacheManager resize.
resize_kv_cache_manager() recreates the KVCacheManager and refreshes paged/state views, but contiguous paged caches remain at the old shape. That can cause shape mismatches and invalid accesses after resize.

🛠️ Suggested fix
 def resize_kv_cache_manager(self, mem_exclude: int = 0) -> None:
     ...
     max_tokens_final = self._create_kv_cache_manager(max_tokens=max_tokens_optimal)
+
+    # Re-allocate contiguous paged caches to match the new manager size
+    if self._contiguous_paged_cache_order:
+        num_pages = self._kv_cache_manager.blocks_in_primary_pool
+        page_size = self._kv_cache_manager.tokens_per_block
+        for name, handler in self._contiguous_paged_cache_order.items():
+            self._caches[name] = handler.allocate(self.info, num_pages, page_size)
 def _clear_cache_views(self) -> None:
     """Set paged and state cache views to None before pool release."""
     self._kv_cache_config_tuned = None
     for name in self._paged_cache_order:
         self._caches[name] = None
     for name in self._state_resource_order:
         self._caches[name] = None
+    for name in self._contiguous_paged_cache_order:
+        self._caches[name] = None
🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/shim/interface.py` around lines 346 - 352,
Contiguous paged caches in _contiguous_paged_cache_order are left at the old
shape after resize_kv_cache_manager() recreates _kv_cache_manager, causing shape
mismatches; update the code so that after _kv_cache_manager is resized/recreated
you recompute num_pages = self._kv_cache_manager.blocks_in_primary_pool and
page_size = self._kv_cache_manager.tokens_per_block and then reallocate each
contiguous cache by calling handler.allocate(self.info, num_pages, page_size)
and storing the result back into self._caches[name] (optionally releasing or
overwriting the old cache first) to ensure caches match the new KVCacheManager
shape.

Comment on lines +73 to +77
# if t_name == "compile_model": # or whichever transform is last before generation
# from tensorrt_llm._torch.auto_deploy.utils.graph_debug_compare import run_comparison
# run_comparison(mod, cm, self.factory, output_dir="debug_scatter_plots")
# breakpoint() # Optional: pause to inspect results

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.

⚠️ Potential issue | 🟡 Minor

Remove commented-out debug code before merging.

This block contains debugging artifacts (commented-out code with breakpoint()) that should not be committed to the main branch. Additionally, the pipeline failure indicates this section has formatting issues that need to be resolved.

If this debugging capability is valuable, consider:

  1. Making it conditionally enabled via an environment variable (similar to AD_DUMP_GRAPHS_DIR pattern used elsewhere in this PR)
  2. Or removing it entirely and re-adding when needed
🗑️ Proposed fix: Remove the commented-out code
             mod = transform(mod, cm, self.factory, self.shared_config)

-            # if t_name == "compile_model":  # or whichever transform is last before generation
-            #     from tensorrt_llm._torch.auto_deploy.utils.graph_debug_compare import run_comparison
-            #     run_comparison(mod, cm, self.factory, output_dir="debug_scatter_plots")
-            #     breakpoint()  # Optional: pause to inspect results
-
         ############################################################################################
🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/transform/optimizer.py` around lines 73 - 77,
Remove the commented-out debug block (the lines referencing t_name ==
"compile_model", run_comparison, and breakpoint) from
tensorrt_llm/_torch/auto_deploy/transform/optimizer.py to eliminate debugging
artifacts and fix the formatting error; if you want to preserve the debug
capability instead of deleting it, wrap the logic in a conditional gated by an
environment variable (similar to AD_DUMP_GRAPHS_DIR), e.g., check os.environ and
only call run_comparison(mod, cm, self.factory, output_dir=...) when enabled,
ensuring no leftover commented code or stray breakpoint() calls remain.

Comment on lines +1 to +11
import json
import os
import shutil
from pathlib import Path
from typing import Any, Dict, Optional

import dill
import torch
import torch.nn as nn
from safetensors.torch import save_file as safetensors_save

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if dill and safetensors are declared as dependencies
echo "=== Checking for dill dependency ==="
rg "dill" --glob "setup.py" --glob "pyproject.toml" --glob "requirements*.txt" -A 2 -B 2

echo ""
echo "=== Checking for safetensors dependency ==="
rg "safetensors" --glob "setup.py" --glob "pyproject.toml" --glob "requirements*.txt" -A 2 -B 2

echo ""
echo "=== Listing all dependency configuration files ==="
find . -maxdepth 2 -type f \( -name "setup.py" -o -name "setup.cfg" -o -name "pyproject.toml" -o -name "requirements*.txt" \) | head -20

Repository: NVIDIA/TensorRT-LLM

Length of output: 1883


🏁 Script executed:

#!/bin/bash
echo "=== Content of ./pyproject.toml ==="
cat ./pyproject.toml | head -100

echo ""
echo "=== Content of ./requirements.txt ==="
cat ./requirements.txt

echo ""
echo "=== Content of ./setup.py (first 150 lines) ==="
head -150 ./setup.py

Repository: NVIDIA/TensorRT-LLM

Length of output: 12659


Add dill and safetensors to project dependencies.

The code imports dill (line 7) and safetensors (line 10), but neither package is declared in requirements.txt, setup.py, or pyproject.toml. These external dependencies must be added to the main project dependencies so they are automatically installed with the package, otherwise users will encounter import errors at runtime.

🤖 Prompt for AI Agents
In `@tensorrt_llm/_torch/auto_deploy/utils/logger.py` around lines 1 - 11, The
project imports dill and safetensors in
tensorrt_llm._torch.auto_deploy.utils.logger (the symbols dill and
safetensors.torch.save_file / safetensors_save), but these packages aren't
declared as install-time dependencies; update the project's dependency metadata
(e.g., requirements.txt, setup.py install_requires, or pyproject.toml
[project.dependencies]) to include dill and safetensors (use the appropriate
package names on PyPI) and pin or specify compatible version ranges, then run
dependency install to validate imports succeed.

Comment on lines +359 to +392
class TestGLM4Flash(LlmapiAccuracyTestHarness):
"""Accuracy regression tests for GLM-4.7-Flash."""

MODEL_NAME = "zai-org/GLM-4.7-Flash"
MODEL_PATH = MODEL_NAME # Model is in HF_CACHE
# Set minimum possible seq len + small buffer, for test speed & memory usage
MAX_SEQ_LEN = max(MMLU.MAX_INPUT_LEN + MMLU.MAX_OUTPUT_LEN,
GSM8K.MAX_INPUT_LEN + GSM8K.MAX_OUTPUT_LEN)
MAX_NUM_TOKENS = MAX_SEQ_LEN

def get_default_kwargs(self, enable_chunked_prefill=False):
config = {
"skip_tokenizer_init": False,
"trust_remote_code": True,
"compile_backend": "torch-cudagraph",
"max_batch_size": 128,
"max_seq_len": self.MAX_SEQ_LEN,
"max_num_tokens": self.MAX_NUM_TOKENS,
"skip_loading_weights": False,
"disable_overlap_scheduler": False,
"cuda_graph_batch_sizes": [1, 2, 4, 8, 16, 32, 64, 128],
"kv_cache_config": {
"enable_block_reuse": False,
"free_gpu_memory_fraction": 0.88
},
"model_kwargs": {
"torch_dtype": "bfloat16"
},
}
if enable_chunked_prefill:
config["enable_chunked_prefill"] = True
config[
"max_num_tokens"] = 512 # NOTE: must be > max(tokens_per_block, max_batch_size)
return config

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.

⚠️ Potential issue | 🟡 Minor

Inconsistent disable_overlap_scheduler setting.

The test sets disable_overlap_scheduler: False (line 378), but the YAML config at examples/auto_deploy/model_registry/configs/glm-4.7-flash.yaml sets it to true. Consider aligning these values for consistency, or document if the difference is intentional for testing purposes.

🤖 Prompt for AI Agents
In `@tests/integration/defs/accuracy/test_llm_api_autodeploy.py` around lines 359
- 392, The disable_overlap_scheduler flag in TestGLM4Flash.get_default_kwargs is
set to False but differs from the model registry's configuration; update
get_default_kwargs to match the registry flag (set "disable_overlap_scheduler":
True) to keep behavior consistent, or explicitly document the intentional
mismatch by adding a clear comment in the TestGLM4Flash class and in
get_default_kwargs noting why tests require False while the deployed model uses
True; refer to the TestGLM4Flash class and get_default_kwargs to locate the
change and to the "disable_overlap_scheduler" key to update or document.

Comment on lines +485 to +523
# Debug: print state dict keys and shapes
print("\n=== HF MoE state_dict keys and shapes ===")
for k, v in hf_state_dict.items():
print(f" {k}: {v.shape}")

custom_state_dict = _convert_hf_moe_state_dict_to_custom(hf_state_dict, config.n_routed_experts)

print("\n=== Converted custom state_dict keys and shapes ===")
for k, v in custom_state_dict.items():
print(f" {k}: {v.shape}")

print("\n=== Expected custom MoE state_dict keys ===")
for k, v in custom_moe.state_dict().items():
print(f" {k}: {v.shape}")

custom_moe.load_state_dict(custom_state_dict)
custom_moe.eval()

# Sanity check: verify expert weights match after conversion
# HF has stacked weights: experts.gate_up_proj [n_experts, 2*intermediate, hidden]
# Our model has per-expert: experts.{i}.gate_proj.weight, experts.{i}.up_proj.weight
hf_gate_up = hf_moe.experts.gate_up_proj # [n_experts, 2*intermediate, hidden]
hf_down = hf_moe.experts.down_proj # [n_experts, hidden, intermediate]
intermediate_size = config.moe_intermediate_size

print(f"\n=== Debug: intermediate_size = {intermediate_size} ===")
print(f"hf_gate_up shape: {hf_gate_up.shape}")
print(f"hf_gate_up[0, :2, :2]: {hf_gate_up[0, :2, :2]}")

# Get the converted state dict values for comparison
converted_gate_0 = custom_state_dict["experts.0.gate_proj.weight"]
print(f"converted_gate_0 shape: {converted_gate_0.shape}")
print(f"converted_gate_0[:2, :2]: {converted_gate_0[:2, :2]}")

# After load_state_dict
loaded_gate_0 = custom_moe.experts[0].gate_proj.weight
print(f"loaded_gate_0 shape: {loaded_gate_0.shape}")
print(f"loaded_gate_0[:2, :2]: {loaded_gate_0[:2, :2]}")

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.

⚠️ Potential issue | 🟡 Minor

Remove debug print statements from the numerical equivalence test.

These prints will spam CI logs and slow test runs. Prefer removing them or gating behind an explicit debug flag.

🧹 Proposed cleanup
-    # Debug: print state dict keys and shapes
-    print("\n=== HF MoE state_dict keys and shapes ===")
-    for k, v in hf_state_dict.items():
-        print(f"  {k}: {v.shape}")
-
     custom_state_dict = _convert_hf_moe_state_dict_to_custom(hf_state_dict, config.n_routed_experts)
-
-    print("\n=== Converted custom state_dict keys and shapes ===")
-    for k, v in custom_state_dict.items():
-        print(f"  {k}: {v.shape}")
-
-    print("\n=== Expected custom MoE state_dict keys ===")
-    for k, v in custom_moe.state_dict().items():
-        print(f"  {k}: {v.shape}")
-
     custom_moe.load_state_dict(custom_state_dict)
     custom_moe.eval()
@@
-    print(f"\n=== Debug: intermediate_size = {intermediate_size} ===")
-    print(f"hf_gate_up shape: {hf_gate_up.shape}")
-    print(f"hf_gate_up[0, :2, :2]: {hf_gate_up[0, :2, :2]}")
-
     # Get the converted state dict values for comparison
     converted_gate_0 = custom_state_dict["experts.0.gate_proj.weight"]
-    print(f"converted_gate_0 shape: {converted_gate_0.shape}")
-    print(f"converted_gate_0[:2, :2]: {converted_gate_0[:2, :2]}")
-
     # After load_state_dict
     loaded_gate_0 = custom_moe.experts[0].gate_proj.weight
-    print(f"loaded_gate_0 shape: {loaded_gate_0.shape}")
-    print(f"loaded_gate_0[:2, :2]: {loaded_gate_0[:2, :2]}")
🤖 Prompt for AI Agents
In
`@tests/unittest/_torch/auto_deploy/unit/singlegpu/models/test_glm4_moe_lite_modeling.py`
around lines 485 - 523, Remove the debug print statements in the numerical
equivalence test: delete or gate all prints that reference hf_state_dict,
custom_state_dict, custom_moe, hf_gate_up, converted_gate_0, and loaded_gate_0
(the blocks printing shapes, slices, and the "=== ..." headers). Keep the actual
assertions and the call to _convert_hf_moe_state_dict_to_custom and
custom_moe.load_state_dict as-is; if logging is desired for debugging, wrap the
prints behind an explicit debug flag (e.g., a module-level DEBUG or an env var)
so CI runs remain quiet.

Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
bmarimuthu-nv and others added 6 commits February 5, 2026 01:05
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com>
Signed-off-by: Balamurugan Marimuthu <246387390+bmarimuthu-nv@users.noreply.github.com>
@lucaslie

lucaslie commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

see #11324

@lucaslie lucaslie closed this Feb 5, 2026
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.

3 participants