Skip to content

[None][doc] document dtype='auto' resolution for model and KV cache#16240

Open
lonexreb wants to merge 2 commits into
NVIDIA:mainfrom
lonexreb:doc/dtype-auto-resolution
Open

[None][doc] document dtype='auto' resolution for model and KV cache#16240
lonexreb wants to merge 2 commits into
NVIDIA:mainfrom
lonexreb:doc/dtype-auto-resolution

Conversation

@lonexreb

@lonexreb lonexreb commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #15512.

The dtype and KvCacheConfig.dtype docstrings said "auto" without explaining what it resolves to, forcing users to read llm_args.py / model_config.py to predict the effective dtype.

Change

Expand both Field descriptions (docstring-only, no behavior change):

  • model dtype: 'auto' infers from the checkpoint — HF config torch_dtype (or deprecated dtype), falling back to bfloat16 when unspecified (model_config.py torch_dtype property); any other value forces a valid torch dtype.
  • KvCacheConfig.dtype: 'auto' follows the checkpoint's own quant metadata, leaving quant_config.kv_cache_quant_algo untouched; 'fp8'/'nvfp4' override it (verified in sync_quant_config_with_kv_cache_config_dtype).

Note

Deliberately omitted the reporter's mentioned pre-Ampere float16 override — it is not present in the current PyTorch model_config.py path and the reporter also could not verify it, so documenting it would be inaccurate.

Test

Docstring-only; no code path changes. tests/unittest/api_stability snapshots only annotation/default (not descriptions), so it is unaffected.

Summary by CodeRabbit

  • Documentation
    • Clarified how KV cache data types can override model settings, including configuration through trtllm-serve.
    • Documented automatic data type detection from Hugging Face checkpoints and the default to bfloat16.
    • Clarified requirements for explicitly specifying valid PyTorch data types.

Expand the Field descriptions for the model dtype and KvCacheConfig.dtype
so users can predict the resolved value without reading the source:
- model dtype 'auto' infers from the checkpoint (HF torch_dtype/dtype),
  falling back to bfloat16; any other value forces a torch dtype.
- KvCacheConfig.dtype 'auto' follows the checkpoint's quant metadata
  (leaves quant_config.kv_cache_quant_algo untouched); 'fp8'/'nvfp4'
  override it.

Fixes NVIDIA#15512

Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
@lonexreb
lonexreb requested a review from a team as a code owner July 10, 2026 16:10
@lonexreb
lonexreb requested a review from syuoni July 10, 2026 16:10
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updates KvCacheConfig.dtype and BaseLlmArgs.dtype documentation to describe automatic resolution, checkpoint metadata fallbacks, explicit dtype overrides, and LLM construction-time application.

Changes

dtype documentation

Layer / File(s) Summary
Document dtype resolution contracts
tensorrt_llm/llmapi/llm_args.py
KvCacheConfig.dtype now documents checkpoint quantization metadata and fp8/nvfp4 overrides; BaseLlmArgs.dtype documents Hugging Face dtype fallback behavior and forced PyTorch dtype strings.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Possibly related PRs

Suggested reviewers: achartier, moraxu, Superjomn

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR covers most of #15512, but it omits the nested text_config fallback and pre-Ampere float16 override required by the issue. Add the missing model dtype resolution details, including nested text_config fallback and the pre-Ampere float16 override, or explain why they are excluded.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the doc-only dtype auto-resolution update.
Description check ✅ Passed The description follows the template with Description, Change, Note, and Test sections and explains the doc-only scope.
Out of Scope Changes check ✅ Passed The changes stay within the documentation scope and do not introduce unrelated code or API changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 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 `@tensorrt_llm/llmapi/llm_args.py`:
- Around line 2493-2494: The documentation text near the LLM argument
description references the deprecated `--extra_llm_api_options` option; update
it to use the preferred `--config` option while preserving the surrounding
explanation about configuration files and quantization settings.
- Around line 2490-2492: Update the `kv_cache_dtype` documentation in `LLMArgs`
to clarify that `auto` follows checkpoint quantization metadata and may populate
`quant_config.kv_cache_quant_algo` when it is unset, while preserving any
explicitly configured value; retain that `fp8` and `nvfp4` override the setting.
- Around line 2810-2813: Update the dtype argument documentation near
BaseLlmArgs.validate_dtype() to state that although “auto” falls back to
bfloat16 when unspecified, it is converted to float16 on GPUs with compute
capability below SM80; retain the existing description of explicit torch dtype
values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 0a225d25-b656-4087-862c-3b35d013f40c

📥 Commits

Reviewing files that changed from the base of the PR and between 82159e4 and dc18246.

📒 Files selected for processing (1)
  • tensorrt_llm/llmapi/llm_args.py

Comment on lines +2490 to +2492
"The data type to use for the KV cache. 'auto' (default) follows the checkpoint's own "
"quantization metadata, leaving quant_config.kv_cache_quant_algo untouched. 'fp8' or "
"'nvfp4' override it, setting quant_config.kv_cache_quant_algo to that KV-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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Clarify that auto may populate quant_config.kv_cache_quant_algo.

The construction path sets quant_config.kv_cache_quant_algo from checkpoint metadata when it is unset; auto only avoids overriding an explicitly configured value.

