#596 by GitHub stars

stas00/the-art-of-debugging

Systematic methodology and concrete tool recipes for debugging Unix, Python, and PyTorch programs - crashes, hangs, segfaults, wrong output, CUDA OOM, NaN/Inf, slowness, and multi-node/multi-GPU issues. Use when a program crashes, hangs, deadlocks, segfaults, runs out of memory (OOM), produces NaN/I

History

Review weekly changes to SKILL.md before updating. Dates mark the weeks in which we observed each version; checks apply to the recorded commits.

View weekly changes

SKILL.md

Week of Nov 2, 2026 · +0 / −0 lines

Before Network or broad shell → After Network or broad shell

7e479bfba164 → 7e479bfba164

Diff text is unavailable under the recorded licenses. Line counts and the GitHub link remain available.

Compare on GitHub

Week of Oct 26, 2026 · Line counts unavailable

Before Not checked yet → After Network or broad shell

First observation → 7e479bfba164

No earlier version was observed for comparison.

Compare on GitHub

View on GitHubAdd to my skills

Verified commit 7e479bfba164b3f19cf4ccae2a038175fc05554e

1.7kGitHub stars
2stars in 7 days
1skill in this repository
3commits in 30 days

Heat

4.5
  • Star growth, last 7 daysAhead of 50% of tracked repositories
  • Star growth, last 24 hoursAhead of 84% of tracked repositories
  • Rank movement, last 7 daysAhead of 12% of tracked repositories
  • Commits, last 30 daysAhead of 64% of tracked repositories
  • Accounts asking about it through MCP, last 7 daysNot available
  • Hot votes this weekAhead of 0% of tracked repositories

Heat never changes the order by stars, and sponsorship never touches it. How heat works

Stars over time

Aug 1, 2026Nov 7, 20261,745

Individual skills in this repository

How it works

art-of-debugging

When your agent uses it

Systematic methodology and concrete tool recipes for debugging Unix, Python, and PyTorch programs - crashes, hangs, segfaults, wrong output, CUDA OOM, NaN/Inf, slowness, and multi-node/multi-GPU issues. Use when a program crashes, hangs, deadlocks, segfaults, runs out of memory (OOM), produces NaN/Inf or wrong numbers, runs too slowly, or when the user mentions gdb, strace, py-spy, core files, CUDA_LAUNCH_BLOCKING, ldd/nm/LD_PRELOAD, cProfile, or distributed training hangs. Distilled from "The Art of Debugging", the latest version of which can be found at https://github.com/stas00/the-art-of-debugging The latest SKILL.md version can be found at https://github.com/stas00/the-art-of-debugging/blob/master/SKILL.md

What it loads into context

Frontmatter

209 tokens

Always available to the agent

SKILL.md

6,160 tokens

When the skill is activated

Reference documents

124,232 tokens

Loaded on request

Token counts are estimates. Scripts run separately; they are not counted as reference context.

The playbook

  1. The debugging loop
  2. Unix / shell
  3. Compiled programs (C/C++, extensions, shared libraries)
  4. Python
  5. PyTorch (incl. CUDA / multi-GPU / multi-node)
  6. Pick the tool by symptom
  7. Notes for AI agents

Scripts executed separately

  • Makefile
  • build/check-links.py
  • build/check-new-links.sh
  • build/check-programs
  • build/check-redirects.py
  • build/check-style.py
  • build/check-table-width.py
  • build/cover/build_final_cover.py
  • build/fix-tables.py
  • build/mdbook/md-to-html.py
  • build/mdbook/mv-links.py
  • build/mdbook/preprocess-html-for-epub.py
  • build/mdbook/utils/build_utils.py
  • build/mdbook/utils/github_md_utils.py
  • python/grad_demo.py
  • pytorch/NicerTrace.py
  • pytorch/code/collective_mismatch.py
  • pytorch/code/collective_mismatch_analyze.py
  • pytorch/code/kernel_oob.py
  • pytorch/code/kernel_oob_gdb.py
  • pytorch/code/kernel_oob_prebuilt.py
  • pytorch/code/kernel_race.py
  • pytorch/code/see-mem-usage.py
  • pytorch/printflock.py
  • pytorch/tiny-scripts/c4-en-10k.py
  • pytorch/tiny-scripts/cm4-synthetic-testing.py
  • pytorch/tiny-scripts/fsmt-make-super-tiny-model.py
  • pytorch/tiny-scripts/general-pmd-ds-unpack.py
  • pytorch/tiny-scripts/general-pmd-synthetic-testing.py
  • pytorch/tiny-scripts/idefics-make-tiny-model.py
  • pytorch/tiny-scripts/m4-ds-unpack.py
  • pytorch/tiny-scripts/mt5-make-tiny-model.py
  • pytorch/tiny-scripts/openwebtext-10k.py
  • pytorch/tiny-scripts/oscar-en-10k.py
  • pytorch/torch-distributed-gpu-test.py
  • pytorch/underflow_overflow.py

Files

  • .gitignoreasset277 bytes
  • LICENSE-CC-BY-SAasset20,131 bytes
  • Makefileruns3,545 bytes
  • README.mddoc4,795 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • SKILL.mdcore24,281 bytes
  • build/README.mddoc2,473 bytes
  • build/SESSION.mddoc58,254 bytes
  • build/check-links.pyruns4,463 bytes
  • build/check-new-links.shruns1,662 bytes
  • build/check-programsruns2,483 bytes
  • build/check-redirects.pyruns20,342 bytes
  • build/check-style.pyruns3,893 bytes
  • build/check-table-width.pyruns12,152 bytes
  • build/consistency-checks.mddoc6,897 bytes
  • build/cover/README.mddoc164 bytes
  • build/cover/build_final_cover.pyruns10,826 bytes
  • build/cover/sources/labyrinth.pngasset1,874,689 bytes
  • build/fix-tables.pyruns11,285 bytes
  • build/linkcheckerrcasset211 bytes
  • build/mdbook/md-to-html.pyruns3,479 bytes
  • build/mdbook/mv-links.pyruns934 bytes
  • build/mdbook/preprocess-html-for-epub.pyruns5,736 bytes
  • build/mdbook/utils/build_utils.pyruns152 bytes
  • build/mdbook/utils/github_md_utils.pyruns7,416 bytes
  • build/prince_style.cssasset3,339 bytes
  • build/requirements.txtdoc53 bytes
  • chapters-md.txtdoc128 bytes
  • compiled-programs/README.mddoc34,752 bytes
  • compiled-programs/dl1/dl1.casset124 bytes
  • compiled-programs/dl1/util.casset88 bytes
  • compiled-programs/dl2/dl2.casset163 bytes
  • compiled-programs/dl2/util.casset157 bytes
  • compiled-programs/segfault/make-segfault.casset133 bytes
  • images/The-Art-of-Debugging-SKILL.pngasset1,631,220 bytes
  • images/The-Art-of-Debugging-book-cover-1536x1988.pngasset1,662,599 bytes
  • images/The-Art-of-Debugging-book-cover-200x259.pngasset48,644 bytes
  • images/The-Art-of-Debugging-book-cover.oraasset3,392,292 bytes
  • images/The-Art-of-Debugging-book-cover.pdfasset2,038,615 bytes
  • images/The-Art-of-Debugging-book-cover.pngasset284,516 bytes
  • images/The-Art-of-Debugging-book-cover.svgasset2,114,517 bytes
  • incoming.mddoc213 bytes
  • methodology.mddoc38 bytes
  • methodology/README.mddoc58,013 bytes
  • python/README.mddoc50,758 bytes
  • python/grad_demo.pyruns224 bytes
  • python/images/py-spy-flamegraph-speedscope.pngasset42,774 bytes
  • python/images/py-spy-flamegraph.pngasset22,439 bytes
  • python/images/pycharm-data-view.pngasset217,124 bytes
  • python/images/pycharm-demo-py.pngasset134,947 bytes
  • python/images/vscode-data-view.pngasset123,764 bytes
  • python/images/vscode-demo-py.pngasset69,263 bytes
  • pytorch/NicerTrace.pyruns9,469 bytes
  • pytorch/README.mddoc239,325 bytes
  • pytorch/code/collective_mismatch.pyruns495 bytes
  • pytorch/code/collective_mismatch_analyze.pyruns872 bytes
  • pytorch/code/kernel_oob.cuasset459 bytes
  • pytorch/code/kernel_oob.pyruns237 bytes
  • pytorch/code/kernel_oob_gdb.pyruns300 bytes
  • pytorch/code/kernel_oob_prebuilt.pyruns273 bytes
  • pytorch/code/kernel_race.cuasset513 bytes
  • pytorch/code/kernel_race.pyruns239 bytes
  • pytorch/code/see-mem-usage.pyruns4,950 bytes
  • pytorch/images/math-fp-discrepancy-outcome-lizard.pngasset689,964 bytes
  • pytorch/images/mem-profiler-llama-8b-ckpt-offload-cpu.pngasset427,834 bytes
  • pytorch/images/tensor-needle-in-a-hay-stack.pngasset32,098 bytes
  • pytorch/images/torch-mem-profile-mem-leak.pngasset189,562 bytes
  • pytorch/printflock.pyruns1,903 bytes
  • pytorch/tiny-scripts/README.mddoc686 bytes
  • pytorch/tiny-scripts/c4-en-10k.pyruns2,622 bytes
  • pytorch/tiny-scripts/cm4-synthetic-testing.pyruns8,260 bytes
  • pytorch/tiny-scripts/fsmt-make-super-tiny-model.pyruns3,263 bytes
  • pytorch/tiny-scripts/general-pmd-ds-unpack.pyruns3,142 bytes
  • pytorch/tiny-scripts/general-pmd-synthetic-testing.pyruns6,837 bytes
  • pytorch/tiny-scripts/idefics-make-tiny-model.pyruns1,545 bytes
  • pytorch/tiny-scripts/m4-ds-unpack.pyruns3,553 bytes
  • pytorch/tiny-scripts/mt5-make-tiny-model.pyruns3,347 bytes
  • pytorch/tiny-scripts/openwebtext-10k.pyruns3,078 bytes
  • pytorch/tiny-scripts/oscar-en-10k.pyruns4,193 bytes
  • pytorch/torch-distributed-gpu-test.pyruns3,787 bytes
  • pytorch/underflow_overflow.pyruns13,104 bytes
  • unix/README.mddoc27,880 bytes
  • unix/bash-git-prompt/Stas.bgpthemeasset2,619 bytes
  • unix/images/prompt.pngasset73,970 bytes

No excerpt is shown for this license. Read the source on GitHub.

View the complete source on GitHub

Skills included

  • art-of-debugging

