awesome-cursor-rules-mdc is a generator that creates Cursor MDC rule files from structured library information, using semantic search and language models to gather and organize guidance. Developers use it to produce reusable rules for libraries in Cursor, and the catalogue includes 200 of those rules.
Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/sanjeed5/awesome-cursor-rules-mdcWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/rules/sanjeed5/awesome-cursor-rules-mdc/pytorch)<a href="https://agentmods.dev/rules/sanjeed5/awesome-cursor-rules-mdc/pytorch"><img src="https://agentmods.dev/badge/rules/sanjeed5/awesome-cursor-rules-mdc/pytorch.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.03584 | $0.03584 |
| Opus 5 | $0.01792 | $0.01792 |
| Sonnet 5 | $0.00717 | $0.00717 |
| Haiku 4.5 | $0.00358 | $0.00358 |
Grade A, and why
pytorch scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 494 lines — stays where its author put it; the contents beside it link to each section on GitHub.
PyTorch Best Practices
This guide outlines the definitive best practices for developing with PyTorch, ensuring your code is readable, performant, and production-ready. We prioritize usability, explicit control, and modern tooling.
1. Code Organization and Structure
Structure your PyTorch projects for clarity, testability, and scalability. Encapsulate logical blocks into distinct functions or classes.
1.1. Modularize Your Codebase
Separate data loading, model definition, training, and evaluation into dedicated modules or functions. This makes components reusable and testable.
❌ BAD: Monolithic script
# train.py
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
# ... data loading, model definition, training loop all in one file ...
class MyModel(nn.Module):
# ...
pass
def main():
# Data loading
train_data = TensorDataset(...)
train_loader = DataLoader(train_data, batch_size=32)
# Model, optimizer, loss
model = MyModel()
optimizer = torch.optim.Adam(model.parameters())
criterion = nn.CrossEntropyLoss()
# Training loop
for epoch in range(10):
for batch_idx, (data, target) in enumerate(train_loader):
# ... training logic ...
pass
if __name__ == "__main__":
main()
✅ GOOD: Modularized structure
# src/data.py
import torch
from torch.utils.data import DataLoader, TensorDataset
def get_dataloaders(batch_size: int) -> tuple[DataLoader, DataLoader]:
# Example: Create synthetic data
X = torch.randn(1000, 784)
y = torch.randint(0, 10, (1000,))
train_dataset = TensorDataset(X, y)
val_dataset = TensorDataset(X[:100], y[:100]) # Smaller val set
train_loader = DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=4, pin_memory=True)
val_loader = DataLoader(val_dataset, batch_size=batch_size, shuffle=False, num_workers=4, pin_memory=True)
return train_loader, val_loader
# src/model.py
import torch.nn as nn
class SimpleCNN(nn.Module):
def __init__(self, num_classes: int = 10):
super().__init__()
self.features = nn.Sequential(
nn.Conv2d(1, 32, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(32, 64, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2)
)
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(64 * 7 * 7, 128), # Assuming 28x28 input, adjust for other sizes
nn.ReLU(),
nn.Linear(128, num_classes)
)
def forward(self, x: torch.Tensor) -> torch.Tensor:
x = self.features(x)
x = self.classifier(x)
return x
# src/train.py
import torch
import torch.nn as nn
from torch.optim import Adam
from src.model import SimpleCNN
from src.data import get_dataloaders
def train_epoch(model: nn.Module, loader: DataLoader, optimizer: Adam, criterion: nn.Module, device: torch.device) -> float:
model.train()
total_loss = 0.0
for data, target in loader:
data, target = data.to(device), target.to(device)
optimizer.zero_grad()
output = model(data)
loss = criterion(output, target)
loss.backward()
optimizer.step()
total_loss += loss.item()
return total_loss / len(loader)
def evaluate_model(model: nn.Module, loader: DataLoader, device: torch.device) -> float:
model.eval()
correct = 0
total = 0
with torch.no_grad():
for data, target in loader:
data, target = data.to(device), target.to(device)
output = model(data)
_, predicted = torch.max(output.data, 1)
total += target.size(0)
correct += (predicted == target).sum().item()
return 100 * correct / total
# main.py
import torch
from src.model import SimpleCNN
from src.data import get_dataloaders
from src.train import train_epoch, evaluate_model
def run_experiment(epochs: int = 10, batch_size: int = 64, lr: float = 1e-3):
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
train_loader, val_loader = get_dataloaders(batch_size)
model = SimpleCNN().to(device)
optimizer = torch.optim.Adam(model.parameters(), lr=lr)
criterion = torch.nn.CrossEntropyLoss()
for epoch in range(epochs):
train_loss = train_epoch(model, train_loader, optimizer, criterion, device)
val_accuracy = evaluate_model(model, val_loader, device)
print(f"Epoch {epoch+1}: Train Loss = {train_loss:.4f}, Val Acc = {val_accuracy:.2f}%")
torch.save(model.state_dict(), "final_model.pth")
if __name__ == "__main__":
run_experiment()
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 3d ago First seen · 494 lines · 3,584 tokens per session scan A a319950e7923
pytorch is a cursor rule published in the GitHub repository sanjeed5/awesome-cursor-rules-mdc (3,571 stars, last pushed 3mo ago), licensed CC0-1.0. It adds 3,584 tokens to every session, about $0.0179 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.
Other cursor rules, from other repositories
pyspark-etl-best-practices-cursorrules-prompt-file
Cursor rules for PySpark ETL development with code style, joins, window functions, map operations, and Iceberg patterns.
python-llm-ml-workflow-cursorrules-prompt-file
Cursor rules for Python LLM & ML development with workflow integration.
automl-hyperparameter-optimization
AutoML and hyperparameter optimization rules for Python ML projects using Ray Tune, Optuna, PyCaret, and time-series AutoML libraries.
fenic
Cursor rule "fenic" from typedef-ai/fenic, covering writing fenic, must-knows and traps fenic check can't catch — get these right by hand.
cursorrules
You are building an AI/ML project with Python. The project uses PyTorch for model training, handles data pipelines with proper validation, tracks experiments systematically, and follows production ML engineering practices. Code is type-hinted, tested, and reproducible.
sygaldry
You are an expert in Python, Mirascope, and the Sygaldry AI framework.