Skip to content

[ATOM SGLang] GLM 5.2 MTP#1694

Draft
ZhiweiYan-96 wants to merge 6 commits into
mainfrom
zhiwei/glm_mtp_clean
Draft

[ATOM SGLang] GLM 5.2 MTP#1694
ZhiweiYan-96 wants to merge 6 commits into
mainfrom
zhiwei/glm_mtp_clean

Conversation

@ZhiweiYan-96

@ZhiweiYan-96 ZhiweiYan-96 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Motivation

Enable GLM 5.2 MTP at sglang plugin

Technical Details

Test Plan

export AITER_QUICK_REDUCE_QUANTIZATION=INT4
export AITER_USE_FLYDSL_MOE_SORTING=1
export SGLANG_USE_AITER=1
export SGLANG_EXTERNAL_MODEL_PACKAGE=atom.plugin.sglang.models
export PYTHONPATH="${ROOT}:/app/sglang"
export CUDA_VISIBLE_DEVICES=4,5,6,7
export TORCHINDUCTOR_COMPILE_THREADS=128

export ATOM_SPEC_DECODE_FAST_LOADER=0
export ATOM_LOADER_NUM_THREADS=1
export ATOM_GLM52_DRAFT_ATTN_MODE=full
export ATOM_SGLANG_DRAFT_ARGMAX=1
export ATOM_REPLICATE_VOCAB_EMBED=1
export ATOM_GLM52_MTP_FUSED_INPUT=1
export ATOM_GLM52_MTP_WRAPPER_MODE=current

python3 -m sglang.launch_server \
  --model-path /workspace/shared/data/amd_int/models/GLM-5.2-MXFP4 \
  --host 0.0.0.0 \
  --port 8016 \
  --trust-remote-code \
  --tp-size 4 \
  --mem-fraction-static 0.8 \
  --disable-radix-cache \
  --max-running-requests 128 \
  --enable-return-hidden-states \
  --kv-cache-dtype fp8_e4m3 \
  --model-loader-extra-config '{"online_quant_config":{"global_quant_config":"ptpc_fp8","exclude_layer":["lm_head","model.embed_tokens","*.mlp.gate","*expert*"]}}' \
  --speculative-algorithm EAGLE \
  --speculative-draft-attention-backend aiter \
  --speculative-num-steps 3 \
  --speculative-eagle-topk 1 \
  --speculative-num-draft-tokens 4 \
  2>&1 | tee log.glm52_mtp_server.log

Test Result

image image

Submission Checklist

Add the plugin-owned GLM-5.2 MTP metadata bridge and fixed-shape CUDA graph support for draft decode, target verify, and draft extend. Keep SGLang request/KV ownership and route the draft model through the general ATOM AITER attention backend.
Keep the PR branch limited to the general ATOM draft attention route by removing hybrid native-attention cache and layer-id compatibility.
Keep the GLM-5.2 PR route fixed on the validated plugin-owned draft-extend implementation and remove the upstream-handler environment switch.
Remove GLM-5.2 phase and capacity environment switches. Let SGLang's native disable_cuda_graph server argument control graph capture, with all speculative graph phases enabled by default and an internal fixed metadata capacity.
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 1694 --add-label <label>

@github-actions github-actions 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.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

work_metadata: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

work_indptr: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

work_info_set: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

reduce_indptr: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

reduce_final_map: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

reduce_partial_map: Optional[torch.Tensor]


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

) -> Optional[SparseMLAGraphBuffers]:


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

input_dtype: Optional[torch.dtype] = None,


⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

