Skip to content

concept olmo block - #4927

Open
grimoire wants to merge 20 commits into
InternLM:mainfrom
grimoire:codex/concept-olmo-block
Open

grimoire wants to merge 20 commits into
InternLM:mainfrom
grimoire:codex/concept-olmo-block

Conversation

@grimoire

@grimoire grimoire commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@grimoire
grimoire force-pushed the codex/concept-olmo-block branch from 9ad5553 to 7a9a64d Compare September 3, 2026 07:40
@grimoire
grimoire marked this pull request as ready for review September 4, 2026 03:20
Copilot AI lite review requested due to automatic review settings September 4, 2026 03:20

Copilot AI 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.

🟡 Changes recommended

It unconditionally enables trust_remote_code=True when loading a tokenizer during config building, which is a security-sensitive behavior that should be explicitly user-controlled.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds initial runtime + model implementation support for ConceptLM v2.2 VQ (“intern_ncp”), including model configuration backfilling from exported training config, backend runtime ops (Torch + Triton), and CUDA kernels to support chunk-based concept prediction during prefill/decode.

Changes:

  • Introduces ConceptLMV22VQForCausalLM model implementation (modules/metadata/weight loading) and wires it into MODULE_MAP.
  • Adds ConceptLM runtime ops contract + default/cuda backend implementations and Triton kernels for chunk merge + cache updates.
  • Adds a ConceptLM config builder that can backfill sparse HF exports from training_config.yaml, plus tests for backfill and YaRN rotary normalization.
File summaries
File Description
tests/pytorch/config/test_model_config.py Adds unit tests for ConceptLM training-config backfill and YaRN rotary normalization behavior.
lmdeploy/pytorch/nn/conceptlm.py Adds ConceptLMRuntimeOps nn.Module wrapper to dispatch runtime ops via backend.
lmdeploy/pytorch/nn/init.py Exports ConceptLMRuntimeOps from the nn package.
lmdeploy/pytorch/models/module_map.py Registers ConceptLMV22VQForCausalLM for dynamic model loading.
lmdeploy/pytorch/models/intern_ncp/init.py Declares the intern_ncp model package export.
lmdeploy/pytorch/models/intern_ncp/weight.py Adds weight utilities (OLMo QKV repack, stacked codebook slice loading).
lmdeploy/pytorch/models/intern_ncp/modules.py Implements ConceptLM/OLMo blocks, routing, quantizer, and weight-loading logic.
lmdeploy/pytorch/models/intern_ncp/modeling.py Adds top-level ConceptLMV22VQForCausalLM forward path, cache plumbing, and weight loading.
lmdeploy/pytorch/models/intern_ncp/metadata.py Adds ConceptLM metadata + cache view helpers (KV split, named state cache access).
lmdeploy/pytorch/configurations/conceptlm.py Adds ConceptLM model-config builder with training-config backfill and rotary normalization.
lmdeploy/pytorch/backends/base.py Adds new OpType.ConceptLMRuntimeOps.
lmdeploy/pytorch/backends/conceptlm.py Adds backend contract types for ConceptLM runtime ops and metadata structs.
lmdeploy/pytorch/backends/default/op_backend.py Registers default backend builder for ConceptLMRuntimeOps.
lmdeploy/pytorch/backends/default/conceptlm.py Implements Torch fallback ConceptLM runtime ops (prefill compaction, decode update, KV snapshot/restore).
lmdeploy/pytorch/kernels/cuda/conceptlm.py Adds Triton kernels for ConceptLM chunk merge and cache updates.
lmdeploy/pytorch/backends/cuda/op_backend.py Registers CUDA backend builder for ConceptLMRuntimeOps.
lmdeploy/pytorch/backends/cuda/conceptlm.py Connects CUDA backend ops to Triton kernels with fallbacks.
lmdeploy/pytorch/backends/cuda/attention/fa3.py Uses attn_metadata.max_q_seqlen when provided.
autotest/interface/restful/tool_parser/test_tool_call_anthropic_sdk.py Minor docstring wording tweak.
Review details
  • Files reviewed: 19/19 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +287 to +295
def _fill_special_tokens(hf_config, model_path: str = None):
try:
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
hf_config.bos_token_id = tok.bos_token_id
hf_config.eos_token_id = tok.eos_token_id
if getattr(hf_config, 'pad_token_id', None) is None:
hf_config.pad_token_id = tok.pad_token_id
except Exception as e: # noqa: BLE001
Comment on lines +679 to +681
qkv_states = self.qkv_proj(hidden_states)
qkv_states = qkv_states.flatten(0, -2) # (-1, heads_total, head_dim)
query_states, key_states, value_states = self.qkv_proj.split_qkv(qkv_states)
@lvhan028 lvhan028 added the enhancement New feature or request label Sep 7, 2026
…block

# Conflicts:
#	lmdeploy/pytorch/backends/cuda/op_backend.py
#	lmdeploy/pytorch/backends/default/op_backend.py
…block

# Conflicts:
#	autotest/interface/restful/tool_parser/test_tool_call_anthropic_sdk.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants