Skip to content

refactor(serving): remove now-unused guard, debug, profiling, and host LM-head code from npu runners - #142

Merged
superxf merged 4 commits into
hw-native-sys:mainfrom
ndleslx:worktree-remove-kernel-contract-check
Aug 6, 2026
Merged

refactor(serving): remove now-unused guard, debug, profiling, and host LM-head code from npu runners#142
superxf merged 4 commits into
hw-native-sys:mainfrom
ndleslx:worktree-remove-kernel-contract-check

Conversation

@ndleslx

@ndleslx ndleslx commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Four focused dead-code cleanups, one per commit. Net deletion across all four; rebased onto current main.

refactor(deepseek): remove _validate_kernel_contract startup guard

Removes the fail-fast _validate_kernel_contract guard in DeepSeekV4PyptoExecutor plus its AST helper (_int_constant_from_file, _AST_INT_OPERATORS) and the now-unused import ast / import operator. The guard compared checked-in pypto-lib kernel constants against the serving layout at model load; purely defensive, no runtime dependency. Its two dedicated unit tests are dropped.

Also drops the now-unused importlib.util import, the unreferenced profile_verbose property (no callers; the base class does not define it), and the orphaned l3_trace constructor param / self._l3_trace attribute.

refactor(deepseek): remove npu_runner debug instrumentation

Removes the ad-hoc print-based debug scaffolding from DeepSeekV4ModelRunner:

  • _debug_prefill_dispatch, _debug_decode_dispatch, _debug_tensor_stats, _debug_tensor_stats_enabled, _tensor_is_finite and all their call sites (prefill / decode / lm-head), plus the now-unused import os. Gated on undocumented PYPTO_DSV4_* env vars, referenced nowhere outside this file.
  • The optional scope-stats profiling path (_scope_stats_run_config + its run_config branch in _run_l3), whose default output dir was hardcoded to a personal /data/liuxu/... path.
  • The MTP decode test that monkeypatched _debug_decode_dispatch.

refactor(serving): drop unused L3 timing plumbing from npu runners

Both runners captured the worker.run() return value and attached host/device wall times to profiling spans via per-runner helpers (_kernel_trace_name, _add_run_timing_args in deepseek; _kernel_trace_name, _run_timing_us, _add_run_timing_args in qwen). The captured timing was no longer consumed, so the helpers are removed and the dispatch methods (DeepSeekV4ModelRunner._run_l3, Qwen314BModelRunner._run_distributed_program) are simplified to a plain worker.run(...) that no longer records or returns timing. Profiling span names now use callable_spec.name directly.

refactor(deepseek): remove dead host LM-head and worker-reset code

Removes production-dead methods from DeepSeekV4ModelRunner now that the LM head runs on device and these host paths have no callers:

  • _is_layer_weight_name, _logits_for_hidden, _final_hidden, _final_norm (host-side LM-head / final-norm cluster)
  • _invalidate_resident_cache_tensors, _reset_l3_worker (unused worker teardown helpers)
  • the now-orphaned DEEPSEEK_V4_RMS_NORM_EPS / DEEPSEEK_V4_HC_EPS constants

Drops the two unit tests that exercised the removed host LM-head path.

Verification

  • No dangling references to any removed symbol repo-wide.
  • All touched modules py_compile cleanly.
  • pytest tests/unit/model/70 passed (on the rebased branch).

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fbcb3b8d-77a3-44d0-b7ae-57acdfd6b71d

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
📝 Walkthrough

Walkthrough

DeepSeek kernel contract validation, profiling exposure, dispatch diagnostics, tensor checks, and optional scope-statistics execution were removed. Related unit-test cases and debug-hook setup were deleted.

Changes

DeepSeek runtime cleanup

Layer / File(s) Summary
Remove kernel contract validation
pypto_serving/model/deepseek/npu_executor.py, tests/unit/model/deepseek/test_model_components.py
The executor no longer parses kernel constants, validates required modules or configuration values, or exposes profile_verbose. Tests for contract rejection were removed.
Remove runner diagnostics
pypto_serving/model/deepseek/npu_runner.py, tests/unit/model/deepseek/test_model_components.py
Dispatch hooks, tensor statistics, finite-output checks, LM-head diagnostics, and scope-statistics configuration were removed. L3 execution always calls worker.run with the compiled kernel and arguments. The fused MTP test no longer installs a debug hook.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Poem