q_scale: Optional[torch.Tensor] = None,


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from atom.plugin.sglang.glm52_mtp.cache_bind import bind_glm52_dsa_cache_views
from atom.plugin.sglang.glm52_mtp.common import (
ATTENTION_PAGE_SIZE_ATTR,
DECODE_GRAPH_BUFFERS_ATTR,
DRAFT_SUB_STEP_ATTR,
EMPTY_VALUE_CACHE_ATTR,
INDEXER_PAGE_SIZE_ATTR,
SHARED_SPARSE_INDICES_ATTR,
is_glm52_dsa_arch,
maybe_get_glm52_dsa_pools_from_sglang_backend,
)
from atom.plugin.sglang.glm52_mtp.decode_graph import (
build_atom_glm52_decode_graph_metadata_from_sglang,
)
from atom.plugin.sglang.glm52_mtp.dispatcher import (
build_atom_glm52_attention_metadata_from_sglang,
)
from atom.plugin.sglang.glm52_mtp.draft_decode import (
build_decode_metadata as _build_decode_metadata,
clear_draft_decode_sub_step,
get_draft_decode_sub_step,
set_draft_decode_sub_step,
)
from atom.plugin.sglang.glm52_mtp.draft_extend import (
build_mtp_draft_extend_decode_metadata as _build_mtp_draft_extend_decode_metadata,
draft_extend_token_num,
draft_extend_token_num as _draft_extend_token_num,
should_use_mtp_draft_extend_decode_path as _should_use_mtp_draft_extend_decode_path,
)
from atom.plugin.sglang.glm52_mtp.target_verify import (
build_mtp_verify_decode_metadata as _build_mtp_verify_decode_metadata,
should_use_mtp_verify_prefill_path as _should_use_mtp_verify_prefill_path,
)


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from atom.plugin.sglang.glm52_mtp.cache_bind import bind_glm52_dsa_cache_views
from atom.plugin.sglang.glm52_mtp.common import (
maybe_get_glm52_dsa_pools_from_sglang_backend,
)
from atom.plugin.sglang.glm52_mtp.dispatcher import (
build_atom_glm52_attention_metadata_from_sglang,
)
from atom.plugin.sglang.glm52_mtp.decode_graph import (
build_atom_glm52_decode_graph_metadata_from_sglang,
)
from atom.plugin.sglang.glm52_mtp.draft_decode import (
clear_draft_decode_sub_step,
get_draft_decode_sub_step,
set_draft_decode_sub_step,
)
from atom.plugin.sglang.glm52_mtp.draft_extend import draft_extend_token_num


⚠️ [ruff] <B009> reported by reviewdog 🐶
Do not call getattr with a constant attribute value. It is not any safer than normal property access.

index_entry_dim = int(getattr(indexer, "head_dim")) + 4


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from atom.plugin.sglang.glm52_mtp.draft_decode import is_draft_decode_metadata


⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception


⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception


⚠️ [ruff] <PLR1730> reported by reviewdog 🐶
Replace if statement with min call

if extend_end > int(req_to_token_row.numel()):
extend_end = int(req_to_token_row.numel())


⚠️ [ruff] <B009> reported by reviewdog 🐶
Do not call getattr with a constant attribute value. It is not any safer than normal property access.

num_heads = int(getattr(hf_config, "num_attention_heads"))


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import torch
from aiter import get_mla_metadata_v1
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton
from atom.plugin.sglang.glm52_mtp.common import (
DECODE_GRAPH_BUFFERS_ATTR,
SHARED_SPARSE_INDICES_ATTR,
get_index_topk,
local_num_attention_heads,
make_mla_work_buffers,
metadata_dtype,
validate_page_size,
attention_page_size,
)


⚠️ [ruff] <F401> reported by reviewdog 🐶
atom.plugin.sglang.glm52_mtp.common.compute_mtp_sparse_per_token_kv_lens imported but unused

compute_mtp_sparse_per_token_kv_lens,


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.common import (
get_extend_lens_cpu,
get_extend_prefix_lens_cpu,
get_seq_lens_cpu,
is_draft_extend_mode,
)
from atom.plugin.sglang.glm52_mtp.multi_token import build_mtp_multi_token_decode_metadata


⚠️ [ruff] <SIM103> reported by reviewdog 🐶
Return the condition directly

if int(getattr(forward_batch, "_graph_cache_bs", 0) or 0) > 0:
return True
return False


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import logging
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.common import (
attention_page_size,
build_token_table,
compute_mtp_sparse_per_token_kv_lens,
counts_to_indptr,
ensure_shared_sparse_buffer,
flatten_kv_indices,
get_index_topk,
is_draft_extend_mode,
local_num_attention_heads,
make_mla_work_buffers,
make_sparse_mtp_work_buffers,
metadata_dtype,
validate_page_size,
)