Repository facts

License
CC-BY-SA-4.0
Created
Oct 1, 2023
Last pushed
Oct 13, 2026
Forks
107
Open issues
0
Project activity
Active

Rank over the last 12 weeks

Now #596 · best #422 · down 90 in 30 days

  1. #583 on Nov 2
  2. #586 on Nov 3
  3. #587 on Nov 4
  4. #591 on Nov 5
  5. #594 on Nov 6
  6. #596 since Nov 7
36 earlier periods
  1. #417 on Aug 1
  2. #405 on Aug 8
  3. #426 on Aug 13
  4. #424 on Aug 14
  5. #416 on Aug 15
  6. #422 on Aug 16
  7. #425 on Aug 17
  8. #430 on Aug 18
  9. #434 on Aug 19
  10. #432 on Aug 21
  11. #438 on Aug 25
  12. #442 on Aug 27
  13. #440 on Aug 28
  14. #437 on Sep 4
  15. #460 on Sep 8
  16. #461 on Sep 9
  17. #472 on Sep 14
  18. #462 on Sep 19
  19. #484 on Sep 22
  20. #471 on Sep 25
  21. #496 on Sep 30
  22. #488 on Oct 1
  23. #473 on Oct 3
  24. #478 on Oct 5
  25. #493 on Oct 6
  26. #492 on Oct 7
  27. #506 on Oct 8
  28. #505 on Oct 9
  29. #504 on Oct 11
  30. #512 on Oct 13
  31. #541 on Oct 21
  32. #564 on Oct 25
  33. #574 on Oct 28
  34. #577 on Oct 29
  35. #578 from Oct 30 to Oct 31
  36. #580 on Nov 1

Before you install

Network or broad shell

Automated signals, not a guarantee

Checked Nov 3, 2026

Not fully analyzed: some files were too long, unreadable or missing. This never lowers the level.

Show 30 notes
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
  • SKILL.md:1 Analysis incomplete: Referenced executable target unavailable; not analyzed
Show all 460 signals by file

Makefile

  • Executable scriptline 1
    Executable file
  • Dangerous shell operationline 70
    find . -name "*html" -exec rm {} \;