A rabbit hops through kernels bright,
Contract checks fade from sight.
Debug prints rest, tensors run clean,
L3 calls stay direct and lean.
“Less noise,” says Bunny, “what a scene!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main cleanup changes in the DeepSeek NPU runners.
Description check ✅ Passed The description directly explains the removed guards, debug code, profiling paths, host LM-head code, tests, and verification.

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.

@ndleslx ndleslx changed the title refactor(deepseek): remove _validate_kernel_contract startup guard refactor(deepseek): remove kernel-contract guard and npu_runner debug instrumentation Aug 6, 2026
@ndleslx
ndleslx force-pushed the worktree-remove-kernel-contract-check branch from fe0909a to 46c1ce1 Compare August 6, 2026 03:32
@ndleslx
ndleslx marked this pull request as ready for review August 6, 2026 03:33
@ndleslx
ndleslx force-pushed the worktree-remove-kernel-contract-check branch from 46c1ce1 to 6feca44 Compare August 6, 2026 03:42
@ndleslx ndleslx changed the title refactor(deepseek): remove kernel-contract guard and npu_runner debug instrumentation refactor(serving): remove now-unused guard, debug, and profiling code from npu runners Aug 6, 2026
@ndleslx
ndleslx force-pushed the worktree-remove-kernel-contract-check branch 2 times, most recently from 9a52806 to 59b211a Compare August 6, 2026 08:23
@ndleslx ndleslx changed the title refactor(serving): remove now-unused guard, debug, and profiling code from npu runners refactor(serving): remove now-unused guard, debug, profiling, and host LM-head code from npu runners Aug 6, 2026
ndleslx added 4 commits August 6, 2026 01:53
Remove the fail-fast kernel-contract validator plus the AST-based helper
it depended on (_int_constant_from_file, _AST_INT_OPERATORS) and the now-
unused `ast`/`operator` imports. The guard compared checked-in pypto-lib
kernel constants against the serving layout at model load; it was purely
defensive, ran once off the hot path, and is no longer wanted. Drop its
two dedicated unit tests as well.

Also drop the now-unused `importlib.util` import, the unreferenced
`profile_verbose` property (no callers; the base class does not define
it), and the orphaned `l3_trace` constructor param / `self._l3_trace`
attribute.
Drop the ad-hoc print-based debug scaffolding from DeepSeekV4ModelRunner:
_debug_prefill_dispatch, _debug_decode_dispatch, _debug_tensor_stats,
_debug_tensor_stats_enabled, and _tensor_is_finite, plus their call sites
in the prefill/decode/lm-head paths and the now-unused `import os`. These
were gated on undocumented PYPTO_DSV4_DEBUG / PYPTO_DSV4_DEBUG_ARGS /
PYPTO_DSV4_LOGIT_DEBUG env vars and referenced nowhere outside this file.

Also remove the optional scope-stats profiling path (_scope_stats_run_config
and its run_config branch in _run_l3), whose default output dir was
hardcoded to a personal /data/liuxu path.

Update the MTP decode test that monkeypatched _debug_decode_dispatch.
Both runners captured the worker.run() return value and attached host/device
wall times to profiling spans via per-runner helpers: _kernel_trace_name and
_add_run_timing_args in deepseek (plus _run_timing_us in qwen). The captured
timing is no longer consumed, so remove the helpers and simplify the dispatch
methods (DeepSeekV4ModelRunner._run_l3, Qwen314BModelRunner._run_distributed_program)
to a plain worker.run(...) that no longer records or returns timing. Profiling
span names now use callable_spec.name directly instead of the prefill/decode
lane mapper.
Remove production-dead methods from DeepSeekV4ModelRunner now that the
LM head runs on device and these host paths have no callers:
- _is_layer_weight_name, _logits_for_hidden, _final_hidden, _final_norm
  (host-side LM-head / final-norm cluster)
- _invalidate_resident_cache_tensors, _reset_l3_worker (unused worker
  teardown helpers)
- the now-orphaned DEEPSEEK_V4_RMS_NORM_EPS / DEEPSEEK_V4_HC_EPS constants

Drop the two unit tests that exercised the removed host LM-head path
(test_deepseek_lm_head_computes_selected_rows_on_host_without_padded_vocab,
test_deepseek_final_hidden_normalizes_before_hc_head_projection_overflows).
@ndleslx
ndleslx force-pushed the worktree-remove-kernel-contract-check branch from 59b211a to 16da634 Compare August 6, 2026 08:55
@superxf
superxf merged commit c42271e into hw-native-sys:main Aug 6, 2026
4 checks passed
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.

2 participants