⚠️ [ruff] <SIM103> reported by reviewdog 🐶
Return the negated condition directly

if num_tokens_per_req is not None and int(num_tokens_per_req) != 1:
return False
return True


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.multi_token import build_mtp_multi_token_decode_metadata


⚠️ [ruff] <F841> reported by reviewdog 🐶
Local variable bs is assigned to but never used

bs = int(forward_batch.batch_size)


⚠️ [ruff] <F401> reported by reviewdog 🐶
contextlib imported but unused


⚠️ [ruff] <UP035> reported by reviewdog 🐶
Import from collections.abc instead: Iterable

from typing import Iterable, Optional, Tuple


⚠️ [ruff] <UP035> reported by reviewdog 🐶
typing.Tuple is deprecated, use tuple instead

from typing import Iterable, Optional, Tuple


⚠️ [ruff] <RET501> reported by reviewdog 🐶
Do not explicitly return None in function if it is the only possible return value


⚠️ [ruff] <RET501> reported by reviewdog 🐶
Do not explicitly return None in function if it is the only possible return value


⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception


⚠️ [ruff] <B010> reported by reviewdog 🐶
Do not call setattr with a constant attribute value. It is not any safer than normal property access.

setattr(
token_to_kv_pool,
"_atom_glm52_draft_decode_graph_metadata",
graph_cache,
)


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import logging
import os
from dataclasses import dataclass
from contextlib import AbstractContextManager, nullcontext
from typing import Any, Callable, Optional


⚠️ [ruff] <UP035> reported by reviewdog 🐶
Import from collections.abc instead: Callable

from typing import Any, Callable, Optional

import time
from glob import glob
from typing import Generator, Tuple
from typing import Callable, Generator, Tuple

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.

⚠️ [ruff] <UP035> reported by reviewdog 🐶
Import from collections.abc instead: Callable, Generator

Suggested change
from typing import Callable, Generator, Tuple
from typing import Tuple
from collections.abc import Callable, Generator

import time
from glob import glob
from typing import Generator, Tuple
from typing import Callable, Generator, Tuple

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.

⚠️ [ruff] <UP035> reported by reviewdog 🐶
typing.Tuple is deprecated, use tuple instead

*,
shard_files: list[str] | None = None,
key_filter: Callable[[str], bool] | None = None,
) -> Generator[Tuple[str, torch.Tensor], None, None]:

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.

⚠️ [ruff] <UP006> reported by reviewdog 🐶
Use tuple instead of Tuple for type annotation

Suggested change
) -> Generator[Tuple[str, torch.Tensor], None, None]:
) -> Generator[tuple[str, torch.Tensor], None, None]:

yield name, param
else:
with safetensors.safe_open(st_file, framework="pt", device="cpu") as f:
for name in f.keys():

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.

⚠️ [ruff] <SIM118> reported by reviewdog 🐶
Use key in dict instead of key in dict.keys()

Suggested change
for name in f.keys():
for name in f:

if remapped is None:
return False
name = remapped
for mapping_part in weights_mapping.keys():

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.

⚠️ [ruff] <SIM118> reported by reviewdog 🐶
Use key in dict instead of key in dict.keys()

Suggested change
for mapping_part in weights_mapping.keys():
for mapping_part in weights_mapping:

last_page_len: torch.Tensor
use_fast_metadata: bool
work_metadata: Optional[torch.Tensor] = None
work_indptr: Optional[torch.Tensor] = None

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.

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

Suggested change
work_indptr: Optional[torch.Tensor] = None
work_indptr: torch.Tensor | None = None

use_fast_metadata: bool
work_metadata: Optional[torch.Tensor] = None
work_indptr: Optional[torch.Tensor] = None
work_info_set: Optional[torch.Tensor] = None

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.

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

Suggested change
work_info_set: Optional[torch.Tensor] = None
work_info_set: torch.Tensor | None = None

work_metadata: Optional[torch.Tensor] = None
work_indptr: Optional[torch.Tensor] = None
work_info_set: Optional[torch.Tensor] = None
reduce_indptr: Optional[torch.Tensor] = None

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.

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