README.md

  • Network accessline 37
    6. **[Debugging Machine Learning Projects](https://github.com/stas00/ml-engineering/tree/master/debug)** (external)
  • Network accessline 42
    I announce any significant updates on my twitter channel [https://twitter.com/StasBekman](https://twitter.com/StasBekman).
  • Network accessline 47
    You can download various ebook formats of this book: * [PDF](https://huggingface.co/stas/the-art-of-debugging-book/resolve/main/Stas%20Bekman%20-%20The%20Art%20of%20Debugging.pdf?download=true)
  • Network accessline 48
    * [PDF](https://huggingface.co/stas/the-art-of-debugging-book/resolve/main/Stas%20Bekman%20-%20The%20Art%20of%20Debugging.pdf?download=true)
  • Network accessline 49
    * [EPUB](https://huggingface.co/stas/the-art-of-debugging-book/resolve/main/Stas%20Bekman%20-%20The%20Art%20of%20Debugging.epub?download=true)
  • Network accessline 57
    See also the companion skills: [Machine Learning Engineering](https://github.com/stas00/ml-engineering/blob/master/skills/ml-engineering/SKILL.md) and [Stas' Python Cookbook](https://github.com/stas00/python-cookbook/blob/master/SKILL.md).
  • Network accessline 62
    - [Machine Learning Engineering Open Book](https://github.com/stas00/ml-engineering) — training and operating large-scale ML models.
  • Network accessline 63
    - [Stas' Python Cookbook](https://github.com/stas00/python-cookbook) — everyday Python and standard-library recipes.
  • Network accessline 69
    If you found a bug, typo or would like to propose an improvement please don't hesitate to open an [Issue](https://github.com/stas00/the-art-of-debugging/issues) or contribute a PR.
  • Network accessline 80
    ✔ **Books:**  [Machine Learning Engineering](https://github.com/stas00/ml-engineering) |
  • Network accessline 81
    [Machine Learning Engineering](https://github.com/stas00/ml-engineering) |
  • Network accessline 82
    [The Art of Debugging](https://github.com/stas00/the-art-of-debugging) |
  • Network accessline 83
    [Stas' Python Cookbook](https://github.com/stas00/python-cookbook)
  • Network accessline 85
    ✔ **Applications:**  [ipyexperiments](https://github.com/stas00/ipyexperiments)
  • Network accessline 86
    [ipyexperiments](https://github.com/stas00/ipyexperiments)
  • Network accessline 88
    ✔ **Tools and Cheatsheets:**  [bash](https://github.com/stas00/bash-tools) |
  • Network accessline 89
    [bash](https://github.com/stas00/bash-tools) |
  • Network accessline 90
    [conda](https://github.com/stas00/conda-tools) |
  • Network accessline 91
    [git](https://github.com/stas00/git-tools) |
  • Network accessline 92
    [jupyter-notebook](https://github.com/stas00/jupyter-notebook-tools) |
  • Network accessline 93
    [make](https://github.com/stas00/make-tools) |
  • Network accessline 94
    [python](https://github.com/stas00/python-tools) |
  • Network accessline 95
    [tensorboard](https://github.com/stas00/tensorboard-tools) |
  • Network accessline 96
    [unix](https://github.com/stas00/unix-tools)
  • Network accessline 98
    ✔ **Other Machine Learning:**  [ML ways](https://github.com/stas00/ml-ways) |
  • Network accessline 99
    [ML ways](https://github.com/stas00/ml-ways) |
  • Network accessline 100
    [Porting](https://github.com/stas00/porting)

SKILL.md

  • Network accessline 8
    numbers, runs too slowly, or when the user mentions gdb, strace, py-spy,   core files, CUDA_LAUNCH_BLOCKING, ldd/nm/LD_PRELOAD, cProfile, or distributed   training hangs. Distilled from "The Art of Debugging", the latest version of which ca
  • Network accessline 10
    training hangs. Distilled from "The Art of Debugging", the latest version of which can be found at https://github.com/stas00/the-art-of-debugging
  • Network accessline 12
    The latest SKILL.md version can be found at https://github.com/stas00/the-art-of-debugging/blob/master/SKILL.md
  • Network accessline 17
    > Distilled from **The Art of Debugging Open Book** by Stas Bekman - source: https://github.com/stas00/the-art-of-debugging (CC BY-SA 4.0). This skill is a condensed index; each section links back to the full chapter for depth.
  • Network accessline 19
    Actionable methodology + copy-paste recipes for debugging Unix / Python / PyTorch programs. Apply the general loop first; then jump to the domain cheatsheet for the failure at hand. For scaling this up to large-model training/inference on r
  • Network accessline 25
    1. **Reproduce reliably.** Get one command that triggers the bug every time. If it's flaky, pin the nondeterminism (seeds, ordering, timing, network, uninitialized memory) first - you can't debug what you can't repeat. 2. **Shrink the paylo
  • Network accessline 26
    2. **Shrink the payload.** Make the repro *fast*: fewer layers, tiny model/data, one process, one CPU/GPU, one node. A 2-second repro beats a 2-minute one - you'll run it hundreds of times. See [methodology](https://github.com/stas00/the-ar
  • Network accessline 33
    - **Atomic debug cycles.** Make each iteration a single self-contained, repeatable command (setup + run in one shot) so you never hand-redo multi-step state. See [atomic debug cycles](https://github.com/stas00/the-art-of-debugging/blob/mast
  • Network accessline 34
    - **Automate diagnostics, minimize typing.** Alias the repro and your most-used commands; one keystroke to re-run. See [alias frequently used commands](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README.md#alias-f
  • Network accessline 35
    - **One-liner programs.** `perl`/`awk`/`python -c` to slice logs, extract fields, transform data on the fly instead of writing throwaway scripts. See [the power of one-liner programs](https://github.com/stas00/the-art-of-debugging/blob/mast
  • Network accessline 36
    - **Juggle configs cleanly** when running many debug experiments so results don't get confused. See [juggling multiple sets of configs](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README.md#juggling-multiple-sets-
  • Network accessline 45
    `traceback.print_stack()` shows callers without stopping (useful when the same function is reached via many paths). See [am I editing the right file and the right class?](https://github.com/stas00/the-art-of-debugging/blob/master/methodolog
  • Network accessline 46
    - **Bisect a regression.** `git bisect start / bad / good <rev>` walks commits automatically to the one that broke things - script the test for `git bisect run`. See [finding a breaking commit by bisecting](https://github.com/stas00/the-art
  • Network accessline 47
    - **Small/synthetic payload first.** Use tiny or synthetic inputs; switch to real data only when the bug is data-dependent. See [real vs random vs synthetic data](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README
  • Network accessline 48
    - **Race conditions.** Reordering/timing bugs hide under async; forcing synchronous execution can expose (or mask) them - note which. See [avoiding race conditions](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/READ
  • Network accessline 52
    - **Cap resources on purpose** to test failure paths: emulate a nearly-full disk, limited CPU RAM, or limited GPU memory. See [running out of resources](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README.md#runnin
  • Network accessline 53
    - **Watch resources live.** `watch -n1 nvidia-smi` / `free -h` / `df -h` in a second visible terminal to correlate a hang/OOM with what the machine is doing. See [watching and reproducing resource issues](https://github.com/stas00/the-art-o
  • Network accessline 54
    - **Inject `sleep`** to freeze a program at the interesting moment so you can attach a debugger or snapshot state. See [uses for sleep](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README.md#uses-for-sleep).
  • Network accessline 55
    - **HPC/SLURM:** keep the allocation and re-run with `srun` instead of re-`sbatch`-ing to cut per-iteration overhead. See [SLURM salloc and srun fast debug combo](https://github.com/stas00/the-art-of-debugging/blob/master/methodology/README
  • Network accessline 59
    Full chapter: [Unix Tools for Debugging](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md).
  • Network accessline 69
    Combine as `set -euo pipefail`. See [controlling script execution](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#controlling-script-execution).
  • Network accessline 78
    Classic use: a process at 100% CPU with no output, or hung on I/O/network. See [strace](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#strace).
  • Network accessline 83
    See [nohup](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#nohup).
  • Network accessline 84
    - **`make`** - after editing compiled sources, rebuild before re-testing, or you'll debug a stale binary. See [make](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#make).
  • Network accessline 85
    - **Terminal ergonomics:** search long scrollback and copy multi-line commands cleanly; keep an **informative prompt** (host, path, git branch, last exit code) so you always know where/what ran. See [shell environment](https://github.com/st
  • Network accessline 89
    Full chapter: [Debugging Compiled Programs](https://github.com/stas00/the-art-of-debugging/blob/master/compiled-programs/README.md). Compile with `-g` for debug symbols.
  • Dangerous shell operationline 94
    sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t  # control where cores go
  • Network accessline 104
    See [segmentation fault, core files and gdb](https://github.com/stas00/the-art-of-debugging/blob/master/compiled-programs/README.md#segmentation-fault-core-files-and-gdb).
  • Network accessline 110
    See [run the program under gdb](https://github.com/stas00/the-art-of-debugging/blob/master/compiled-programs/README.md#run-the-program-under-gdb).
  • Dangerous shell operationline 113
    sudo gdb --pid=PID    # attach; then: thread apply all bt
  • Network accessline 116
    See [get the backtrace from the still running process](https://github.com/stas00/the-art-of-debugging/blob/master/compiled-programs/README.md#get-the-backtrace-from-the-still-running-process).
  • Network accessline 124
    See [debugging shared libraries and symbol resolution](https://github.com/stas00/the-art-of-debugging/blob/master/compiled-programs/README.md#debugging-shared-libraries-and-symbol-resolution) ([ldd](https://github.com/stas00/the-art-of-debu
  • Network accessline 128
    Full chapter: [Debugging Python Programs](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md).
  • Network accessline 130
    - **Print effectively** instead of scattering bare `print`:   - **auto-print name+value** so you never mislabel output. See [auto-print what's being observed](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#auto-
  • Network accessline 131
    - **auto-print name+value** so you never mislabel output. See [auto-print what's being observed](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#auto-print-whats-being-observed).
  • Network accessline 132
    - **dump all attributes** of an object to see its real state. See [printing object variables](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#printing-object-variables).
  • Network accessline 133
    - **trace calls/returns** with `q` (writes to `/tmp/q`, doesn't pollute stdout). See [q](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#q).
  • Network accessline 140
    See [ensuring the Python package you edit is the one that is run](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#ensuring-the-python-package-you-edit-is-the-one-that-is-run) and [make tests use the git repo's pa
  • Network accessline 141
    - **Who called this?** `traceback.print_stack()` or the `die` trick to reveal the caller in complex codebases. See [who is calling?](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#who-is-calling).
  • Dangerous shell operationline 149
    No sudo? `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`. **The first line of each dump is where it's stuck.** See [py-spy](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#py-spy).
  • Network accessline 149
    No sudo? `echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope`. **The first line of each dump is where it's stuck.** See [py-spy](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#py-spy).
  • Network accessline 155
    For sub-ms functions, bump `pstats` precision (e.g. `pstats.f8 = lambda x: f"{x:6.3f}"`) so timings aren't all `0.000`. See [profilers](https://github.com/stas00/the-art-of-debugging/blob/master/python/README.md#profilers) and [cProfile](ht
  • Network accessline 159
    Full chapter: [Debugging PyTorch Programs](https://github.com/stas00/the-art-of-debugging/blob/master/pytorch/README.md).
  • Network accessline 163
    Shrink the model, not the problem - make a full run finish in seconds: - **Fewer layers** via (1) a local clone with config edits, (2) editing the config object on the fly, or (3) hacking the modeling code. See [reducing the number of layer
  • Network accessline 164
    - **Fewer layers** via (1) a local clone with config edits, (2) editing the config object on the fly, or (3) hacking the modeling code. See [reducing the number of layers](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#r
  • Network accessline 165
    - **Tiny random model + tiny tokenizer + tiny dataset** for near-instant iterations; reproduce at full scale only for scale-only bugs. See [making a tiny model](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#making-a-tin
  • Network accessline 174
    See [dealing with async CUDA bugs](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#dealing-with-async-cuda-bugs).
  • Network accessline 178
    - Distinguish OOM in **`forward`** (activations - batch/seq len) vs **`backward`** (gradients/optimizer state). See [debugging CUDA OOM in forward](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#debugging-cuda-oom-in-for
  • Network accessline 179
    - **Fragmentation** (free memory exists but not contiguous): tune `PYTORCH_ALLOC_CONF` (e.g. `expandable_segments:True`, `max_split_size_mb:...`). See [overcoming CUDA OOM due to memory fragmentation](https://github.com/stas00/the-art-of-de
  • Network accessline 180
    - **See who allocated what** with the memory profiler / allocation tracing; probe the ceiling with the allocatable-GBs test. See [PyTorch memory profiler](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#pytorch-memory-pro
  • Network accessline 181
    - **CPU OOM / peak RAM:** see [CPU memory](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#cpu-memory).
  • Network accessline 188
    Find where bad values first appear; watch fp underflow/overflow (especially fp16/bf16); expect small, benign cross-device numeric differences. Inspect tensors compactly (shape/device/dtype/stats) and use `lovely-tensors` for one-line summar
  • Network accessline 197
    See [segfaults and getting a backtrace from a core file](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#segfaults-and-getting-a-backtrace-from-a-core-file).
  • Network accessline 201
    1. **Verify comms first** with a minimal all-reduce test (`torch-distributed-gpu-test.py`); rule out network/NCCL before app code. See [getting nodes to talk to each other](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#
  • Network accessline 202
    2. **Dump every rank's stack at once** with `py-spy` (recipes for python/deepspeed/accelerate, across nodes via `srun`/`pdsh`). Ranks stuck at *different* lines reveal the desync (a mismatched collective). See [diagnosing crashes, hangs and
  • Network accessline 203
    3. **Make distributed output legible:** prefix every log line with `node:rank`, and target `pdb` at one rank. See [prefixing logs](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#prefixing-logs-with-noderank-interleaved-a
  • Network accessline 204
    4. **Narrow further:** check for a [network-level hang](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#network-level-hanging), [isolate a bad GPU](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#isolat
  • Network accessline 206
    For the cluster-level context around these bugs (verifying node connectivity, NCCL/InfiniBand tuning, network benchmarking, checkpointing/fault tolerance), see [Machine Learning Engineering](https://github.com/stas00/ml-engineering/blob/mas
  • Network accessline 216
    See [measuring durations](https://github.com/stas00/the-art-of-debugging/tree/master/pytorch#measuring-durations).
  • Network accessline 217
    - **Profile ops** with `torch.profiler` (CPU+GPU, op-level, small overhead); when it's not enough, drop to `cProfile` for pure-Python hot spots. See [performance and profiling](https://github.com/stas00/the-art-of-debugging/tree/master/pyto
  • Network accessline 245
    - **Read the linked chapter section** before applying an unfamiliar recipe - each has worked examples, caveats, and copy-paste scripts. - Prefer built-in, low-overhead tools (`py-spy`, `strace`, `gdb`, env vars) that need no source changes 
  • Network accessline 247
    - For large-scale ML training/inference engineering (bottleneck analysis, throughput/memory, distributed hangs at cluster scale, fault tolerance), use the companion skill: [Machine Learning Engineering](https://github.com/stas00/ml-engineer

build/README.md

  • Network accessline 12
    2. Download the free version of [Prince XML](https://www.princexml.com/download/). It's used to build the pdf version of this book.

build/SESSION.md

  • Network accessline 108
    1. In-book links use the file form `pytorch/README.md#anchor`, never the bare-directory form `pytorch#anchor`. The compiled HTML/PDF/epub build resolves the file form to a real anchor, but a bare directory has no anchor target in the built 
  • Network accessline 109
    2. GitHub-web caveat for large files: GitHub's blob (file) view does not serve heading-anchor ids for large Markdown files, so an absolute deep link such as `.../blob/master/pytorch/README.md#anchor` does not scroll to the section on a cold
  • Network accessline 110
    3. Remedy for that case only: for an *absolute* cross-repo deep link into a large folder-README, use the folder (`tree`) form `https://github.com/OWNER/REPO/tree/master/pytorch#anchor` instead of `.../blob/master/pytorch/README.md#anchor`. 
  • Network accessline 114
    7. A link can resolve perfectly and still be broken. After moving or rewriting any block that other places point at, check the referrers, not the thing you just edited. Grep for every inbound reference to the thing you moved, and for each o
  • Network accessline 116
    9. This book's one oversized deep-link target is `pytorch/README.md`, and it *is* a folder README - so the item 3 remedy applies: absolute/cross-repo links into it take the tree form `https://github.com/stas00/the-art-of-debugging/tree/mast
  • Network accessline 221
    wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36" URL
  • Network accessline 241
    8. A `000` result is bot mitigation, not death. Confirm with the browser user-agent recipe in `Sources and citations` item 9 before calling anything dead. 9. Watch the URL extractor itself. Markdown wraps URLs in ways that corrupt a naive r
  • Network accessline 242
    9. Watch the URL extractor itself. Markdown wraps URLs in ways that corrupt a naive regex: a closing paren ends the match, and a URL inside backticks picks the backtick up as its tail. 10. Two moves are invisible to an HTTP check, and `buil
  • Network accessline 243
    10. Two moves are invisible to an HTTP check, and `build/check-redirects.py` reports both. A **`<meta http-equiv="refresh">`** is markup rather than a status, so `curl -L` does not follow it and the stale URL answers `200` forever. Chains a

build/check-links.py

  • Executable scriptline 1
    #!/usr/bin/env python3
  • Network accessline 17
    # network. But one defect is detectable locally and cheaply, so it is caught on every run: a URL # wrapped into another URL. An archive citation legitimately carries two schemes # (web.archive.org/web/<ts>/https://original), so three or mor
  • Network accessline 18
    # wrapped into another URL. An archive citation legitimately carries two schemes # (web.archive.org/web/<ts>/https://original), so three or more means a replacement was applied to a # URL that was a substring of a longer one. Concrete near-
  • Network accessline 19
    # (web.archive.org/web/<ts>/https://original), so three or more means a replacement was applied to a

build/check-new-links.sh

  • Executable scriptline 1
    #!/usr/bin/env bash
  • Network accessline 25
    for url in "$@"; do     case "$url" in         http://*|https://*) ;;
  • Network accessline 26
    case "$url" in         http://*|https://*) ;;         *)
  • Network accessline 27
    http://*|https://*) ;;
  • Network accessline 57
    if result=$(curl "${curl_args[@]}" "$url" 2>&1); then
  • Network accessline 58
    printf 'LIVE %s -> %s\n' "$url" "$result"     elif result=$(curl --http1.1 "${curl_args[@]}" "$url" 2>&1); then         printf 'LIVE %s -> %s\n' "$url" "$result"
  • Network accessline 59
    elif result=$(curl --http1.1 "${curl_args[@]}" "$url" 2>&1); then

build/check-programs

  • Executable scriptline 1
    #!/usr/bin/env bash

build/check-redirects.py

  • Executable scriptline 1
    #!/usr/bin/env python3
  • Network accessline 8
    Two mechanisms are checked. HTTP redirects, which curl follows for us, and <meta refresh>,
  • Network accessline 55
    # A <meta http-equiv="refresh"> is a redirect that curl does not follow, because it is markup
  • Network accessline 118
    u = re.sub(r'^(https://github\.com/[^/]+/[^/]+)\.git$', r'\1', u)
  • Network accessline 145
    try:         r = subprocess.run(['curl', '-sL', '--max-time', '20', '-A', BROWSER_UA,
  • Network accessline 146
    r = subprocess.run(['curl', '-sL', '--max-time', '20', '-A', BROWSER_UA,
  • Network accessline 197
    """curl never sends the #fragment, so `final` always lacks it. Carry it over, or a naive

build/check-style.py

  • Executable scriptline 1
    #!/usr/bin/env python3

build/check-table-width.py

  • Executable scriptline 1
    #!/usr/bin/env python3
  • Network accessline 247
    ("|[" + "n" * 20 + "](https://example.com/" + "n" * 80 + ")|\n|---|\n|x|", False),

build/cover/build_final_cover.py

  • Executable scriptline 1
    #!/usr/bin/env python3
  • Network accessline 145
    return (         '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'         '<svg xmlns="http://www.w3.org/2000/svg" '
  • Network accessline 146
    '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'         '<svg xmlns="http://www.w3.org/2000/svg" '         'xmlns:xlink="http://www.w3.org/1999/xlink" '
  • Network accessline 147
    '<svg xmlns="http://www.w3.org/2000/svg" '
  • Network accessline 148
    'xmlns:xlink="http://www.w3.org/1999/xlink" '
  • Network accessline 149
    'xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" '

build/fix-tables.py

  • Executable scriptline 1
    #!/usr/bin/env python

build/linkcheckerrc

  • Network accessline 1
    # rtfm https://linkchecker.github.io/linkchecker/man/linkcheckerrc.html

build/mdbook/md-to-html.py

  • Executable scriptline 1
    Executable file
  • Network accessline 19
    my_repo_url = "https://github.com/stas00/the-art-of-debugging/blob/master"
  • Network accessline 48
    with open(cover_md_file, "w") as f:         f.write(f"""         PDF Conversion was done with https://www.princexml.com
  • Network accessline 49
    f.write(f"""         PDF Conversion was done with https://www.princexml.com <div class="page_break"></div>
  • Network accessline 50
    PDF Conversion was done with https://www.princexml.com
  • Network accessline 55
    This is an ebook version of [The Art of Debugging Open Book by Stas Bekman](https://github.com/stas00/the-art-of-debugging/) generated on {date}.
  • Network accessline 57
    As this book is constantly being updated, if you downloaded it as a pdf or an epub file and the date isn't recent, chances are that it's already outdated - make sure to check the latest version at [https://github.com/stas00/the-art-of-debug

build/mdbook/mv-links.py

  • Executable scriptline 1
    Executable file

build/mdbook/preprocess-html-for-epub.py

  • Executable scriptline 1
    #!/usr/bin/env python3

build/mdbook/utils/build_utils.py

  • Executable scriptline 1
    Executable file

build/mdbook/utils/github_md_utils.py

  • Executable scriptline 1
    Executable file
  • Network accessline 115
    # - empty links (i.e. just local anchor to the same doc)     # - skip explicit .md links     # - external links like https://...
  • Network accessline 117
    # - external links like https://...
  • Network accessline 150
    # skip:     # - empty links (i.e. just local anchor to the same doc)     # - external links like https://...
  • Network accessline 152
    # - external links like https://...
  • Network accessline 241
    # # run to test some of these utils     # para = 'bb [Markdown text](foo.md#tar) aaa bb [Markdown text2](foo/#bar) aaa [Markdown text3](http://ex.com/foo/#bar)'
  • Network accessline 242
    # para = 'bb [Markdown text](foo.md#tar) aaa bb [Markdown text2](foo/#bar) aaa [Markdown text3](http://ex.com/foo/#bar)'

build/prince_style.css

  • Network accessline 1
    /*   CSS style sheet for prince html2pdf system (http://www.princexml.com/)
  • Network accessline 2
    CSS style sheet for prince html2pdf system (http://www.princexml.com/)
  • Network accessline 6
    prince --no-author-style -s prince_style.css http://en.wikipedia.org/wiki/Winter_war -o foo.pdf
  • Network accessline 9
    @import url(http://www.princexml.com/fonts/gentium/index.css);

compiled-programs/README.md

  • Network accessline 35
    git clone https://github.com/stas00/the-art-of-debugging
  • Dangerous shell operationline 126
    sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
  • Dangerous shell operationline 154
    sudo sysctl -w kernel.core_pattern=core-%e.%p.%h.%t
  • Network accessline 191
    case study: [this issue](https://github.com/pytorch/pytorch/issues/59384#issuecomment-854953165) shows a huge traceback from PyTorch crashing.
  • Dangerous shell operationline 198
    sudo gdb --pid=107903
  • Network accessline 206
    case study: see this [Issue](https://github.com/pytorch/pytorch/issues/60158#issuecomment-865142029) for an example of how this approach was used to diagnose a deadlock in PyTorch. This is also a good example of seeing a backtrace for multi
  • Network accessline 283
    case study: [this issue](https://github.com/pytorch/pytorch/issues/46807#issuecomment-718452462) shows how gdb was used to get a backtrace on a crashing test.
  • Network accessline 285
    footnote: more useful recipes for python + gdb can be found [here](https://wiki.python.org/moin/DebuggingWithGdb).
  • Network accessline 287
    footnote: this chapter assumes you only have the binary. In the less common case where you do have the source and can recompile it, building with the compiler sanitizers - `-fsanitize=address` for memory errors (out-of-bounds, use-after-fre
  • Dangerous shell operationline 319
    sudo ldconfig
  • Network accessline 680
    case study: in other situations a symbol could be missing because the program wasn't linked properly at build time. Here is a bug report [undefined symbol curandCreateGenerator for torch extensions](https://github.com/pytorch/pytorch/issues
  • Network accessline 714
    Primary reference: [NVIDIA CUDA installation guide for Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/).
  • Dangerous shell operationline 744
    sudo apt-get install -y ltrace

images/The-Art-of-Debugging-book-cover.svg

  • Network accessline 1
    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="1536" height="1988" viewBox="0 0 1
  • Network accessline 2
    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="1536" height="1988" viewBox="0 0 1536 1988">

methodology/README.md

  • Network accessline 78
    If you are into Machine Learning and want to go into a detailed process please read: [Faster debug and development with tiny models, tokenizers and datasets](https://github.com/stas00/ml-engineering/blob/eb81cd46a3b508d7ef6bd3f528134f9b7721
  • Network accessline 92
    footnote: I was able to get a [PCIe version of A100 working in my desktop](https://stasosphere.com/entrepreneur-being/262-getting-nvidia-a100-80gb-pcie-to-work-on-a-consumer-motherboard-with-custom-water-cooling/). I was hoping that I could
  • Dangerous shell operationline 160
    rm -r data
  • Dangerous shell operationline 167
    rm -r data; ./launch.sh
  • Network accessline 175
    This is also why notebook technologies like [Jupyter Notebook](https://jupyter.org/), [IPython](https://en.wikipedia.org/wiki/IPython) and alike, which allow you to go back and forth between different lines of code and re-execute them selec
  • Dangerous shell operationline 184
    rm -r data; echo start; ./launch.sh
  • Dangerous shell operationline 189
    rm -r data && echo start && ./launch.sh
  • Network accessline 300
    # reset branch's HEAD to a given commit hash: # find the last commit that was supposed to be the HEAD, e.g.: # https://github.com/fastai/fastai/commit/1c63e868d3d11e73d9f51f58cbd271e67a0fe983
  • Network accessline 301
    # find the last commit that was supposed to be the HEAD, e.g.: # https://github.com/fastai/fastai/commit/1c63e868d3d11e73d9f51f58cbd271e67a0fe983 # and now reset the branch's HEAD to it
  • Network accessline 302
    # https://github.com/fastai/fastai/commit/1c63e868d3d11e73d9f51f58cbd271e67a0fe983
  • Network accessline 373
    # use the PR version of transformers till it's merged git clone https://github.com/huggingface/transformers -b add-model-idefics
  • Network accessline 374
    git clone https://github.com/huggingface/transformers -b add-model-idefics
  • Network accessline 377
    # reshard this model - replace only this to do another model git clone https://huggingface.co/HuggingFaceM4/idefics-9b
  • Network accessline 378
    git clone https://huggingface.co/HuggingFaceM4/idefics-9b
  • Dangerous shell operationline 393
    git rm pytorch_model-*.bin
  • Dangerous shell operationline 394
    git rm model*safetensors
  • Network accessline 409
    Here are some of my cheatsheets if you need a starter: [ [python](https://github.com/stas00/python-tools/blob/main/python.txt) |
  • Network accessline 410
    [ [python](https://github.com/stas00/python-tools/blob/main/python.txt) | [git](https://github.com/stas00/git-tools/blob/master/git.txt) |
  • Network accessline 411
    [python](https://github.com/stas00/python-tools/blob/main/python.txt) |
  • Network accessline 412
    [git](https://github.com/stas00/git-tools/blob/master/git.txt) |
  • Network accessline 413
    [bash](https://github.com/stas00/bash-tools/blob/main/bash.txt) |
  • Network accessline 414
    [make](https://github.com/stas00/make-tools/blob/main/make.txt) |
  • Network accessline 415
    [conda](https://github.com/stas00/conda-tools/blob/master/conda.txt)
  • Network accessline 444
    Sometimes it's even possible to completely automate the reporting w/o requiring any typing at all. When I try to debug memory leaks I use tools that report memory usage or deltas automatically. e.g. I developed [ipyexperiments](https://gith
  • Network accessline 446
    gdb supports the same idea via `~/.gdbinit`, where you can add your own [user-defined commands](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Define.html) and `alias`es. And for ready-made productivity boosters there are full enhan
  • Network accessline 448
    Learn your shell's line-editing and history shortcuts - they save a lot of debug time. These are covered in the Unix chapter under [Handy shell shortcuts](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#handy-shell
  • Network accessline 493
    footnote: stepping aside from the discussion of debugging I use one-liners for refactoring/renaming - since I can then share these with others who are impacted by my changes and they can just copy-n-paste my commands and immediately update 
  • Network accessline 500
    As you warm up to the joy and profit of using one-liners make sure to empower yourself with [Handy shell shortcuts](https://github.com/stas00/the-art-of-debugging/blob/master/unix/README.md#handy-shell-shortcuts) to navigate the command lin
  • Dangerous shell operationline 510
    python -c "import torch; exec('with torch.cuda.device(0):\n  x = torch.ones(1,1)')"
  • Dangerous shell operationline 630
    sudo mount -t tmpfs -o size=1G,user,mode=1777 tmpfs ~/ramdisk
  • Network accessline 641
    Just beware that `tmpfs` uses volatile virtual memory. When you unmount this partition or reboot your system all files created in this partition will disappear. You can read about tmpfs [here](https://www.kernel.org/doc/html/latest/filesyst
  • Dangerous shell operationline 645
    sudo umount ~/ramdisk
  • Network accessline 699
    You can read [A Deep Investigation into MMAP Not Leaking Memory](https://stasosphere.com/entrepreneur-being/301-mmap-memory-leak-investigation/) to see how I used this technique to figure out whether MMAP leaks memory or not.
  • Network accessline 701
    For the detailed manpage see [systemd-run](https://www.freedesktop.org/software/systemd/man/systemd-run.html) and for additional properties that can be set [this section](https://www.freedesktop.org/software/systemd/man/systemd.resource-con
  • Network accessline 743
    If you have a recent NVIDIA GPU (A100, H100, and higher) you could also reshape your GPU using Multi-Instance GPU (MIG) as explained [here](https://www.nvidia.com/en-us/technologies/multi-instance-gpu/). So if you're trying to ensure your s
  • Network accessline 797
    git clone https://github.com/huggingface/transformers
  • Network accessline 820
    So for example if you know that `transformers==4.33.0` was good and `transformers@main` (`HEAD`) is bad, find which commit is corresponding to the tag `4.33.0` by visiting [the releases page](https://github.com/huggingface/transformers/rele
  • Network accessline 891
    You can then go to `https://github.com/huggingface/transformers/commit/` and append the commit SHA to that url which will take you to the commit, (e.g. `https://github.com/huggingface/transformers/commit/57f44dc4288a3521bd700405ad41e90a4687

python/README.md

  • Network accessline 20
    This package, that can be installed from https://github.com/zestyping/q or `pip install q`, is designed for a quick code and function tracing. By default it sends its output into the `/tmp/q` file, so in one console start watching this file
  • Network accessline 168
    You can control what attributes are dumped via various args to [`rich.inspect()`](https://rich.readthedocs.io/en/stable/reference/init.html#rich.inspect).
  • Network accessline 170
    The closest Python built-in way I found is `inspect.getmembers()`, but alas it won't let me filter the variable attributes (but it does let you filter by other types of attributes via a [`predicate` argument](https://docs.python.org/3.13/li
  • Network accessline 303
    git clone https://github.com/huggingface/transformers/
  • Network accessline 312
    git clone https://github.com/huggingface/transformers/
  • Network accessline 320
    we used `src` because that's where source files of HF `transformers` package reside, that is they are under `[src/](https://github.com/huggingface/transformers/tree/main/src/). Other git repos could use a different path where they place the
  • Network accessline 371
    There is an easy solution to that. You can see how I did it in [ipyexperiments](https://github.com/stas00/ipyexperiments). I created [tests/conftest.py](https://github.com/stas00/ipyexperiments/blob/39c9b454e89e53b74c74dcb579c12ecf3d2161b9/
  • Network accessline 396
    If your project uses a sub-directory like HF `transformers`' `src`, simply add it to the `git_repo_path`, e.g. you can see how this is done [here](https://github.com/huggingface/transformers/blob/6cbc1369a330860c128a1ba365f246751382c9e5/con
  • Network accessline 438
    The sections above are terminal-driven - you type commands at a prompt. The other major family is the graphical debugger built into an IDE, where the breakpoints, the call stack, the source and the variable inspector are all on the screen a
  • Network accessline 440
    footnote: [Cursor](https://cursor.com/download) is a fork of VSCode, so everything that applies to VSCode in this section applies to Cursor alike.
  • Network accessline 514
    case study: In 2020 I ported my first model architecture to HF Transformers and I was using 2 PyCharm instances to step through the original model code in fairseq and the new model code in Transformers - I was matching the tensor values on 
  • Access to secretsline 573
    [Credential-related source omitted]
  • Network accessline 597
    cProfile is a built-in profiler that is quite easy to use. The full documentation is [here](https://docs.python.org/3/library/profile.html).
  • Network accessline 679
    The only argument to `pr.print_stats` is how you want the output to be sorted, the example above uses `SortKey.CUMULATIVE` - cumulative time, `SortKey` is an `enum` variable, with other commonly useful values are `SortKey.TIME` (total time)
  • Network accessline 728
    The argument to `stats.sort_stats` could be a string name or the `SortKey` enum like in the previous example. The complete table of options is [here](https://docs.python.org/3/library/profile.html#pstats.Stats.sort_stats).
  • Network accessline 967
    Finally, `py-spy record -f speedscope` writes the profile for [speedscope](https://www.speedscope.app/) instead of an SVG, which adds a time-ordered view of the samples that a flame graph deliberately discards. Here is what it looks like (w

python/grad_demo.py

  • Executable scriptline 1
    Executable file

pytorch/NicerTrace.py

  • Executable scriptline 1
    Executable file
  • Network accessline 85
    It was written against https://github.com/python/cpython/blob/3.8/Lib/trace.py. If you're
  • Access to secretsline 207
    [Credential-related source omitted]
  • Dangerous shell operationline 226
    # string with commands to run - passed to exec()

pytorch/README.md

  • Network accessline 13
    Moreover, large models often require massive resources, which are typically expensive and can also can make a debugging process super complicated. For example any debugger can handle a single process, but if your model doesn't fit and requi
  • Network accessline 26
    Important: given their popularity and the well designed simple API I will be discussing HF [`transformers`](https://github.com/huggingface/transformers/) models. But the same principle can be applied to any other model.
  • Network accessline 39
    Now let's go through the actual code and convert ["google/mt5-small"](https://huggingface.co/google/mt5-small/tree/main) into its tiny random counterpart.
  • Network accessline 63
    Also please note that you don't need any GPUs to do that and you could do this even on a huge 176B parameter model like [BLOOM-176B](https://huggingface.co/bigscience/bloom). Since you never load the actual original model, except its config
  • Network accessline 81
    The original ["google/mt5-small"](https://huggingface.co/google/mt5-small/tree/main) model file was 1.2GB. With the above changes (and vocab shrinking as explained in the following sections) we got it down to 126MB.
  • Network accessline 83
    If you're dealing with a multi-level nested config, you will have to update each sub-level's config object separately. For example in [IDEFICS](https://huggingface.co/HuggingFaceM4/idefics-9b/blob/main/config.json) we have 1 main and 2 nest
  • Network accessline 105
    A related trap: architectures that interleave block types spell the pattern out in a `layer_types` list with one entry per layer. [Qwen/Qwen-AgentWorld-35B-A3B](https://huggingface.co/Qwen/Qwen-AgentWorld-35B-A3B/blob/main/config.json#L19) 
  • Network accessline 152
    [Anthony Moi](https://github.com/n1t0)'s tokenizer shrinker:
  • Network accessline 199
    [Lysandre Debut](https://github.com/LysandreJik)' shrinker using `train_new_from_iterator`:
  • Network accessline 274
    Here is the full version of [make_tiny_model.py](https://huggingface.co/stas/tiny-random-llama-2/blob/main/make_tiny_model.py) which includes both the model and the tokenizer shrinking.
  • Network accessline 281
    git clone https://github.com/google/sentencepiece
  • Access to secretsline 286
    [Credential-related source omitted]
  • Network accessline 301
    tokenizer_orig.save_pretrained(tmp_dir) with open(vocab_orig_path, 'rb') as f: data = f.read() # adapted from https://blog.ceshine.net/post/trim-down-sentencepiece-vocabulary/
  • Network accessline 302
    with open(vocab_orig_path, 'rb') as f: data = f.read() # adapted from https://blog.ceshine.net/post/trim-down-sentencepiece-vocabulary/ m = model.ModelProto()
  • Network accessline 303
    # adapted from https://blog.ceshine.net/post/trim-down-sentencepiece-vocabulary/
  • Network accessline 321
    If we continue the MT5 code from earlier in this chapter and add the tokenizer shrinking code from the previous section, we end up with this script [mt5-make-tiny-model.py](https://huggingface.co/stas/mt5-tiny-random/blob/main/mt5-make-tiny
  • Network accessline 323
    Here is another example  [fsmt-make-super-tiny-model.py](https://huggingface.co/stas/tiny-wmt19-en-ru/blob/main/fsmt-make-super-tiny-model.py) - here you can see I'm creating a totally new tiny vocab from scratch.
  • Network accessline 327
    Also be aware that since HF `transformers` needs tiny models for their testing, you are very likely to already find one for each architecture available mostly from https://huggingface.co/hf-internal-testing (except they didn't include the c
  • Network accessline 346
    footnote: as of [`datasets` 4.0](https://github.com/huggingface/datasets/releases/tag/4.0.0), Hub-hosted Python loading scripts are no longer executed by `load_dataset`. Keep any builder/unpacker `.py` in the repo as documentation of how th
  • Network accessline 350
    - [stas/oscar-en-10k](https://huggingface.co/datasets/stas/oscar-en-10k/blob/main/oscar-en-10k.py)
  • Network accessline 351
    - [stas/c4-en-10k](https://huggingface.co/datasets/stas/c4-en-10k/blob/main/c4-en-10k.py)
  • Network accessline 352
    - [stas/openwebtext-10k](https://huggingface.co/datasets/stas/openwebtext-10k/blob/main/openwebtext-10k.py)
  • Network accessline 356
    And here are some examples of synthetic datasets, where instead of just shrinking the original tarball, I untar'ed it, manually chose the representative examples and then wrote a script to build any size of desired dataset based on those fe
  • Network accessline 357
    - [stas/general-pmd-synthetic-testing](https://huggingface.co/datasets/stas/general-pmd-synthetic-testing/blob/main/general-pmd-synthetic-testing.py) and the [unpacker](https://huggingface.co/datasets/stas/general-pmd-synthetic-testing/blob
  • Network accessline 358
    - [stas/cm4-synthetic-testing](https://huggingface.co/datasets/stas/cm4-synthetic-testing/blob/main/cm4-synthetic-testing.py) - and the [unpacker](https://huggingface.co/datasets/stas/cm4-synthetic-testing/blob/main/m4-ds-unpack.py)
  • Network accessline 366
    And here is for example the instructions of deploying these scripts for [stas/general-pmd-synthetic-testing](https://huggingface.co/datasets/stas/general-pmd-synthetic-testing/):
  • Network accessline 369
    # prep dataset repo https://huggingface.co/new-dataset => stas/general-pmd-synthetic-testing
  • Network accessline 370
    https://huggingface.co/new-dataset => stas/general-pmd-synthetic-testing
  • Network accessline 371
    git clone https://huggingface.co/datasets/stas/general-pmd-synthetic-testing
  • Dangerous shell operationline 376
    rm -rf data
  • Dangerous shell operationline 387
    rm image.jpg text.txt
  • Network accessline 407
    Similar to tiny models, you will find many tiny datasets under https://huggingface.co/hf-internal-testing.
  • Network accessline 421
    perl -lne 'while (/(https.*?.py)\)/g) { $x=$1; $x=~s/blob/raw/; print qq[wget $x] }' make-tiny-models.md
  • Network accessline 430
    Therefore in this section we will discuss how to reduce the model's number of hidden layers from many to just 1-2. If the layers aren't identical (e.g. some MoE models alternate between 2 different block configurations) then ensure you incl
  • Network accessline 434
    The config entry that we want to change is [`num_hidden_layers`](https://huggingface.co/Qwen/Qwen3-30B-A3B-Instruct-2507/blob/e67ac5d/config.json#L24). Some architectures pair it with a companion entry that has to be trimmed in lockstep - a
  • Network accessline 439
    git clone https://huggingface.co/Qwen/Qwen3-30B-A3B-Instruct-2507
  • Network accessline 468
    After finding the desired model on https://huggingface.co/, clone its git repo to the local disk, modify the `num_hidden_layers` entry in `config.json`, and then load the model from the local clone (same as we have just shown when measuring
  • Network accessline 471
    git clone https://huggingface.co/Qwen/Qwen3-30B-A3B-Instruct-2507
  • Network accessline 507
    git clone https://github.com/huggingface/transformers/tree/main/src/transformers
  • Network accessline 513
    Continuing the example of working with `Qwen/Qwen3-30B-A3B-Instruct-2507` model, we find the place where its architecture modeling code lives in the HF Transformers code base. For example, we can look at the `architectures` field in the [mo
  • Network accessline 578
    When I was debugging 15M sequence length training using [ALST](https://arxiv.org/abs/2506.13996) - I would only run self-attention in the last layer and then skip it in the previous layers - this reduced my testing time from hours to minute
  • Network accessline 716
    Luckily, PyTorch has a special [autograd mechanism that is used to detect anomalies](https://docs.pytorch.org/docs/stable/autograd.html#debugging-and-anomaly-detection). When enabled it'll augment the `backward` traceback with the `forward`
  • Network accessline 809
    When developing [Arctic Long Sequence Training](https://arxiv.org/abs/2506.13996) a lot of the work involved hard (`contiguous`) reshaping of tensors for Sequence Parallelism, which lead to a very poor HBM utilization, because the reshapes 
  • Network accessline 859
    Indeed, H200 is about 140GiB, so this checks out. You might wonder what's the point of this. This discovery code is useful when you have to deal with multiple systems accessing the same GPU - e.g. VLLM and VeRL sharing the same GPUs and PyT
  • Network accessline 914
    The solution: to prevent CPU from stealing GPU memory switch to the CDMM mode (from the default NUMA mode), as explained in a paper linked from [this post](https://developer.nvidia.com/blog/understanding-memory-management-on-hardware-cohere
  • Dangerous shell operationline 916
    $ echo options nvidia NVreg_CoherentGPUMemoryMode=driver | sudo tee /etc/modprobe.d/nvidia-openrm.conf
  • Network accessline 967
    At this stage you'd typically go to https://docs.pytorch.org/memory_viz and drop the memory profile pickle file you generated in Stage 1 into the browser at that URL. The most useful feature there is the 'Active memory profile` drop-down me
  • Network accessline 969
    To get a feeling for what it looks like, here is an example of a memory profile rendering for a memory leak I discovered while I was working on a tricky implementation of a [`TiledMLP` `torch.autograd.Function`](https://github.com/deepspeed
  • Network accessline 977
    As long as you're in the `forward` function it's relatively easy to find where in the code leaks comes from. But if it's a `backward` it becomes much more complicated unless you're debugging a custom autograd function. Still it should give 
  • Network accessline 979
    Besides profiling memory leaks, this functionality is also useful for showing how different implementations of the same algorithm use a different amount of gpu memory. For example, the following visualization I prepared for the [Arctic Long
  • Network accessline 994
    Additional resources: - [Understanding GPU Memory 1: Visualizing All Allocations over Time](https://pytorch.org/blog/understanding-gpu-memory-1/)
  • Network accessline 995
    - [Understanding GPU Memory 1: Visualizing All Allocations over Time](https://pytorch.org/blog/understanding-gpu-memory-1/)
  • Network accessline 996
    - HF folks made an [improved rendering version](https://huggingface.co/spaces/Leiyre/memory-viz).
  • Network accessline 1001
    While external memory profilers can be very useful, often having control over when you take a sample of GPU and CPU memory usage is needed. `see-mem-usage` debug util has been developed by the [DeepSpeed project](https://github.com/deepspee
  • Network accessline 1162
    For example, here is how I found a memory leak in `all_gather_object`, which you can see from this [Issue](https://github.com/pytorch/pytorch/issues/150798). And there were several other similar leaks in PyTorch I discovered using this tool
  • Network accessline 1176
    which is very difficult to notice. This is typically performed by an `oom-kill` via [cgroups](https://docs.kernel.org/admin-guide/cgroup-v2.html). The `SIGKILL` is not trappable, so the program itself can't report anything - but the kernel 
  • Network accessline 1178
    footnote: Moreover in some situations, as in recent kubernetes implementations, the user gets kicked out from the job allocation, which makes it even more difficult to debug. [Kubernetes Silent Pod Killer](https://itnext.io/kubernetes-silen
  • Network accessline 1293
    [`cgmemtime`](https://github.com/gsauthof/cgmemtime) is a little gem of a C program that uses cgroups v2 to measure the peak CPU memory usage of a process and all of its descendants no matter how many generations follow it.
  • Network accessline 1297
    git clone https://github.com/gsauthof/cgmemtime
  • Network accessline 1694
    Until recently Python couldn't tell us the name of the variable that was passed to a function, hence we need to pass the variable name as a string. Since Python 3.14 there is a way to overcome this, using [template strings (t-strings)](http
  • Network accessline 1843
    There is also the [lovely-tensors](https://github.com/xl0/lovely-tensors/) library that is designed to automate the process of making the tensor dump more useful and provide shapes, statistics, nan/inf counts, tensor memory usage, etc.
  • Network accessline 1915
    See also [Numerical instabilities](https://github.com/stas00/ml-engineering/blob/master/training/instabilities/README.md#numerical-instabilities) in the training chapter, which covers training-level causes and remedies for `inf`/`nan` value
  • Network accessline 1921
    Let's use fp16 floating point representation for demonstrating how we end up with Infinity numbers. 65504 is the largest normal floating point number that can be represented in the fp16 precision. This is slightly below `2**16` due to how t
  • Network accessline 1930
    The first tensor is fine, but the last one overflows when I added `50` to it and we get `inf`. If you remember back in the day, models were trained in fp16 mixed precision regime and this `inf` happened a lot, thus a special scaler was used
  • Network accessline 1974
    As of `transformers==4.57.1` the above will give you `loss=tensor(nan)`. The issue here is that the special `-100` label masks tokens to be excluded from the loss calculation and in the above example, we have 0 tokens that aren't masked, si
  • Network accessline 1982
    You can see it in context [here](https://github.com/deepspeedai/DeepSpeed/blob/df59f203f40c8a292dd019ae68c9e6c88f107026/deepspeed/runtime/sequence_parallel/ulysses_sp.py#L1184-L1186). Though the code has evolved since then, and you can find
  • Network accessline 2092
    Let's match the report to the code from [`models/t5/modeling_t5.py`](https://github.com/huggingface/transformers/blob/main/src/transformers/models/t5/modeling_t5.py):
  • Network accessline 2223
    See also [Reproducibility](https://github.com/stas00/ml-engineering/blob/master/training/reproducibility/README.md#achieve-determinism-in-randomness-based-software) for achieving determinism across different software and hardware setups.
  • Network accessline 2259
    For example, see this [discussion](https://github.com/deepspeedai/DeepSpeed/issues/4932) - the users reported that when doing Llama-2-7b inference they were getting quite different logits depending on how the model was initialized. To clari
  • Network accessline 2265
    This snapshot and the commentary come from this [PyTorch Issue thread](https://github.com/pytorch/pytorch/issues/84936#issuecomment-1246084645).
  • Network accessline 2267
    If you're curious where I pulled this code from - this is a simplified reduction of this original code in [modeling_llama.py](https://github.com/huggingface/transformers/blob/3f69f415adcbdaedec154ba8eac220ef3276975d/src/transformers/models/
  • Network accessline 2283
    If you suspect a crash is caused by faulty hardware rather than your code, see also [Troubleshooting NVIDIA GPUs](https://github.com/stas00/ml-engineering/blob/master/compute/accelerator/nvidia/debug.md#errors-and-diagnostics).
  • Network accessline 2327
    In theory enabling this variable should make everything run really slow, but in reality it really depends on your software. We did the whole of BLOOM-176B training using `CUDA_LAUNCH_BLOCKING=1` with [`Megatron-DeepSpeed`](https://github.co
  • Network accessline 2331
    Note: [NCCL==2.14.3 coming with `pytorch==1.13` hangs](https://github.com/NVIDIA/nccl/issues/750) when `CUDA_LAUNCH_BLOCKING=1` is used. So don't use it with that version of pytorch. The issue has been fixed in `nccl>=2.17` which should be 
  • Network accessline 2503
    Primary reference: [NVIDIA Compute Sanitizer](https://docs.nvidia.com/compute-sanitizer/).
  • Network accessline 2524
    Reference: [NVIDIA cuda-gdb](https://docs.nvidia.com/cuda/cuda-gdb/).
  • Network accessline 2805
    - `PID` is the process id of the hanging python process. - `-n` is useful if you want to see stack traces from python extensions written in C, C++, etc., as the program may hang in one of the extensions - you may need to add `sudo` before t
  • Network accessline 2807
    - you may need to add `sudo` before the command - for more details see [this note](https://github.com/benfred/py-spy/blob/master/README.md#when-do-you-need-to-run-as-sudo).
  • Dangerous shell operationline 2811
    sudo echo 0 > /proc/sys/kernel/yama/ptrace_scope
  • Network accessline 2813
    which will allow you running `py-spy` (and `strace`) without needing `sudo`. Beware of the possible [security implications](https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection) - but typically if your compute node
  • Dangerous shell operationline 2817
    sudo sysctl -w kernel.yama.ptrace_scope=0
  • Dangerous shell operationline 2818
    sudo bash -c "echo 0 > /proc/sys/kernel/yama/ptrace_scope"
  • Dangerous shell operationline 3001
    PDSH_RCMD_TYPE=ssh pdsh -w nodename-[5,8] 'sudo bash -c "source ~/.pdshrc; pgrep -P $(pgrep -o python) | xargs -I {} py-spy dump --pid {}"'
  • Access to secretsline 3012
    [Credential-related source omitted]
  • Access to secretsline 3013
    [Credential-related source omitted]
  • Dangerous shell operationline 3040
    ds_ssh -f hostfile "source ~/.pdshrc; ps aux | grep python | grep -v grep | grep `whoami` | awk '{print \$2}' | xargs -I {} sudo py-spy dump --pid {} "
  • Network accessline 3148
    Primary reference: [ProcessGroupNCCL environment variables](https://docs.pytorch.org/docs/stable/torch_nccl_environment_variables.html).
  • Access to secretsline 3242
    [Credential-related source omitted]
  • Dangerous shell operationline 3391
    sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
  • Network accessline 3433
    See [Troubleshooting AMD GPUs](https://github.com/stas00/ml-engineering/blob/master/compute/accelerator/amd/debug.md#hangs-or-slow-multi-gpu-runs-and-iommu) in ML Engineering.
  • Network accessline 3437
    For diagnosing NCCL connectivity problems between GPUs and nodes (the layer below PyTorch), see also [How to diagnose NCCL multi-gpu and multi-node connectivity issues](https://github.com/stas00/ml-engineering/blob/master/network/debug/READ
  • Network accessline 3441
    Once you need to use more than one node to scale your training, e.g., if you want to use DDP to train faster, you have to get the nodes to talk to each other, so that communication collectives could send data to each other. This is typicall
  • Network accessline 3460
    telnet localhost:6000 nmap -p 6000 localhost nc -zv localhost 6000
  • Network accessline 3461
    nmap -p 6000 localhost nc -zv localhost 6000 curl -v telnet://localhost:6000
  • Network accessline 3462
    nc -zv localhost 6000
  • Network accessline 3463
    curl -v telnet://localhost:6000
  • Dangerous shell operationline 3508
    $ sudo ifconfig
  • Network accessline 3513
    Then there is the inter-node interface which can be InfiniBand, EFA, OPA, HPE Slingshot, etc. ([more information](https://github.com/stas00/ml-engineering/blob/master/network/README.md#inter-node-networking)). There could be one or dozens o
  • Dangerous shell operationline 3518
    $ sudo ifconfig
  • Dangerous shell operationline 3530
    $ sudo ifconfig
  • Network accessline 3535
    Here `ib` typically tells us it's an InfiniBand card, but really it can be any other vendor. I have seen [OmniPath](https://github.com/stas00/ml-engineering/blob/master/network/README.md#omni-path) using `ib` for example. Again `inet` tells
  • Network accessline 3604
    Another popular way is to use [Message Passing Interface (MPI)](https://en.wikipedia.org/wiki/Message_Passing_Interface). There are a few open source implementations of it available.
  • Network accessline 3657
    There could be a variety of reason for this failing, but of the most likely one is when you're on the cloud and the 2 nodes weren't provisioned so that their IB is connected. So your Ethernet inter-node connectivity works, but it's too slow
  • Network accessline 3796
    """     PDB Subclass for debugging multi-processed code     Suggested in: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
  • Network accessline 3797
    PDB Subclass for debugging multi-processed code     Suggested in: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess     """
  • Network accessline 3798
    Suggested in: https://stackoverflow.com/questions/4716533/how-to-attach-debugger-to-a-python-subproccess
  • Network accessline 3822
    `dist.breakpoint()` and `ForkedPdb` above both require you to plant the breakpoint in the source before the run. Python 3.14 adds the missing case: attaching to a process that is *already running* and that you did not prepare in advance, gi
  • Network accessline 3841
    Primary reference: [Python 3.14 pdb](https://docs.python.org/3.14/library/pdb.html).
  • Network accessline 3889
    [hyperfine](https://github.com/sharkdp/hyperfine) runs a given command multiple times and reports how long it took to run: the mean, the standard deviation, and the fastest and slowest run. It can also compare two or more commands and repor
  • Dangerous shell operationline 3893
    sudo apt-get install -y hyperfine
  • Dangerous shell operationline 3928
    $ hyperfine -p 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'python -c "import torch"'
  • Network accessline 3946
    What an import actually reads, and how to build a file system benchmark out of timings like these, is covered in [Usability perception IO benchmarks](https://github.com/stas00/ml-engineering/blob/master/storage/README.md#usability-perceptio
  • Network accessline 3984
    - `ht.hpu.Event(enable_timing)` - Intel Gaudi - `torch.xpu.Event(enable_timing)` - Intel dGPUs - Apple MPS has a different API, but we can emulate the same API as can seen in [mamf-finder.py](https://github.com/stas00/ml-engineering/blob/00
  • Network accessline 3986
    - Apple MPS has a different API, but we can emulate the same API as can seen in [mamf-finder.py](https://github.com/stas00/ml-engineering/blob/0099885db36a8f06556efe1faf552518852cb1e0/compute/accelerator/benchmarks/mamf-finder.py#L159).
  • Network accessline 3988
    Here are good practical examples of measuring time durations with the help of device events: - [mamf-finder](https://github.com/stas00/ml-engineering/blob/master/compute/accelerator/benchmarks/mamf-finder.py)
  • Network accessline 3989
    - [mamf-finder](https://github.com/stas00/ml-engineering/blob/master/compute/accelerator/benchmarks/mamf-finder.py)
  • Network accessline 3990
    - [torch-dist-bench](https://github.com/stas00/ml-engineering/blob/master/network/benchmarks/torch-dist-bench.py)
  • Network accessline 3992
    Here are some excellent articles going into deeper explanations and examples: - [How to Accurately Time CUDA Kernels in Pytorch](https://www.speechmatics.com/company/articles-and-news/timing-operations-in-pytorch)
  • Network accessline 3993
    - [How to Accurately Time CUDA Kernels in Pytorch](https://www.speechmatics.com/company/articles-and-news/timing-operations-in-pytorch)
  • Network accessline 4063
    For more options please refer to the [`torch.profiler` doc](https://docs.pytorch.org/docs/stable/profiler.html).
  • Network accessline 4065
    Additionally, here is [an excellent introduction to `torch.profiler` from the HuggingFace team](https://huggingface.co/blog/torch-profiler).
  • Network accessline 4075
    I assume you already have the correct version of torch installed, if not head [here](https://pytorch.org/get-started/locally/).
  • Network accessline 4157
    Now let's use it to profile 2 forward calls using [Liger Kernel](https://github.com/linkedin/Liger-Kernel):
  • Access to secretsline 4264
    [Credential-related source omitted]
  • Access to secretsline 4265
    [Credential-related source omitted]
  • Network accessline 4277
    footnote: since the culprit here was `torch.compile`, you could also have spotted the recompilation directly with `TORCH_LOGS=recompiles` (and `TORCH_LOGS=graph_breaks` for eager fallbacks); see [PyTorch compiler troubleshooting](https://do

pytorch/code/collective_mismatch.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/collective_mismatch_analyze.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/kernel_oob.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/kernel_oob_gdb.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/kernel_oob_prebuilt.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/kernel_race.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/code/see-mem-usage.py

  • Executable scriptline 1
    Executable file

pytorch/printflock.py

  • Executable scriptline 1
    Executable file

pytorch/tiny-scripts/c4-en-10k.py

  • Executable scriptline 1
    Executable file
  • Network accessline 6
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 7
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 8
    #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 38
    The full 1TB+ dataset is at https://huggingface.co/datasets/c4.
  • Network accessline 41
    _URL = "https://cdn-datasets.huggingface.co/nlp/datasets/c4/c4-en-10k.tar.xz"
  • Network accessline 56
    description=_DESCRIPTION,             features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://huggingface.co/datasets/allenai/c4/",
  • Network accessline 57
    features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://huggingface.co/datasets/allenai/c4/",             citation=_CITATION,
  • Network accessline 58
    homepage="https://huggingface.co/datasets/allenai/c4/",

pytorch/tiny-scripts/cm4-synthetic-testing.py

  • Executable scriptline 1
    Executable file
  • Dangerous shell operationline 7
    rm -rf data
  • Dangerous shell operationline 18
    # rm texts*
  • Network accessline 27
    # prep dataset repo https://huggingface.co/new-dataset => HuggingFaceM4/cm4-synthetic-testing
  • Network accessline 28
    https://huggingface.co/new-dataset => HuggingFaceM4/cm4-synthetic-testing
  • Network accessline 29
    git clone https://huggingface.co/datasets/HuggingFaceM4/cm4-synthetic-testing
  • Network accessline 70
    _DESCRIPTION = """This dataset is designed to be used in testing. It's derived from cm4-10k dataset""" _HOMEPAGE = "https://huggingface.co/datasets/HuggingFaceM4/cm4-synthetic-testing"
  • Network accessline 71
    _HOMEPAGE = "https://huggingface.co/datasets/HuggingFaceM4/cm4-synthetic-testing"
  • Network accessline 73
    _URL = "https://huggingface.co/datasets/HuggingFaceM4/cm4-synthetic-testing/resolve/main/data.tar.gz"

pytorch/tiny-scripts/fsmt-make-super-tiny-model.py

  • Executable scriptline 1
    #!/usr/bin/env python
  • Network accessline 7
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 8
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 9
    #     http://www.apache.org/licenses/LICENSE-2.0

pytorch/tiny-scripts/general-pmd-ds-unpack.py

  • Executable scriptline 1
    Executable file
  • Network accessline 50
    list2range('1,2,5-7,10')     [1, 2, 5, 6, 7, 10]     # from https://stackoverflow.com/a/6405711/9201239
  • Network accessline 51
    [1, 2, 5, 6, 7, 10]     # from https://stackoverflow.com/a/6405711/9201239     """
  • Network accessline 52
    # from https://stackoverflow.com/a/6405711/9201239

pytorch/tiny-scripts/general-pmd-synthetic-testing.py

  • Executable scriptline 1
    Executable file
  • Network accessline 6
    # prep dataset repo https://huggingface.co/new-dataset => HuggingFaceM4/general-pmd-synthetic-testing
  • Network accessline 7
    https://huggingface.co/new-dataset => HuggingFaceM4/general-pmd-synthetic-testing
  • Network accessline 8
    git clone https://huggingface.co/datasets/HuggingFaceM4/general-pmd-synthetic-testing
  • Dangerous shell operationline 12
    rm -rf data
  • Dangerous shell operationline 22
    rm image.jpg text.txt
  • Dangerous shell operationline 41
    rm -rf data
  • Network accessline 70
    _DESCRIPTION = """This dataset is designed to be used in testing. It's derived from general-pmd-10k dataset""" _HOMEPAGE = "https://huggingface.co/datasets/HuggingFaceM4/general-pmd-synthetic-testing"
  • Network accessline 71
    _HOMEPAGE = "https://huggingface.co/datasets/HuggingFaceM4/general-pmd-synthetic-testing"
  • Network accessline 73
    _URL = "https://huggingface.co/datasets/HuggingFaceM4/general-pmd-synthetic-testing/resolve/main/data.tar.gz"

pytorch/tiny-scripts/idefics-make-tiny-model.py

  • Executable scriptline 1
    #!/usr/bin/env python

pytorch/tiny-scripts/m4-ds-unpack.py

  • Executable scriptline 1
    Executable file
  • Network accessline 52
    list2range('1,2,5-7,10')     [1, 2, 5, 6, 7, 10]     # from https://stackoverflow.com/a/6405711/9201239
  • Network accessline 53
    [1, 2, 5, 6, 7, 10]     # from https://stackoverflow.com/a/6405711/9201239     """
  • Network accessline 54
    # from https://stackoverflow.com/a/6405711/9201239

pytorch/tiny-scripts/mt5-make-tiny-model.py

  • Executable scriptline 1
    #!/usr/bin/env python
  • Network accessline 7
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 8
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 9
    #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 22
    # To build: # 1. clone sentencepiece into this dir # git clone https://github.com/google/sentencepiece
  • Network accessline 23
    # 1. clone sentencepiece into this dir # git clone https://github.com/google/sentencepiece #
  • Network accessline 24
    # git clone https://github.com/google/sentencepiece
  • Network accessline 53
    # adapted from https://blog.ceshine.net/post/trim-down-sentencepiece-vocabulary/

pytorch/tiny-scripts/openwebtext-10k.py

  • Executable scriptline 1
    Executable file
  • Network accessline 6
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 7
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 8
    #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 27
    title={OpenWebText Corpus},   author={Aaron Gokaslan*, Vanya Cohen*, Ellie Pavlick, Stefanie Tellex},   howpublished{\\url{http://Skylion007.github.io/OpenWebTextCorpus}},
  • Network accessline 28
    author={Aaron Gokaslan*, Vanya Cohen*, Ellie Pavlick, Stefanie Tellex},   howpublished{\\url{http://Skylion007.github.io/OpenWebTextCorpus}},   year={2019}
  • Network accessline 29
    howpublished{\\url{http://Skylion007.github.io/OpenWebTextCorpus}},
  • Network accessline 39
    The full 8M-record dataset is at https://huggingface.co/datasets/openwebtext
  • Network accessline 42
    _URL = "https://cdn-datasets.huggingface.co/nlp/datasets/openwebtext/openwebtext-10k.tar.xz"
  • Network accessline 57
    description=_DESCRIPTION,             features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://skylion007.github.io/OpenWebTextCorpus/",
  • Network accessline 58
    features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://skylion007.github.io/OpenWebTextCorpus/",             citation=_CITATION,
  • Network accessline 59
    homepage="https://skylion007.github.io/OpenWebTextCorpus/",

pytorch/tiny-scripts/oscar-en-10k.py

  • Executable scriptline 1
    Executable file
  • Network accessline 6
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 7
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 8
    #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 31
    address   = {Mannheim},   doi       = {10.14618/ids-pub-9021},   url       = {http://nbn-resolving.de/urn:nbn:de:bsz:mh39-90215},
  • Network accessline 32
    doi       = {10.14618/ids-pub-9021},   url       = {http://nbn-resolving.de/urn:nbn:de:bsz:mh39-90215},   pages     = {9 -- 16},
  • Network accessline 33
    url       = {http://nbn-resolving.de/urn:nbn:de:bsz:mh39-90215},
  • Network accessline 44
    The full 1TB+ dataset is at https://huggingface.co/datasets/oscar.
  • Network accessline 47
    _URL = "https://cdn-datasets.huggingface.co/nlp/datasets/oscar/oscar-en-10k.tar.xz"
  • Network accessline 62
    description=_DESCRIPTION,             features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://oscar-corpus.com/",
  • Network accessline 63
    features=datasets.Features({"text": datasets.Value("string")}),             homepage="https://oscar-corpus.com/",             citation=_CITATION,
  • Network accessline 64
    homepage="https://oscar-corpus.com/",

pytorch/torch-distributed-gpu-test.py

  • Executable scriptline 1
    #!/usr/bin/env python
  • Access to secretsline 74
    [Credential-related source omitted]

pytorch/underflow_overflow.py

  • Executable scriptline 1
    Executable file
  • Network accessline 5
    # You may obtain a copy of the License at # #     http://www.apache.org/licenses/LICENSE-2.0
  • Network accessline 6
    # #     http://www.apache.org/licenses/LICENSE-2.0 #
  • Network accessline 7
    #     http://www.apache.org/licenses/LICENSE-2.0

unix/README.md

  • Network accessline 15
    If you use [`tmux`](https://github.com/tmux/tmux) `Ctrl-b->[` will enter scrollback mode, and vi/emacs (depending on your settings) keys can be used for search/scroll/etc.
  • Network accessline 44
    Anything that has to do with the current status is very helpful. If you work with git a lot and have to switch back and forth between different branches and forks. A tool like [bash-git-prompt](https://github.com/magicmonty/bash-git-prompt)
  • Network accessline 73
    cd ~ git clone https://github.com/magicmonty/bash-git-prompt ~/.bash-git-prompt --depth=1
  • Network accessline 74
    git clone https://github.com/magicmonty/bash-git-prompt ~/.bash-git-prompt --depth=1 cd ~/.bash-git-prompt/themes wget https://raw.githubusercontent.com/stas00/the-art-of-debugging/master/unix/bash-git-prompt/Stas.bgptheme
  • Network accessline 76
    wget https://raw.githubusercontent.com/stas00/the-art-of-debugging/master/unix/bash-git-prompt/Stas.bgptheme
  • Network accessline 238
    The possible exit codes are listed [here](https://tldp.org/LDP/abs/html/exitcodes.html). and `127` corresponds to "command not found" error - which is indeed the case here. Though most of the time the exit code will be `1`, which is a catch
  • Dangerous shell operationline 489
    $ sudo dmesg -T | grep -i "killed process"
  • Dangerous shell operationline 496
    sudo dmesg -l err,crit   # only errors and worse
  • Dangerous shell operationline 497
    sudo dmesg -w            # follow new messages, like tail -f
  • Network accessline 522
    `oom_group_kill` is a different axis: it counts the times the kernel took the whole cgroup down together instead of picking one victim, which it only does when `memory.oom.group` is set to 1. Kubernetes sets that by default, which is how on
  • Dangerous shell operationline 547
    $ sudo dmesg -T | grep -iE "oom-kill|out of memory" | tail -2
  • Dangerous shell operationline 556
    $ sudo mkdir /sys/fs/cgroup/oomtest
  • Dangerous shell operationline 557
    $ echo 50M | sudo tee /sys/fs/cgroup/oomtest/memory.max
  • Dangerous shell operationline 559
    $ echo 0 | sudo tee /sys/fs/cgroup/oomtest/memory.swap.max
  • Dangerous shell operationline 561
    $ sudo bash -c 'echo $$ > /sys/fs/cgroup/oomtest/cgroup.procs; exec python3 -c "bytearray(300*2**20)"'
  • Dangerous shell operationline 572
    $ sudo rmdir /sys/fs/cgroup/oomtest
  • Network accessline 578
    If you're chasing a GPU fault, the NVIDIA driver logs `Xid` errors here too - see [Xid Errors](https://github.com/stas00/ml-engineering/blob/master/compute/accelerator/nvidia/debug.md#xid-errors) in the companion book for how to read them.
  • Network accessline 604
    In order that we have something to work with, let's take the `Makefile` from [ipyexperiments](https://github.com/stas00/ipyexperiments):
  • Network accessline 606
    git clone https://github.com/stas00/ipyexperiments
  • Network accessline 647
    This is probably the least interesting section of this guide, but it is what it is. For more information please see [GNU make](https://www.gnu.org/software/make/manual/make.html).

unix/bash-git-prompt/Stas.bgptheme

  • Network accessline 12
    # symbols: https://unicodelookup.com/#circle/1

How the signals fit together

Facts from a static read of the files at the pinned commit. They describe what the code does, not why.

Some files could not be read; the facts below still hold.

Signal confidence: 14 facts
  • Network access in prose of the SKILL.mdSKILL.md:19Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:26Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:33Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:34Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:46Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:53Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:55Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:85Low confidence
  • Dangerous shell operation in code of the SKILL.mdSKILL.md:94High confidence
  • Network access in prose of the SKILL.mdSKILL.md:110Low confidence
  • Dangerous shell operation in code of the SKILL.mdSKILL.md:113High confidence
  • Network access in prose of the SKILL.mdSKILL.md:140Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:203Low confidence
  • Network access in prose of the SKILL.mdSKILL.md:204Low confidence

Works with

Agent compatibility, from the files in this repository
AgentStatusEvidenceInstall to
Claude CodeCompatibleStandard SKILL.md SKILL.md.claude/skills/<skill-name>/
CodexCompatibleStandard SKILL.md SKILL.md.agents/skills/<skill-name>/
CursorCompatibleStandard SKILL.md SKILL.md.cursor/skills/<skill-name>/
Gemini CLICompatibleStandard SKILL.md SKILL.md.gemini/skills/<skill-name>/
GitHub CopilotCompatibleStandard SKILL.md SKILL.md.github/skills/<skill-name>/
OpenCodeCompatibleStandard SKILL.md SKILL.md.opencode/skills/<skill-name>/
  • Native The repository ships a manifest, folder or frontmatter field for this agent.
  • Compatible A standard SKILL.md that this agent can read.
  • Unknown No evidence either way.

Derived automatically from paths, manifests and frontmatter. Not tested on each agent.

Add this badge to your README

It updates every night and links to this page.

stas00/the-art-of-debugging: #596 on hotskills, 1.7k stars

[![stas00/the-art-of-debugging on hotskills](https://hotskills.dev/badge/stas00-the-art-of-debugging.svg)](https://hotskills.dev/skill/stas00-the-art-of-debugging/)