-
Notifications
You must be signed in to change notification settings - Fork 106
[ATOM][Kimi-K3] ATOM support Kimi-K3 #1712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c84f297
9841bc5
91f71fc
fdcafd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,22 @@ | |
| from dataclasses import dataclass | ||
| from typing import Optional, Tuple | ||
|
|
||
| KIMI_THINK_END = "<|close|>think<|sep|>" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no model specific stuff should be here |
||
| KIMI_RESPONSE_START = "<|open|>response<|sep|>" | ||
| KIMI_RESPONSE_END = "<|close|>response<|sep|>" | ||
| KIMI_MESSAGE_END = "<|close|>message<|sep|>" | ||
| KIMI_END_OF_MSG = "<|end_of_msg|>" | ||
|
|
||
|
|
||
| def _strip_kimi_response_markers(text: str) -> str: | ||
| if text.startswith(KIMI_RESPONSE_START): | ||
| text = text[len(KIMI_RESPONSE_START) :] | ||
|
|
||
| for marker in (KIMI_RESPONSE_END, KIMI_MESSAGE_END, KIMI_END_OF_MSG): | ||
| if marker in text: | ||
| text = text.partition(marker)[0] | ||
| return text.strip() | ||
|
|
||
|
|
||
| def separate_reasoning(text: str) -> Tuple[Optional[str], str]: | ||
| """Separate reasoning content from the final answer. | ||
|
|
@@ -23,6 +39,23 @@ def separate_reasoning(text: str) -> Tuple[Optional[str], str]: | |
| Tuple of (reasoning_content, content). reasoning_content is None if | ||
| no thinking block was found. | ||
| """ | ||
| kimi_response_delim = KIMI_THINK_END + KIMI_RESPONSE_START | ||
| if kimi_response_delim in text: | ||
| reasoning, _, content = text.partition(kimi_response_delim) | ||
| reasoning = reasoning.strip() | ||
| content = _strip_kimi_response_markers(content) | ||
| return (reasoning if reasoning else None, content) | ||
|
|
||
| if KIMI_RESPONSE_START in text: | ||
| _, _, content = text.partition(KIMI_RESPONSE_START) | ||
| return (None, _strip_kimi_response_markers(content)) | ||
|
|
||
| if KIMI_THINK_END in text: | ||
| reasoning, _, content = text.partition(KIMI_THINK_END) | ||
| reasoning = reasoning.strip() | ||
| content = _strip_kimi_response_markers(content) | ||
| return (reasoning if reasoning else None, content) | ||
|
|
||
| # Check for closed thinking block: <think>...</think> | ||
| match = re.match(r"<think>(.*?)</think>\s*(.*)", text, flags=re.DOTALL) | ||
| if match: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,7 @@ | |
| "Qwen3_5ForConditionalGeneration": "atom.models.qwen3_5.Qwen3_5MultimodalModel", | ||
| "Qwen3_5MoeForConditionalGeneration": "atom.models.qwen3_5.Qwen3_5MoeMultimodalModel", | ||
| "KimiK25ForConditionalGeneration": "atom.models.kimi_k25.KimiK25ForCausalLM", | ||
| "KimiK3ForConditionalGeneration": "atom.models.kimi_k3.KimiK3ForCausalLM", | ||
| "MiniMaxM2ForCausalLM": "atom.models.minimax_m2.MiniMaxM2ForCausalLM", | ||
| "MiMoV2ForCausalLM": "atom.models.mimo_v2.MiMoV2ForCausalLM", | ||
| "MiMoV2FlashForCausalLM": "atom.models.mimo_v2.MiMoV2ForCausalLM", | ||
|
|
@@ -771,6 +772,15 @@ def __init__(self, rank: int, config: Config): | |
| f"[{self.rank_name}] Model load done: {config.model} " | ||
| f"(weights loaded in {load_elapsed:.2f}s)" | ||
| ) | ||
| if ( | ||
| os.getenv("ATOM_SYNC_AFTER_LOAD", "0").lower() in ("1", "true", "yes") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this |
||
| and get_tp_group().world_size > 1 | ||
| ): | ||
| logger.info( | ||
| "Waiting for all TP ranks to finish model loading before warmup" | ||
| ) | ||
| get_tp_group().barrier() | ||
| logger.info("All TP ranks finished model loading") | ||
|
|
||
| # Optional debug instrumentation; no-op when env vars unset. | ||
| # See atom/utils/debug_helper/. | ||
|
|
@@ -899,10 +909,14 @@ def is_qwen_next(self) -> bool: | |
| "qwen3_next_mtp", | ||
| "qwen3_5_text", | ||
| "qwen3_5_moe_text", | ||
| "kimi_linear", | ||
| ): | ||
| return True | ||
| return False | ||
|
|
||
| def is_kimi_linear(self) -> bool: | ||
| return getattr(self.hf_text_config, "model_type", None) == "kimi_linear" | ||
|
|
||
| def is_deepseek_v4(self) -> bool: | ||
| # NOTE: `hf_text_config.model_type` reads "deepseek_v3" for V4 because | ||
| # `_CONFIG_REGISTRY` maps deepseek_v4 → deepseek_v3 (V4 reuses V3 schema). | ||
|
|
@@ -1340,6 +1354,16 @@ def warmup_model(self): | |
| if pcp_size > 1: | ||
| warmup_max_tokens = max(1, warmup_max_tokens // pcp_size) | ||
|
|
||
| # TEMPORARY (benign, warmup-only): cap the dummy warmup prefill. A large | ||
| # all-zero warmup batch samples garbage logits over all positions and | ||
| # faults the sampler/softmax on gfx1250; real inference only samples the | ||
| # last token per seq so it is unaffected. Proper fix = skip/greedy sampling | ||
| # during is_dummy_run warmup, then this cap can go. Not needed for the MoE | ||
| # (that large-M crash is fixed in aiter grouped_moe_gfx1250). | ||
| _warmup_cap = int(os.environ.get("ATOM_WARMUP_MAX_TOKENS", "0") or "0") | ||
| if _warmup_cap > 0: | ||
| warmup_max_tokens = min(warmup_max_tokens, _warmup_cap) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this? |
||
|
|
||
| num_seqs = min(warmup_max_tokens // max_model_len, self.config.max_num_seqs) | ||
|
|
||
| if num_seqs == 0: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1455,6 +1455,15 @@ def postprocess( | |
| num_placeholder += 1 | ||
|
|
||
| for seq in self.running: | ||
| # A disconnected client may abort a seq while its current forward is | ||
| # still in flight. Do not try to backfill deferred placeholders for | ||
| # that seq: aborted partial-prefill requests may not have any | ||
| # output_tokens placeholder to overwrite. | ||
| if seq.status == SequenceStatus.ABORTED: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ABORTED should already supported? @yhl-amd any comments? |
||
| seq.leave_reason = "aborted" | ||
| seq.status = SequenceStatus.FINISHED | ||
| finished_seqs.append(seq) | ||
| continue | ||
| # Update the running status | ||
| idx = fwd_output.get_idx(seq.id) | ||
| if idx is None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
text_model_type = text_config_dict.get("model_type", "deepseek_v3") ->text_model_type = text_config_dict.get("model_type", "text_config")