Suggested change
reduce_indptr: Optional[torch.Tensor] = None
reduce_indptr: torch.Tensor | None = None

work_indptr: Optional[torch.Tensor] = None
work_info_set: Optional[torch.Tensor] = None
reduce_indptr: Optional[torch.Tensor] = None
reduce_final_map: Optional[torch.Tensor] = None

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.

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

Suggested change
reduce_final_map: Optional[torch.Tensor] = None
reduce_final_map: torch.Tensor | None = None

work_info_set: Optional[torch.Tensor] = None
reduce_indptr: Optional[torch.Tensor] = None
reduce_final_map: Optional[torch.Tensor] = None
reduce_partial_map: Optional[torch.Tensor] = None

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.

⚠️ [ruff] <UP045> reported by reviewdog 🐶
Use X | None for type annotations

Suggested change
reduce_partial_map: Optional[torch.Tensor] = None
reduce_partial_map: torch.Tensor | None = None

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

import concurrent.futures
import json
import os
import logging
import re
import threading
import time
from glob import glob
from typing import Callable, Generator, Tuple
from collections.abc import Iterable, Mapping
from dataclasses import dataclass, field
from typing import Any, Optional
import safetensors
import safetensors.torch
import torch
from torch import nn
from tqdm import tqdm
from transformers import AutoConfig

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
from dataclasses import dataclass
import logging
import os
import re
from typing import Optional
import numpy as np
import torch
from aiter import (
cp_gather_indexer_k_quant_cache,
dtypes,
get_mla_metadata_info_v1,
get_mla_metadata_v1,
indexer_k_quant_and_cache,
indexer_qk_rope_quant_and_cache,
top_k_per_row_decode,
top_k_per_row_prefill,
)
from aiter.mla import mla_decode_fwd
from aiter.ops.triton.fp8_mqa_logits import fp8_mqa_logits
from aiter.ops.triton.pa_mqa_logits import deepgemm_fp8_paged_mqa_logits
import triton
import triton.language as tl
from atom.utils.custom_register import direct_register_custom_op
from atom.plugin.sglang.glm52_mtp.common import GLM52_GRAPH_SEQ_LEN_CAPACITY

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

import copy
import contextlib
import logging
import os
import re
from typing import Iterable, Optional, Tuple
import torch
from torch import nn
from sglang.srt.distributed import get_pp_group
from sglang.srt.layers.logits_processor import LogitsProcessor
from sglang.srt.layers.quantization.base_config import QuantizationConfig
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.server_args import get_global_server_args
from atom.config import QuantizationConfig as AtomQuantizationConfig
from atom.config import SpeculativeConfig
from atom.plugin.config import generate_atom_config_for_plugin_mode
from atom.plugin.sglang.models.deepseek_mla import (
setup_deepseek_for_sglang,
)
from atom.plugin.sglang.runtime import (
SGLangPluginRuntime,
plugin_runtime_scope,
)

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from atom.plugin.register import (
init_aiter_dist,
register_ops_to_sglang,
set_attn_cls,
)
from atom.models.deepseek_mtp import DeepSeekMTP

Keep target attention on the native ATOM GLM-5.2 backend and draft attention on the general AITER backend without a runtime mode switch. Remove debug metadata hooks, allocation pointer logs, and route-only logging wrappers.

@github-actions github-actions 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.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.common import (
attention_page_size,
build_token_table,
compute_mtp_sparse_per_token_kv_lens,
counts_to_indptr,
ensure_shared_sparse_buffer,
flatten_kv_indices,
get_index_topk,
is_draft_extend_mode,
local_num_attention_heads,
make_mla_work_buffers,
make_sparse_mtp_work_buffers,
metadata_dtype,
validate_page_size,
)


⚠️ [ruff] <SIM103> reported by reviewdog 🐶
Return the negated condition directly

if num_tokens_per_req is not None and int(num_tokens_per_req) != 1:
return False
return True


⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from __future__ import annotations
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.multi_token import build_mtp_multi_token_decode_metadata


⚠️ [ruff] <F841> reported by reviewdog 🐶
Local variable bs is assigned to but never used

bs = int(forward_batch.batch_size)


