[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EVKHBHARNHTHADGS08CW30":3,"skill-same:01M7EVKHBHARNHTHADGS08CW30":47},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":28,"repositoryHtmlUrl":29,"repositoryHomepageUrl":6,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M7EVKHBHARNHTHADGS08CW30","pytorch-pro",null,"PyTorch guidance — tensors, autograd, training loops, DataLoader, distributed training, and production inference.","TanNhatCMS\u002Fjarvis","TanNhatCMS","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F113796420?v=4","01M753MV17KG5CD3152G3WQEQY","KietNT","01M7EKEDYVYQ6PWVJJMZ911VMX",0,"MIT","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-pytorch-pro\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: pytorch-pro\ndescription: PyTorch guidance — tensors, autograd, training loops, DataLoader, distributed training, and production inference.\ncategory: development\n---\n\n## Overview\n\nPyTorch is the dominant framework for deep learning research and increasingly for production: dynamic computation graphs, Pythonic APIs, and an ecosystem (torchvision, torchaudio, Hugging Face, Lightning) that covers most use cases. Its imperative style makes debugging intuitive — you can print tensors mid-forward-pass like any Python code.\n\nThis skill covers the PyTorch fundamentals that transfer everywhere: tensors and autograd, correct training loops, efficient data loading, distributed training, and the path to production inference (TorchScript, ONNX, TensorRT, torch.compile).\n\n## When to use\n\n- Building or debugging PyTorch models.\n- Writing correct training loops (train\u002Feval modes, gradient handling).\n- Optimizing data loading (DataLoader bottlenecks).\n- Training on multiple GPUs (DDP).\n- Exporting models for production inference.\n- Choosing between PyTorch, TensorFlow, and JAX.\n\n## Core concepts\n\n- **Tensors.** The core data structure: `torch.tensor`, shapes\u002Fdtypes\u002Fdevices. Think in shapes — most bugs are shape mismatches; print shapes liberally while developing. `device` discipline (`.to(device)`) avoids CPU\u002FGPU mixing errors.\n- **Autograd.** Automatic differentiation: operations on `requires_grad=True` tensors build a graph; `loss.backward()` computes gradients. `torch.no_grad()` for inference (saves memory, disables graph); `detach()` to cut graph edges.\n- **nn.Module.** The building block: `__init__` defines layers, `forward` defines computation. `model.train()` vs `model.eval()` — dropout\u002FBatchNorm behave differently; forgetting `eval()` at inference is a classic silent bug.\n- **Training loop anatomy.** Zero grads → forward → loss → backward → optimizer step. `optimizer.zero_grad()` placement matters (gradients accumulate by default — a feature for accumulation, a bug when forgotten).\n- **DataLoader.** `Dataset` + `DataLoader`: `num_workers` for parallel loading, `pin_memory` for GPU transfer speed, custom `collate_fn` for variable-length data. Data loading is the usual bottleneck — profile it (`nvidia-smi` showing idle GPU = starved pipeline).\n- **Losses and optimizers.** CrossEntropyLoss (classification), MSE\u002FBCE variants; Adam\u002FAdamW defaults, SGD with momentum for some vision tasks; learning-rate schedulers (cosine, OneCycle, ReduceLROnPlateau). AdamW + cosine is the strong default.\n- **Mixed precision.** `torch.cuda.amp` (autocast + GradScaler): ~2x speedup, half memory, with loss scaling for stability. Nearly free performance — use it unless you have a reason not to.\n- **Gradient clipping\u002Faccumulation.** Clip (`clip_grad_norm_`) for RNNs\u002Ftransformers stability; accumulation (`loss \u002F k`, step every k batches) for effective large batches on limited VRAM.\n- **Checkpointing.** Save `model.state_dict()` + `optimizer.state_dict()` + epoch + scheduler + RNG states — resumable training needs all of these, not just weights. Save best + latest.\n- **Distributed (DDP).** `DistributedDataParallel` — one process per GPU, gradients averaged. `torchrun` launcher; `DistributedSampler` for the DataLoader; sync BatchNorm where needed. DDP (not DataParallel) is the correct multi-GPU approach.\n- **torch.compile.** The 2.0+ compiler: often 30%+ speedup with one line (`torch.compile(model)`). Graph breaks from data-dependent control flow reduce gains — write compile-friendly code (avoid Python branching on tensor values in hot paths).\n- **Inference optimization.** `model.eval()` + `torch.no_grad()`\u002F`inference_mode()`; export paths: TorchScript (C++ runtime), ONNX (cross-framework), TensorRT (NVIDIA GPUs, max perf), quantization (INT8 for CPU\u002Flatency). Choose by deployment target.\n- **Debugging.** NaN hunting (check loss per batch, `torch.autograd.set_detect_anomaly(True)` for the guilty op), shape printing, overfitting a single batch as a smoke test (if it can't overfit 10 samples, something's broken).\n- **Ecosystem.** torchvision\u002Ftorchaudio\u002Fhuggingface for pretrained models; PyTorch Lightning for training-loop structure; `torchmetrics` for correct metric computation.\n\n## Practical workflow\n\n1. **Write the correct loop.** Train\u002Feval modes, zero grads, no-grad inference — the template:\n   ```python\n   for epoch in range(epochs):\n       model.train()\n       for x, y in train_loader:\n           x, y = x.to(device), y.to(device)\n           optimizer.zero_grad()\n           with torch.autocast(device_type=\"cuda\", dtype=torch.float16):\n               loss = criterion(model(x), y)\n           scaler.scale(loss).backward()\n           scaler.unscale_(optimizer)\n           torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)\n           scaler.step(optimizer); scaler.update()\n       # validation\n       model.eval()\n       with torch.inference_mode():\n           val_loss = sum(criterion(model(x.to(device)), y.to(device))\n                          for x, y in val_loader) \u002F len(val_loader)\n   ```\n2. **Smoke-test first.** Overfit a single batch — if loss doesn't → ~0, debug before full training (LR, data, labels, architecture).\n3. **Fix data loading.** `num_workers=4+`, `pin_memory=True`, profile GPU utilization; move preprocessing (tokenization, augmentation) into the pipeline, not the training step.\n4. **Scale with DDP.** `torchrun --nproc_per_node=4 train.py`; DDP wrap; DistributedSampler; scale LR with batch size (linear scaling rule as starting point).\n5. **Checkpoint completely.** state_dicts for model+optimizer+scheduler, epoch, RNG states; save best-by-val and latest; test resume once.\n6. **Compile and export.** `torch.compile` for training\u002Finference speed; export to ONNX\u002FTensorRT\u002Fquantized for deployment targets; benchmark latency\u002Fthroughput per export.\n7. **Monitor training.** Loss curves, LR schedule, gradient norms, GPU util\u002Fmemory — W&B\u002FMLflow from run one. Diverging loss? Check LR, data normalization, and label correctness first.\n8. **Serve efficiently.** Batch inference requests, `inference_mode()`, right-sized instances; the deployment format (ONNX\u002FTensorRT) chosen by latency requirements.\n\n## Common pitfalls\n\n- **Forgetting `model.eval()`** — dropout\u002FBatchNorm active at inference; silent quality drop.\n- **Forgetting `zero_grad()`** — gradients accumulating unintentionally; loss behaves strangely.\n- **No `torch.no_grad()` at inference** — graph building wasting memory; `inference_mode()` is stricter.\n- **DataLoader bottleneck** — GPU idle; `num_workers`, `pin_memory`, pipeline preprocessing.\n- **Using DataParallel** — deprecated, slower; DDP with `torchrun`.\n- **NaNs unchecked** — training diverging silently; anomaly detection + per-batch loss logging.\n- **Wrong device mixing** — CPU tensor + CUDA tensor errors; consistent `.to(device)`.\n- **Saving whole model instead of state_dict** — pickle fragility; `state_dict` + architecture code.\n- **Incomplete checkpoints** — weights only, can't resume optimizer\u002Fscheduler; save everything.\n- **LR not scaled with batch size** — DDP batch growth without LR adjustment; linear scaling starting point.\n- **Compile-unfriendly code** — data-dependent Python branching killing `torch.compile` gains; restructure hot paths.\n- **No smoke test** — full training on a broken setup; overfit-one-batch first.\n- **Metric bugs** — wrong averaging across batches; `torchmetrics` or careful accumulation.\n","## Overview\n\nPyTorch is the dominant framework for deep learning research and increasingly for production: dynamic computation graphs, Pythonic APIs, and an ecosystem (torchvision, torchaudio, Hugging Face, Lightning) that covers most use cases. Its imperative style makes debugging intuitive — you can print tensors mid-forward-pass like any Python code.\n\nThis skill covers the PyTorch fundamentals that transfer everywhere: tensors and autograd, correct training loops, efficient data loading, distributed training, and the path to production inference (TorchScript, ONNX, TensorRT, torch.compile).\n\n## When to use\n\n- Building or debugging PyTorch models.\n- Writing correct training loops (train\u002Feval modes, gradient handling).\n- Optimizing data loading (DataLoader bottlenecks).\n- Training on multiple GPUs (DDP).\n- Exporting models for production inference.\n- Choosing between PyTorch, TensorFlow, and JAX.\n\n## Core concepts\n\n- **Tensors.** The core data structure: `torch.tensor`, shapes\u002Fdtypes\u002Fdevices. Think in shapes — most bugs are shape mismatches; print shapes liberally while developing. `device` discipline (`.to(device)`) avoids CPU\u002FGPU mixing errors.\n- **Autograd.** Automatic differentiation: operations on `requires_grad=True` tensors build a graph; `loss.backward()` computes gradients. `torch.no_grad()` for inference (saves memory, disables graph); `detach()` to cut graph edges.\n- **nn.Module.** The building block: `__init__` defines layers, `forward` defines computation. `model.train()` vs `model.eval()` — dropout\u002FBatchNorm behave differently; forgetting `eval()` at inference is a classic silent bug.\n- **Training loop anatomy.** Zero grads → forward → loss → backward → optimizer step. `optimizer.zero_grad()` placement matters (gradients accumulate by default — a feature for accumulation, a bug when forgotten).\n- **DataLoader.** `Dataset` + `DataLoader`: `num_workers` for parallel loading, `pin_memory` for GPU transfer speed, custom `collate_fn` for variable-length data. Data loading is the usual bottleneck — profile it (`nvidia-smi` showing idle GPU = starved pipeline).\n- **Losses and optimizers.** CrossEntropyLoss (classification), MSE\u002FBCE variants; Adam\u002FAdamW defaults, SGD with momentum for some vision tasks; learning-rate schedulers (cosine, OneCycle, ReduceLROnPlateau). AdamW + cosine is the strong default.\n- **Mixed precision.** `torch.cuda.amp` (autocast + GradScaler): ~2x speedup, half memory, with loss scaling for stability. Nearly free performance — use it unless you have a reason not to.\n- **Gradient clipping\u002Faccumulation.** Clip (`clip_grad_norm_`) for RNNs\u002Ftransformers stability; accumulation (`loss \u002F k`, step every k batches) for effective large batches on limited VRAM.\n- **Checkpointing.** Save `model.state_dict()` + `optimizer.state_dict()` + epoch + scheduler + RNG states — resumable training needs all of these, not just weights. Save best + latest.\n- **Distributed (DDP).** `DistributedDataParallel` — one process per GPU, gradients averaged. `torchrun` launcher; `DistributedSampler` for the DataLoader; sync BatchNorm where needed. DDP (not DataParallel) is the correct multi-GPU approach.\n- **torch.compile.** The 2.0+ compiler: often 30%+ speedup with one line (`torch.compile(model)`). Graph breaks from data-dependent control flow reduce gains — write compile-friendly code (avoid Python branching on tensor values in hot paths).\n- **Inference optimization.** `model.eval()` + `torch.no_grad()`\u002F`inference_mode()`; export paths: TorchScript (C++ runtime), ONNX (cross-framework), TensorRT (NVIDIA GPUs, max perf), quantization (INT8 for CPU\u002Flatency). Choose by deployment target.\n- **Debugging.** NaN hunting (check loss per batch, `torch.autograd.set_detect_anomaly(True)` for the guilty op), shape printing, overfitting a single batch as a smoke test (if it can't overfit 10 samples, something's broken).\n- **Ecosystem.** torchvision\u002Ftorchaudio\u002Fhuggingface for pretrained models; PyTorch Lightning for training-loop structure; `torchmetrics` for correct metric computation.\n\n## Practical workflow\n\n1. **Write the correct loop.** Train\u002Feval modes, zero grads, no-grad inference — the template:\n   ```python\n   for epoch in range(epochs):\n       model.train()\n       for x, y in train_loader:\n           x, y = x.to(device), y.to(device)\n           optimizer.zero_grad()\n           with torch.autocast(device_type=\"cuda\", dtype=torch.float16):\n               loss = criterion(model(x), y)\n           scaler.scale(loss).backward()\n           scaler.unscale_(optimizer)\n           torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0)\n           scaler.step(optimizer); scaler.update()\n       # validation\n       model.eval()\n       with torch.inference_mode():\n           val_loss = sum(criterion(model(x.to(device)), y.to(device))\n                          for x, y in val_loader) \u002F len(val_loader)\n   ```\n2. **Smoke-test first.** Overfit a single batch — if loss doesn't → ~0, debug before full training (LR, data, labels, architecture).\n3. **Fix data loading.** `num_workers=4+`, `pin_memory=True`, profile GPU utilization; move preprocessing (tokenization, augmentation) into the pipeline, not the training step.\n4. **Scale with DDP.** `torchrun --nproc_per_node=4 train.py`; DDP wrap; DistributedSampler; scale LR with batch size (linear scaling rule as starting point).\n5. **Checkpoint completely.** state_dicts for model+optimizer+scheduler, epoch, RNG states; save best-by-val and latest; test resume once.\n6. **Compile and export.** `torch.compile` for training\u002Finference speed; export to ONNX\u002FTensorRT\u002Fquantized for deployment targets; benchmark latency\u002Fthroughput per export.\n7. **Monitor training.** Loss curves, LR schedule, gradient norms, GPU util\u002Fmemory — W&B\u002FMLflow from run one. Diverging loss? Check LR, data normalization, and label correctness first.\n8. **Serve efficiently.** Batch inference requests, `inference_mode()`, right-sized instances; the deployment format (ONNX\u002FTensorRT) chosen by latency requirements.\n\n## Common pitfalls\n\n- **Forgetting `model.eval()`** — dropout\u002FBatchNorm active at inference; silent quality drop.\n- **Forgetting `zero_grad()`** — gradients accumulating unintentionally; loss behaves strangely.\n- **No `torch.no_grad()` at inference** — graph building wasting memory; `inference_mode()` is stricter.\n- **DataLoader bottleneck** — GPU idle; `num_workers`, `pin_memory`, pipeline preprocessing.\n- **Using DataParallel** — deprecated, slower; DDP with `torchrun`.\n- **NaNs unchecked** — training diverging silently; anomaly detection + per-batch loss logging.\n- **Wrong device mixing** — CPU tensor + CUDA tensor errors; consistent `.to(device)`.\n- **Saving whole model instead of state_dict** — pickle fragility; `state_dict` + architecture code.\n- **Incomplete checkpoints** — weights only, can't resume optimizer\u002Fscheduler; save everything.\n- **LR not scaled with batch size** — DDP batch growth without LR adjustment; linear scaling starting point.\n- **Compile-unfriendly code** — data-dependent Python branching killing `torch.compile` gains; restructure hot paths.\n- **No smoke test** — full training on a broken setup; overfit-one-batch first.\n- **Metric bugs** — wrong averaging across batches; `torchmetrics` or careful accumulation.\n",{"name":5,"category":24,"description":7},"development","main","af388a77c2fe5e0b4fd879cca4300a0ffa9a6579","skills\u002Fams-pytorch-pro",1,"https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis","https:\u002F\u002Fgithub.com\u002FTanNhatCMS","https:\u002F\u002Fmrkiet.name.vn","2026-11-07 14:23:08",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add TanNhatCMS\u002Fjarvis --skill pytorch-pro",{"tool":39,"command":40},"bunx","bunx skills add TanNhatCMS\u002Fjarvis --skill pytorch-pro",{"tool":42,"command":43},"pnpm","pnpm dlx skills add TanNhatCMS\u002Fjarvis --skill pytorch-pro","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fams-pytorch-pro\u002FSKILL.md",true,[],[48,55,63,70,77,84],{"skillNo":49,"name":50,"nameZh":6,"description":51,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":52,"categories":53,"keywords":54,"publishedAt":19},"01M7EWYJR0J8DARY7E59Z6Y9MV","web-scrape","Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open\u002Ffetch fails on JS-heavy pages, or when you need clean markdown\u002Fstructured extraction from a site. Requires FIRECRAWL_API_KEY.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fweb-scrape\u002FSKILL.md",[],[],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":59,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M7EWYBN5P6F2AJG3FR24T9BP","design-taste-frontend","tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML\u002FCSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, \"AI-made\", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Ftaste-design\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M7EWY8FQFNQ2GB7NZZWGSSDX","test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-tdd\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M7EWY5SHBFRH1HDHVWM9K7TV","systematic-debugging","Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-debugging\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M7EWY3NM0Z0JAKS7HDZ24K66","requesting-code-review","Use when completing tasks, implementing major features, or before merging to verify work meets requirements","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-code-review\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M7EWY0WRMWX4M9ZFY0WKC593","brainstorming","You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).","https:\u002F\u002Fgithub.com\u002FTanNhatCMS\u002Fjarvis\u002Fblob\u002Fmain\u002Fskills\u002Fsuperpowers-brainstorming\u002FSKILL.md",[],[]]