Leanpub Header

Skip to main content

Local AI on RTX Spark Laptops

A Hands-On WSL2 Laboratory for Inference, Training, and Deployment, CUDA Programming, GPU Diagnostics, Observability, and Debugging with Complete Exercise Transcripts

Local AI on RTX Spark Laptops
This book is 99% completeLast updated on 2026-10-31

A local model returns the expected answer. How do we know which layers ran on the GPU? In Local AI on RTX Spark Laptops, we investigate questions like this through 251 hands-on WSL2 exercises, following the evidence from model-loader logs down to individual CUDA kernels.

Minimum price

$25.00

$25.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
824
Pages
About

About

About the Book

On a 64 GB RTX Spark laptop, the WSL2 guest reports 15.70 GiB of RAM. Can a process inside that guest allocate and use 18 GiB of CUDA memory? We answer by allocating eighteen tensors, writing to every byte, and checking the values while all eighteen tensors are still live.

In Local AI on RTX Spark Laptops, we take the same approach to inference, training, and deployment. When a model is too large to fit entirely on the GPU, we read the loader log to find which layers stayed on the host. When a fine-tuned checkpoint reloads successfully but produces different continuations, we compare logits and generated tokens. When CUDA arithmetic passes but the profiler records no usable GPU timestamps, we reduce the workload to a small reproducer.

The 251 hands-on exercises extend from writing CUDA kernels to training embedding models, investigating multimodal output, building diagnostic agents, and serving models with Docker and Kubernetes. The book includes 483 recorded command transcripts. The GitHub companion supplies the programs, fixtures, and checkpoints for repeating the investigations and comparing your observations with ours.

Author

About the Author

Dmitry Vostokov

Dmitry Vostokov is an internationally recognized expert, speaker, educator, scientist, inventor, and author. He founded the pattern-oriented software diagnostics, forensics, and prognostics discipline (Systematic Software Diagnostics) and Software Diagnostics Institute. Vostokov has also authored over 50 books on software diagnostics, anomaly detection and analysis, software and memory forensics, root cause analysis and problem solving, memory dump analysis, debugging, software trace and log analysis, reverse engineering, and malware analysis. He has over 30 years of experience in software architecture, design, development, and maintenance in various industries, including leadership, technical, and people management roles. Dmitry founded OpenTask Iterative and Incremental Publishing and Software Diagnostics Technology and Services (former Memory Dump Analysis Services). In his spare time, he explores Software Narratology and Quantum Software Diagnostics. His interest areas are theoretical software diagnostics and its mathematical and computer science foundations, application of formal logic, semiotics, artificial intelligence, machine learning, and data mining to diagnostics and anomaly detection, software diagnostics engineering and diagnostics-driven development, diagnostics workflow and interaction. Recent interest areas also include functional programming, cloud native computing, monitoring, observability, visualization, security, automation, applications of category theory to software diagnostics, development and big data, and diagnostics of artificial intelligence.

The Leanpub Podcast

Podcast

Podcast Episode

Contents

Table of Contents

Contents

Preface (p. 9)

First experiments (p. 11)

Why we chose WSL2 (p. 14)

1. The laptop as an observable system (p. 16)

2. Establishing the WSL2 baseline (p. 19)

3. Accounting for 64 GB of unified memory (p. 23)

4. Preparing a reproducible laboratory (p. 27)

5. Installing the pinned Linux runtime and model (p. 30)

6. Loading a model and proving the execution path (p. 34)

7. Asking a diagnostic question (p. 39)

8. Measuring latency and throughput (p. 43)

9. Context as a controlled resource (p. 50)

10. Quantization and model selection (p. 56)

11. Placement and memory pressure (p. 62)

12. Diagnosing failures by their first failed boundary (p. 68)

13. Testing a CUDA kernel with Python (p. 74)

14. Grounding answers in local evidence (p. 82)

15. A bounded diagnostic agent (p. 87)

16. Letting the local model choose actions (p. 91)

17. Concurrency and the memory cost of agents (p. 98)

18. Offline operation and a repeatable working practice (p. 102)

19. Diagnostic patterns for local models (p. 106)

20. Extending the laboratory (p. 108)

21. Fine-tuning within the observed memory budget (p. 109)

22. Preparing data and training a LoRA adapter (p. 111)

23. Evaluating, retaining, and deploying the adapter (p. 116)

24. Models that do not fit entirely on the GPU (p. 121)

25. Running beyond the GPU budget and diagnosing paging (p. 125)

26. Studying the CUDA ecosystem through evidence (p. 139)

27. Building and examining a small CUDA program (p. 144)

28. Capturing and interpreting GPU memory contents (p. 149)

29. Live device inspection and exception core dumps (p. 152)