⚠️ [ruff] <F401> reported by reviewdog 🐶
contextlib imported but unused


⚠️ [ruff] <UP035> reported by reviewdog 🐶
Import from collections.abc instead: Iterable

from typing import Iterable, Optional, Tuple


⚠️ [ruff] <UP035> reported by reviewdog 🐶
typing.Tuple is deprecated, use tuple instead

from typing import Iterable, Optional, Tuple


⚠️ [ruff] <RET501> reported by reviewdog 🐶
Do not explicitly return None in function if it is the only possible return value


⚠️ [ruff] <RET501> reported by reviewdog 🐶
Do not explicitly return None in function if it is the only possible return value


⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception


⚠️ [ruff] <B010> reported by reviewdog 🐶
Do not call setattr with a constant attribute value. It is not any safer than normal property access.

setattr(
token_to_kv_pool,
"_atom_glm52_draft_decode_graph_metadata",
graph_cache,
)

Comment thread atom/plugin/register.py
from atom.plugin.sglang.glm52_mtp.common import (
GLM52_GRAPH_SEQ_LEN_CAPACITY,
)
except Exception as exc:

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.

⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception

Comment thread atom/plugin/register.py
@@ -204,6 +213,43 @@ def _is_dsv4_nextn_runner(runner) -> bool:
except Exception:

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.

⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception

Comment thread atom/plugin/register.py
or "DeepseekV3ForCausalLMNextN" in str(arch)
for arch in arches
)
except Exception:

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.

⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception

Comment thread atom/plugin/register.py
return model_type == "glm_moe_dsa" or any(
"GlmMoeDsaForCausalLM" in str(arch) for arch in arches
)
except Exception:

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.

⚠️ [ruff] <BLE001> reported by reviewdog 🐶
Do not catch blind exception: Exception

Comment thread atom/plugin/register.py
Comment on lines 405 to 406
except Exception:
pass

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.

⚠️ [ruff] <S110> reported by reviewdog 🐶
try-except-pass detected, consider logging the exception


def local_num_attention_heads(atom_config) -> int:
hf_config = atom_config.hf_config
num_heads = int(getattr(hf_config, "num_attention_heads"))

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.

⚠️ [ruff] <B009> reported by reviewdog 🐶
Do not call getattr with a constant attribute value. It is not any safer than normal property access.

Suggested change
num_heads = int(getattr(hf_config, "num_attention_heads"))
num_heads = int(hf_config.num_attention_heads)

Comment on lines +3 to +21
from __future__ import annotations

import torch
from aiter import get_mla_metadata_v1
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton

from atom.plugin.sglang.glm52_mtp.common import (
DECODE_GRAPH_BUFFERS_ATTR,
SHARED_SPARSE_INDICES_ATTR,
get_index_topk,
local_num_attention_heads,
make_mla_work_buffers,
metadata_dtype,
validate_page_size,
attention_page_size,
)


class GLM52DecodeGraphBuffers:

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

Suggested change
from __future__ import annotations
import torch
from aiter import get_mla_metadata_v1
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton
from atom.plugin.sglang.glm52_mtp.common import (
DECODE_GRAPH_BUFFERS_ATTR,
SHARED_SPARSE_INDICES_ATTR,
get_index_topk,
local_num_attention_heads,
make_mla_work_buffers,
metadata_dtype,
validate_page_size,
attention_page_size,
)
class GLM52DecodeGraphBuffers:
from __future__ import annotations
import torch
from aiter import get_mla_metadata_v1
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton
from atom.plugin.sglang.glm52_mtp.common import (
DECODE_GRAPH_BUFFERS_ATTR,
SHARED_SPARSE_INDICES_ATTR,
attention_page_size,
get_index_topk,
local_num_attention_heads,
make_mla_work_buffers,
metadata_dtype,
validate_page_size,
)
class GLM52DecodeGraphBuffers:

