Skip to content

feat: add Kimi-K3 model definition and quantization example - #2994

Open
kylesayrs wants to merge 4 commits into
mainfrom
kimi-k3-example
Open

feat: add Kimi-K3 model definition and quantization example#2994
kylesayrs wants to merge 4 commits into
mainfrom
kimi-k3-example

Conversation

@kylesayrs

Copy link
Copy Markdown
Collaborator

Summary

  • Adds vendored Kimi-K3 model implementation (KimiK3ForConditionalGeneration) with configuration, vision processing, tokenization, and encoding support
  • Adds quantization example that loads a quantization config from pretrained, adds ignore patterns for residual projections and routed experts, and passes the modified config as a quantization_config loading argument
  • Adds _apply_attn_res to default tracing ignore list for Kimi-K3 compatibility with the sequential pipeline

Test plan

  • Verify example script runs with a small Kimi-K3 model (e.g., inference-optimization/Kimi-K3-0.18B)
  • Verify tracing succeeds with _apply_attn_res in ignore list
  • Verify the vendored model definition loads and generates text correctly

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: ee585514-0910-4ff9-8655-e141fc947e9f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@mergify

mergify Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces support for the Kimi-K3 model, adding its configuration, XTML encoding helpers, multimodal and vision processors, model architectures, and a tokenizer, along with a quantization example. The review feedback identifies a critical bug in modeling_kimi_k3_linear.py where the optimized inference path is hardcoded to False. Additionally, it highlights several improvement opportunities, such as replacing unsafe assert statements used for runtime input, file, and dependency validation with standard if checks that raise appropriate exceptions, and defensively using .get() and type checks to prevent potential KeyError or TypeError crashes.

Comment thread src/llmcompressor/modeling/kimi_k3/modeling_kimi_k3_linear.py Outdated
Comment thread src/llmcompressor/modeling/kimi_k3/modeling_kimi_k3_linear.py Outdated
Comment thread src/llmcompressor/modeling/kimi_k3/modeling_kimi_k3_linear.py Outdated
Comment thread src/llmcompressor/modeling/kimi_k3/modeling_kimi_k3.py
Comment thread src/llmcompressor/modeling/kimi_k3/tokenization_kimi.py
Comment thread src/llmcompressor/modeling/kimi_k3/kimi_k3_processor.py
Comment thread src/llmcompressor/modeling/kimi_k3/configuration_kimi_k3.py
Comment thread src/llmcompressor/modeling/kimi_k3/encoding_k3.py

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

overall lgtm, couple questions. when you have empty checkboxes in your PR summary, does that mean PR is still WIP or that you've added each of those?

Comment thread src/llmcompressor/modeling/kimi_k3/modeling_kimi_linear.py

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.

do you have a record at all of what you had to change to get this to work? In case we need to modify later?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a diff record!

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.

sorry, where is the diff? is it a commit?

@kylesayrs
kylesayrs requested a review from yiliu30 as a code owner August 10, 2026 19:45
@mergify mergify Bot removed the quality-failed label Aug 10, 2026
@mergify

mergify Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

kylesayrs and others added 3 commits August 10, 2026 15:49
Add vendored Kimi-K3 model implementation (KimiK3ForConditionalGeneration)
with configuration, vision processing, tokenization, and encoding support.

Add quantization example that loads a quantization config from pretrained,
adds ignore patterns for residual projections and routed experts, and
passes the config as a loading argument.

Also adds _apply_attn_res to default tracing ignore list for Kimi-K3
compatibility with the sequential pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Kyle Sayers <kylesayrs@gmail.com>
…files

Each kimi_k3 file now has a comment at the top documenting implementation
differences from the original files at moonshotai/Kimi-K3 on Hugging Face.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mergify

mergify Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

…, remove formatting-only comments

- Rename modeling_kimi_k3_linear.py back to modeling_kimi_linear.py to
  match the upstream HuggingFace filename
- Remove the re-export shim that was in modeling_kimi_linear.py
- Remove "Differences: formatting only" comments from files with no
  substantive changes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mergify mergify Bot removed the quality-failed label Aug 10, 2026
@mergify

mergify Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import load_context

MODEL_ID = "moonshotai/Kimi-K3"

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.

@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require one maintainer review 👀 reviews

🔴 Require one maintainer review

Waiting for any of

  • approved-reviews-by=HDCharles
  • approved-reviews-by=brian-dellabetta
  • approved-reviews-by=dsikka
  • approved-reviews-by=kylesayrs
  • approved-reviews-by=yiliu30
This rule is failing.

All PRs must have at least one approving review from a maintainer before merging.

  • any of:
    • approved-reviews-by=HDCharles
    • approved-reviews-by=brian-dellabetta
    • approved-reviews-by=dsikka
    • approved-reviews-by=kylesayrs
    • approved-reviews-by=yiliu30
  • #changes-requested-reviews-by = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants