Open
Conversation
…nalysis Adds nkipy.tools.profiler — a kernel-level profiler that correlates NeuronCore device traces with Python source lines, integrates with scalene for combined CPU + device profiling, and outputs scalene- compatible JSON for visualization. Key capabilities: - Per-line NRT (host submit) and NC (device compute) time attribution - NC/NRT ratio to identify sync vs async execution patterns - Device utilization analysis with idle gap breakdown (D2H/H2D transfers, memory mgmt, exec overhead, sync waits) - CPU-device overlap analysis (populates scalene "Unused Device %") - Per-kernel-name aggregation in scalene function profile table - Distributed support: scalene on rank 0 via torchrun + redirect_python - Kernel-only merge mode for device profiles without scalene Profiling is integrated into each model's test.sh via --profile flag: bash examples/models/qwen3/test.sh --profile bash examples/models/qwen3_embedding/test.sh --profile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nkipy.tools.profiler— kernel-level profiler correlating NeuronCore device traces with Python source linestest.sh --profileUsage
Known issues
LNC>1 double-counts parallel NC time
With
lnc=2, eachSpikeModel.__call__triggers 2nc_exec_runningevents (one per logical NeuronCore) that execute in parallel. The profiler currently sums all event durations, reporting core-time instead of wall-time. This inflates total NC time by ~2x and makes utilization % incorrect. Affects Qwen3-Embedding (LNC=2); Qwen3-30B TP=4 (LNC=1 per rank) is unaffected.Fix: merge overlapping NC host intervals so parallel cores count once, and group
LNCconsecutive NC events per kernel call for per-line attribution.Scalene signal overhead inflates NRT durations
When scalene CPU profiling is active, its signal-based sampling (
SIGVTALRM/SIGPROF) adds overhead tonrt_executehost calls. This shifts the NC/NRT ratio from ~1.9 (async, true hardware behavior) to ~0.6 (appears sync). NC time is unaffected — only host-side NRT is inflated.Workaround: use
--no-scalenefor accurate NRT measurements, or compare NRT with/without scalene to quantify the overhead.Test plan