Comment on lines +12 to +30
from atom.plugin.sglang.glm52_mtp.common import (
DRAFT_SUB_STEP_ATTR,
attention_page_size,
build_draft_decode_token_table,
build_token_table,
compute_mtp_sparse_per_token_kv_lens,
counts_to_indptr,
ensure_shared_sparse_buffer,
flatten_kv_indices,
get_index_topk,
get_seq_lens_cpu,
local_num_attention_heads,
make_mla_work_buffers,
make_sparse_mtp_work_buffers,
metadata_dtype,
resolve_draft_decode_context_lens,
resolve_speculative_num_steps,
validate_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.

⚠️ [ruff] <F401> reported by reviewdog 🐶
atom.plugin.sglang.glm52_mtp.common.compute_mtp_sparse_per_token_kv_lens imported but unused

Suggested change
from atom.plugin.sglang.glm52_mtp.common import (
DRAFT_SUB_STEP_ATTR,
attention_page_size,
build_draft_decode_token_table,
build_token_table,
compute_mtp_sparse_per_token_kv_lens,
counts_to_indptr,
ensure_shared_sparse_buffer,
flatten_kv_indices,
get_index_topk,
get_seq_lens_cpu,
local_num_attention_heads,
make_mla_work_buffers,
make_sparse_mtp_work_buffers,
metadata_dtype,
resolve_draft_decode_context_lens,
resolve_speculative_num_steps,
validate_page_size,
)
from atom.plugin.sglang.glm52_mtp.common import (
DRAFT_SUB_STEP_ATTR,
attention_page_size,
build_draft_decode_token_table,
build_token_table,
counts_to_indptr,
ensure_shared_sparse_buffer,
flatten_kv_indices,
get_index_topk,
get_seq_lens_cpu,
local_num_attention_heads,
make_mla_work_buffers,
make_sparse_mtp_work_buffers,
metadata_dtype,
resolve_draft_decode_context_lens,
resolve_speculative_num_steps,
validate_page_size,
)

Comment on lines +3 to +19
from __future__ import annotations

import os

import numpy as np
import torch

from atom.plugin.sglang.glm52_mtp.common import (
get_extend_lens_cpu,
get_extend_prefix_lens_cpu,
get_seq_lens_cpu,
is_draft_extend_mode,
)
from atom.plugin.sglang.glm52_mtp.multi_token import build_mtp_multi_token_decode_metadata


def draft_extend_k_only() -> bool:

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

Suggested change
from __future__ import annotations
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.common import (
get_extend_lens_cpu,
get_extend_prefix_lens_cpu,
get_seq_lens_cpu,
is_draft_extend_mode,
)
from atom.plugin.sglang.glm52_mtp.multi_token import build_mtp_multi_token_decode_metadata
def draft_extend_k_only() -> bool:
from __future__ import annotations
import os
import numpy as np
import torch
from atom.plugin.sglang.glm52_mtp.common import (
get_extend_lens_cpu,
get_extend_prefix_lens_cpu,
get_seq_lens_cpu,
is_draft_extend_mode,
)
from atom.plugin.sglang.glm52_mtp.multi_token import (
build_mtp_multi_token_decode_metadata,
)
def draft_extend_k_only() -> bool:

Comment on lines +83 to +85
if int(getattr(forward_batch, "_graph_cache_bs", 0) or 0) > 0:
return True
return False

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.

⚠️ [ruff] <SIM103> reported by reviewdog 🐶
Return the condition directly

Suggested change
if int(getattr(forward_batch, "_graph_cache_bs", 0) or 0) > 0:
return True
return False
return int(getattr(forward_batch, "_graph_cache_bs", 0) or 0) > 0

Comment thread atom/plugin/register.py

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.

⚠️ [ruff] <I001> reported by reviewdog 🐶
Import block is un-sorted or un-formatted

from sglang.srt.model_executor.cuda_graph_runner import CudaGraphRunner
from sglang.srt.speculative.eagle_draft_cuda_graph_runner import (
EAGLEDraftCudaGraphRunner,
)
from sglang.srt.speculative.eagle_draft_extend_cuda_graph_runner import (
EAGLEDraftExtendCudaGraphRunner,
)
from sglang.srt.speculative.eagle_worker_v2 import EagleDraftWorker
from atom.plugin.sglang.glm52_mtp.common import (
GLM52_GRAPH_SEQ_LEN_CAPACITY,
)

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.

1 participant