pytorch-cn

pytorch-cn is a cursor rule for Cursor from XingjianTao/Cursor-Rules-for-PyTorch-DeepLearning-Beginner. It costs 5,285 tokens per session, scanned A, original, MIT.

A Chinese-language set of best practices for PyTorch, a Python framework used to build and train machine-learning models. It describes suggested folders for data, models, source code, experiments, tests, scripts, and configuration files.

In plain words
What is it for?
Use it when starting or organising a PyTorch project, especially for arranging datasets, model code, training and evaluation scripts, configuration files, notebooks, utilities, and unit or integration tests.
Why use it?
It gives machine-learning projects a predictable structure and separates experiments, training code, data processing, model definitions, tests, and settings. That makes the codebase easier to navigate and maintain.

Cursor rule for Cursor

Written for Cursor: a Cursor rule (.mdc).

Good fit Use it when starting or organising a PyTorch project, especially for arranging…

Compare 6 cursor rules from other repositories ↓
Install with agentmods
npx agentmods add rules/xingjiantao/cursor-rules-for-pytorch-deeplearning-beginner/pytorch-cn
Install

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.

Clone the repo
git clone --depth 1 https://github.com/XingjianTao/Cursor-Rules-for-PyTorch-DeepLearning-Beginner

Made for: Cursor.

Wrote 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.

agentmods badge for pytorch-cn

README.md
[![agentmods](https://agentmods.dev/badge/rules/xingjiantao/cursor-rules-for-pytorch-deeplearning-beginner/pytorch-cn.svg)](https://agentmods.dev/rules/xingjiantao/cursor-rules-for-pytorch-deeplearning-beginner/pytorch-cn)
Your own site
<a href="https://agentmods.dev/rules/xingjiantao/cursor-rules-for-pytorch-deeplearning-beginner/pytorch-cn"><img src="https://agentmods.dev/badge/rules/xingjiantao/cursor-rules-for-pytorch-deeplearning-beginner/pytorch-cn.svg" alt="Measured on agentmods" height="20"></a>
Per session 5,285 This file is loaded in full into every session.
When invoked 5,285 The same file — it is already loaded in full.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

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.

ModelPer sessionOnce invoked
Fable 5.1 $0.05285 $0.05285
Opus 5 $0.02642 $0.02642
Sonnet 5 $0.01057 $0.01057
Haiku 4.5 $0.00528 $0.00528

Measured 6d ago against content hash e5a44e406093, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

pytorch-cn 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 6d 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.

Original-cn/pytorch-cn.mdc · 384 lines

How it starts

The opening of the file, as written. The whole thing — 384 lines — stays where its author put it; the contents beside it link to each section on GitHub.

PyTorch 最佳实践和编码标准

本文档为PyTorch项目开发提供了全面的指导方针,涵盖了代码组织、性能优化、安全性、测试方法和常见陷阱。遵循这些最佳实践将使PyTorch代码更加可读、可维护和高效。

库信息:

  • 名称:PyTorch
  • 类别:ai_ml
  • 子类别:machine_learning

1. 代码组织和结构

1.1 目录结构最佳实践

一个组织良好的目录结构可以提高代码的可维护性和协作性。以下是PyTorch项目的推荐结构:

project_root/ ├── data/ │ ├── raw/ │ ├── processed/ │ └── ... ├── models/ │ ├── layers.py │ ├── networks.py │ ├── losses.py │ ├── ops.py │ └── model_name.py ├── src/ │ ├── data/ │ │ ├── datasets.py │ │ ├── dataloaders.py │ │ └── transforms.py │ ├── models/ │ │ └── ... (模型相关代码) │ ├── utils/ │ │ └── ... (工具函数) │ └── visualization/ │ └── ... ├── notebooks/ │ └── ... (用于实验的Jupyter笔记本) ├── tests/ │ ├── unit/ │ ├── integration/ │ └── ... ├── scripts/ │ └── train.py │ └── eval.py ├── configs/ │ └── ... (配置文件,例如YAML) ├── README.md ├── requirements.txt ├── .gitignore └── ...

  • data/:存储原始和处理过的数据集。
  • models/:包含PyTorch模型定义、层和自定义损失函数。将网络架构、单独的层/块和操作分为不同的文件。
  • src/:保存主要源代码,包括数据加载、模型定义、工具函数和可视化工具。通常根据职责进一步拆分src/文件夹。
  • notebooks/:用于实验和探索的Jupyter笔记本。使用笔记本进行初步探索和原型开发,但将最终确定的代码转移到Python脚本中。
  • tests/:单元、集成和端到端测试。
  • scripts/:训练、评估和部署脚本。主训练脚本应导入模型定义。
  • configs/:用于超参数设置和其他参数的配置文件。

1.2 文件命名约定

  • 使用描述性和一致的文件名。
  • Python文件:lower_with_under.py(例如,data_loader.pymodel_utils.py)。
  • 模型文件:model_name.py(例如,resnet.pytransformer.py)。
  • 配置文件:config_name.yaml(例如,train_config.yaml)。

1.3 模块组织

  • 将相关函数和类分组到模块中。
  • 使用清晰简洁的模块名称。
  • 在每个模块开头包含一个docstring来描述其用途。
  • 遵循一致的导入风格:
    # 标准库导入
    import os
    import sys
    
    # 第三方库导入
    import numpy as np
    import torch
    import torchvision
    
    # 本地应用程序/库导入
    from src.data import data_loader
    from src.models import resnet
    from src.utils import helper_functions
    

1.4 组件架构

  • nn.Module:创建PyTorch神经网络的基本构建块。始终继承nn.Module来定义模型、层和自定义操作。
  • forward()方法:在forward()方法中实现模块的前向传递。PyTorch使用__call__方法(它会执行forward())来通过模型传递数据。
  • 关注点分离:将模型设计为更小、可重用模块的组合。这促进了模块化并简化了调试。

Read the full file on GitHub · 384 lines

Changes

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.

  1. 6d ago First seen · 384 lines · 5,285 tokens per session scan A e5a44e406093

Subscribe to this mod's changes

pytorch-cn is a cursor rule published in the GitHub repository XingjianTao/Cursor-Rules-for-PyTorch-DeepLearning-Beginner (3 stars, last pushed 1y ago), licensed MIT. It adds 5,285 tokens to every session, about $0.0264 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-08-31.