Suggested wording
-        "quantization metadata, leaving quant_config.kv_cache_quant_algo untouched. 'fp8' or "
+        "quantization metadata. If quant_config.kv_cache_quant_algo is unset, it may be "
+        "populated from the checkpoint; 'fp8' or "
📝 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
"The data type to use for the KV cache. 'auto' (default) follows the checkpoint's own "
"quantization metadata, leaving quant_config.kv_cache_quant_algo untouched. 'fp8' or "
"'nvfp4' override it, setting quant_config.kv_cache_quant_algo to that KV-cache "
"The data type to use for the KV cache. 'auto' (default) follows the checkpoint's own "
"quantization metadata. If quant_config.kv_cache_quant_algo is unset, it may be "
"populated from the checkpoint; 'fp8' or "
"'nvfp4' override it, setting quant_config.kv_cache_quant_algo to that KV-cache "
🤖 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 `@tensorrt_llm/llmapi/llm_args.py` around lines 2490 - 2492, Update the
`kv_cache_dtype` documentation in `LLMArgs` to clarify that `auto` follows
checkpoint quantization metadata and may populate
`quant_config.kv_cache_quant_algo` when it is unset, while preserving any
explicitly configured value; retain that `fp8` and `nvfp4` override the setting.

Comment thread tensorrt_llm/llmapi/llm_args.py Outdated
Comment on lines +2493 to +2494
"quantization algorithm. Applied at LLM construction time, including via "
"trtllm-serve --extra_llm_api_options.")

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the preferred --config option in the documentation.

The repository guidelines require --config instead of --extra_llm_api_options when documenting configuration files.

-        "trtllm-serve --extra_llm_api_options.")
+        "trtllm-serve --config.")
📝 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
"quantization algorithm. Applied at LLM construction time, including via "
"trtllm-serve --extra_llm_api_options.")
"quantization algorithm. Applied at LLM construction time, including via "
"trtllm-serve --config.")
🤖 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 `@tensorrt_llm/llmapi/llm_args.py` around lines 2493 - 2494, The documentation
text near the LLM argument description references the deprecated
`--extra_llm_api_options` option; update it to use the preferred `--config`
option while preserving the surrounding explanation about configuration files
and quantization settings.

Source: Coding guidelines

Comment thread tensorrt_llm/llmapi/llm_args.py Outdated
Comment on lines +2810 to +2813
"The data type to use for the model. 'auto' (default) infers the dtype from the "
"checkpoint: the HF config's 'torch_dtype' (or the deprecated 'dtype' field), falling "
"back to 'bfloat16' when the checkpoint specifies none. Any other value must be a valid "
"torch dtype string (e.g. 'float16', 'bfloat16') and forces that dtype."

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 | 🟡 Minor | ⚡ Quick win

Document the pre-SM80 float16 override.

BaseLlmArgs.validate_dtype() converts 'auto' to 'float16' on GPUs with compute capability below 8.0, so the documented fallback to bfloat16 is not universal.

Suggested wording
         "back to 'bfloat16' when the checkpoint specifies none. Any other value must be a valid "
-        "torch dtype string (e.g. 'float16', 'bfloat16') and forces that dtype."
+        "torch dtype string (e.g. 'float16', 'bfloat16') and forces that dtype. On GPUs with "
+        "compute capability below 8.0, 'auto' is overridden to 'float16'."
📝 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
"The data type to use for the model. 'auto' (default) infers the dtype from the "
"checkpoint: the HF config's 'torch_dtype' (or the deprecated 'dtype' field), falling "
"back to 'bfloat16' when the checkpoint specifies none. Any other value must be a valid "
"torch dtype string (e.g. 'float16', 'bfloat16') and forces that dtype."
"The data type to use for the model. 'auto' (default) infers the dtype from the "
"checkpoint: the HF config's 'torch_dtype' (or the deprecated 'dtype' field), falling "
"back to 'bfloat16' when the checkpoint specifies none. Any other value must be a valid "
"torch dtype string (e.g. 'float16', 'bfloat16') and forces that dtype. On GPUs with "
"compute capability below 8.0, 'auto' is overridden to 'float16'."
🤖 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 `@tensorrt_llm/llmapi/llm_args.py` around lines 2810 - 2813, Update the dtype
argument documentation near BaseLlmArgs.validate_dtype() to state that although
“auto” falls back to bfloat16 when unspecified, it is converted to float16 on
GPUs with compute capability below SM80; retain the existing description of
explicit torch dtype values.

…config

- Document that 'auto' model dtype resolves to float16 on pre-Ampere
  (compute capability < 8.0) GPUs (BaseLlmArgs.validate_dtype).
- Clarify KV cache 'auto' may populate quant_config.kv_cache_quant_algo
  from the checkpoint when unset (preserving an explicit value).
- Use the preferred 'trtllm-serve --config' over --extra_llm_api_options.

Signed-off-by: lonexreb <reach2shubhankar@gmail.com>
@lonexreb

Copy link
Copy Markdown
Contributor Author

Addressed in 6901f55: documented the pre-SM80 float16 override (validate_dtype), clarified that KV auto may populate kv_cache_quant_algo from the checkpoint when unset, and switched to the preferred trtllm-serve --config.

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.

[Doc]: dtype="auto" resolution chain undocumented for LLM and KvCacheConfig

1 participant