30. Finding CUDA memory and synchronization errors (p. 157)

31. Collecting and reading CUDA execution traces (p. 162)

32. Studying individual kernels with Nsight Compute (p. 167)

33. Framework memory evidence and a model tracing capstone (p. 170)

34. Writing and validating a first CUDA kernel (p. 175)

35. Writing kernels for matrix layout and shared memory (p. 180)

36. Reductions and atomic updates (p. 184)

37. Writing a tiled matrix multiplication (p. 189)

38. Measuring kernel changes and writing a fused operation (p. 194)

39. Writing normalization kernels for model workloads (p. 199)

40. Integrating a CUDA kernel with PyTorch (p. 204)

41. Building and diagnosing a small transformer block (p. 210)

42. Warp programming and Tensor Core operations (p. 215)

43. Streams events and CUDA Graphs (p. 220)

44. Writing a teaching INT4 representation (p. 226)

45. Diagnosing training gradients memory and recovery (p. 230)

46. A CUDA diagnostic casebook (p. 234)

47. Agent assisted GPU diagnosis (p. 239)

48. Inspecting PTX, SASS, and device registers (p. 244)

49. Sentence embeddings and masked pooling (p. 248)

50. Retrieval data and evaluation (p. 255)

51. Inspecting embeddings with PCA (p. 259)

52. Comparing t-SNE and UMAP (p. 263)

53. Training a custom BERT model (p. 268)

54. Continuing pretraining and building sentence encoders (p. 273)

55. Fine tuning embedding models (p. 278)

56. Diagnosing and deploying embedding workloads (p. 283)

57. Monitoring GPU metrics and visualizing activity (p. 288)

58. Locating numerical divergence (p. 311)

59. Diagnosing compiled model execution (p. 316)

60. Diagnosing GPU starvation and input pipelines (p. 323)

61. Reasoning with roofline models (p. 328)

62. Diagnosing memory growth across requests (p. 332)

63. Diagnosing stalled progress (p. 337)

64. Tracing complete AI requests (p. 341)

65. Diagnosing model quality regressions (p. 345)

66. Reducing failures and isolating regressions (p. 349)

67. Debugging the observations themselves (p. 352)

68. A diagnostic pattern catalog (p. 356)

69. Blind diagnostic investigations (p. 362)

70. Distributed training on one laptop (p. 367)

71. Sharing one GPU among workers (p. 383)

72. Inference services and request diagnostics (p. 397)

73. Docker deployment inside WSL2 (p. 405)

74. Kubernetes deployment and GPU scheduling (p. 416)

75. vLLM and NVIDIA Triton Inference Server (p. 424)

76. RAPIDS data pipelines and GPU memory (p. 441)

77. ONNX export providers and fallback diagnostics (p. 451)

78. TensorRT engines profiles and execution traces (p. 458)

79. Quantization calibration and quality diagnosis (p. 469)

80. NeMo fine tuning recovery and deployment handoff (p. 479)

81. Images audio and multimodal evidence (p. 504)

82. Vision language inference and visual grounding (p. 513)

83. Diffusion models through a small executable experiment (p. 525)

84. Image generation memory and denoising traces (p. 533)

85. Music generation and audio token diagnostics (p. 550)

86. Text to speech as a reproducible signal pipeline (p. 559)

87. Speech recognition and transcript reliability (p. 571)

88. Adapting and serving multimodal pipelines (p. 582)

89. The NGC catalog as a source of reproducible GPU assets (p. 601)

90. The Hugging Face Hub as a source of models and datasets (p. 616)

91. Prometheus and Grafana for GPU observability (p. 627)

92. LangChain agents and local model adapters (p. 657)

93. LangGraph state, interrupts and recovery (p. 666)

94. LangSmith traces and evaluation (p. 673)

95. PydanticAI typed outputs and retry diagnosis (p. 679)

96. Jev decision models and calibrated routing (p. 684)

97. Ollama as a local model owner (p. 692)

98. Unsloth adaptation with measurable training boundaries (p. 705)

99. LM Studio inside WSL2 with a headless service (p. 722)

100. Nemotron models beyond the GPU weight budget (p. 733)

Advanced memory investigation (p. 750)

Appendix A. Exercise map and expected evidence (p. 771)

Appendix B. Companion programs and their contracts (p. 790)

Appendix C. Glossary (p. 802)

Appendix D. References (p. 810)

Appendix E. Validation and reproduction boundaries (p. 822)

Appendix F. Measurements from the example laptop (p. 824)

Appendix G. Learning paths and completion criteria (p. 850)

Appendix H. Subject index (p. 855)

Appendix I. Troubleshooting by symptom (p. 858)

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

Also by the Author

Also by the Author

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub