feat(skills): add pytorch-patterns skill#550
feat(skills): add pytorch-patterns skill#550code-with-idrees wants to merge 1 commit intoaffaan-m:mainfrom
Conversation
📝 WalkthroughWalkthroughA new documentation file detailing PyTorch development patterns has been added to the skills directory. It covers core design principles, model architecture, training loops, data pipelines, checkpointing, performance optimizations, and practical idioms with code examples and anti-patterns. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can use oxc to improve the quality of JavaScript and TypeScript code reviews.Add a configuration file to your project to customize how CodeRabbit runs oxc. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@skills/pytorch-patterns/SKILL.md`:
- Around line 11-17: Rename the "When to Activate" heading to "When to Use" and
add a new "How It Works" section that briefly describes the skill's approach to
common PyTorch patterns (e.g., model/module structuring, training loop flow,
optimizer/scheduler handling, device/GPU management, and reproducibility
mechanisms), then reorganize the existing examples under a clearly labeled
"Examples" section (group snippets into labeled sub-examples if needed). Locate
and update the headings in SKILL.md (the current "When to Activate" block),
insert the "How It Works" explanatory paragraph between "When to Use" and
"Examples", and move or relabel the code snippets so they appear under the
"Examples" header for clarity.
- Line 284: The use of weights_only=True in the torch.load call (checkpoint =
torch.load(path, map_location="cpu", weights_only=True")) requires PyTorch 2.0+;
update the documentation to explicitly state this version requirement (either
add a Prerequisites bullet or an inline comment near the torch.load line)
similar to the existing note for torch.compile so users running PyTorch < 2.0
won't hit a TypeError.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 27ba21bd-bdbc-49ae-92a9-7bc584788899
📒 Files selected for processing (1)
skills/pytorch-patterns/SKILL.md
Greptile SummaryThis PR adds a new Three issues were found:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Training Script] --> B{scaler is not None?}
B -- Yes AMP enabled --> C["torch.amp.autocast(device.type)"]
B -- No FP32 --> D[Standard forward pass]
C --> E[model forward + loss]
D --> E
E --> F{AMP enabled?}
F -- Yes --> G["scaler.scale(loss).backward()"]
F -- No --> H["loss.backward()"]
G --> I["scaler.unscale_(optimizer)"]
I --> J["clip_grad_norm_()"]
J --> K["scaler.step(optimizer)"]
K --> L["scaler.update()"]
H --> M["clip_grad_norm_()"]
M --> N["optimizer.step()"]
L --> O["optimizer.zero_grad(set_to_none=True)"]
N --> O
O --> P[Accumulate loss]
P --> Q{More batches?}
Q -- Yes --> E
Q -- No --> R[Return avg loss]
Last reviewed commit: 958c81e |
There was a problem hiding this comment.
5 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="skills/pytorch-patterns/SKILL.md">
<violation number="1" location="skills/pytorch-patterns/SKILL.md:41">
P1: The doc claims a “Full reproducibility setup” but omits multi-worker DataLoader seeding guidance (`worker_init_fn`/`generator`), making reproducibility incomplete for the recommended `num_workers=4` pattern.</violation>
<violation number="2" location="skills/pytorch-patterns/SKILL.md:48">
P2: If this helper is presented as a full reproducibility setup, also enable deterministic algorithms; CuDNN flags alone can still allow non-deterministic kernels and lead to run-to-run differences.</violation>
<violation number="3" location="skills/pytorch-patterns/SKILL.md:152">
P2: AMP examples hardcode CUDA (`"cuda"`) even though the skill presents the surrounding training patterns as device-agnostic, leading to inconsistent/non-portable guidance.</violation>
<violation number="4" location="skills/pytorch-patterns/SKILL.md:222">
P2: Dataset example advertises `torch.Tensor` output but can return a PIL image when `transform` is `None`, violating its own type contract.</violation>
<violation number="5" location="skills/pytorch-patterns/SKILL.md:264">
P2: Checkpoint example overclaims "all training state" while only persisting model/optimizer/epoch/loss, which can mislead users into incomplete resume behavior.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Summary
Adds a comprehensive
pytorch-patternsskill covering best practices for PyTorch development.Includes device-agnostic code, reproducibility, model patterns, training loop setups (with AMP constraints), DataLoader best practices, caching gradients, and common anti-patterns.
This serves as the knowledge foundation complementary to the
pytorch-build-resolveragent.Type
Testing
Tested formatting and structure against existing skills (python-patterns, golang-patterns). Code examples verified for syntax and logic.
Checklist
Summary by cubic
Adds the
pytorch-patternsskill with clear, practical PyTorch best practices for models, training, data, performance, and checkpointing. This complements thepytorch-build-resolverby providing a reference for idiomatic, reproducible code.nn.Modulestructure and explicit weight init.zero_grad(set_to_none=True).weights_only=Trueon load.torch.amp, gradient checkpointing, andtorch.compile.Written for commit 958c81e. Summary will update on new commits.
Summary by CodeRabbit