- Home
- Skills
- Code Quality & Review
- research-code-skill
Research Code Skill
Enforce strict ML research engineering standards, Hydra configurations, and PyTorch Lightning architecture.
Free
Works with the AI Agents you already use
research-code-skill
Example session with this skill installed
Refactor my current model training script. It has hardcoded learning rates and the model architecture is mixed with the training loop. Move it to the Lightning-Hydra structure.
- Read your context and instructions
- Compiled the research-code-
I have restructured the training script to follow the lab's architecture. The model backbone is now separated from the LightningModule, and all hyperparameters are moved to Hydra configs.
Convention applied: Refactor to Lightning-Hydra in src/models/mnist_module.py
Decision
- Extracted the CNN architecture into
src/models/components/simple_cnn.py. - Wrapped the backbone in a
LightningModulewith explicittorchmetricsandconfigure_optimizers. - Created
configs/model/mnist.yamlto handle the_target_andlrparameters.
Code
import torch
from lightning import LightningModule
from torchmetrics import MaxMetric, MeanMetric
from torchmetrics.classification import MulticlassAccuracy
class MNISTLitModule(LightningModule):
def __init__(
self,
net: torch.nn.Module,
optimizer: torch.optim.Optimizer,
scheduler: torch.optim.lr_scheduler.LRScheduler,
compile: bool = False,
) -> None:
super().__init__()
self.save_hyperparameters(logger=False)
self.net = net
self.criterion = torch.nn.CrossEntropyLoss()
self.train_acc = MulticlassAccuracy(num_classes=10)
self.val_acc = MulticlassAccuracy(num_classes=10)
def forward(self, x: torch.Tensor) -> torch.Tensor:
return self.net(x)
def training_step(self, batch: tuple[torch.Tensor, torch.Tensor], batch_idx: int):
x, y = batch
logits = self.forward(x)
loss = self.criterion(logits, y)
self.train_acc(logits, y)
self.log("train/loss", loss, on_step=False, on_epoch=True, prog_bar=True)
self.log("train/acc", self.train_acc, on_step=False, on_epoch=True, prog_bar=True)
return loss
def configure_optimizers(self):
optimizer = self.hparams.optimizer(params=self.trainer.model.parameters())
if self.hparams.scheduler is not None:
scheduler = self.hparams.scheduler(optimizer=optimizer)
return {
"optimizer": optimizer,
"lr_scheduler": {"scheduler": scheduler, "monitor": "val/loss", "interval": "epoch"},
}
return {"optimizer": optimizer}
Next steps
- Run
python scripts/run_gate.shto verify the new structure passes linting and tests. - Update
configs/experiment/mnist_base.yamlto reference the new model config. - Delete the legacy training script once the new entrypoint is verified.
Connects securely to your tools. The creator never sees your data.
About this skill
Research codebases often devolve into a mess of hardcoded paths, inconsistent naming, and rigid architectures that break reproducibility. This skill enforces a strict engineering charter for ML and DL projects. It ensures every file, model, and configuration follows a unified standard derived from industry authorities like Google, Meta, and PyTorch Lightning.
What it does
- Enforces Architecture preserves the Lightning-Hydra-Template structure, ensuring data, models, and configs stay in their designated directories.
- Validates Model Design separates model backbones from LightningModule systems and enforces OpenMMLab registry patterns.
- Standardizes Configs replaces hardcoded literals with Hydra-based configuration groups for experiment reproducibility.
- Ensures Code Quality applies Google Python Style naming conventions and type annotations across the entire source package.
- Automates Quality Gates runs a mandatory sequence of Black, Isort, Ruff, Mypy, and Pytest to verify every change.
How it works
- Scenario Selection determines if the task is building a new project from a skeleton or tidying an existing repository.
- Cluster Loading reads specific reference files for the current concern, such as model design or experiment reproducibility.
- Execution writes or refactors code using Karpathy-inspired discipline: think first, stay simple, and use surgical edits.
- Validation runs the five-tool quality gate to confirm the codebase remains conformant and functional.
Frameworks & tools
This skill is built for Python research environments using PyTorch Lightning, Hydra, and Timi. It integrates with Black, Isort, Ruff, Mypy, and Pytest for static analysis and testing.
Why this beats prompting it yourself
Generic prompts often ignore the complex interplay between experiment configs and model registries. This skill uses a fused rule-code registry (RC-*) to ensure conventions are machine-checkable and consistent across the entire project lifecycle.
Use cases
- Scaffolding initializing a new deep learning project with a reproducible directory tree and config system.
- Refactoring migrating a messy research script into a structured, installable Python package.
- Standardization enforcing uniform naming and docstring standards across a multi-member research team.
Known limitations
Does not support non-Python projects or frontend-only applications. Requires a Python 3.8+ interpreter for running quality gate scripts.
How to use
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scanned
Verified clean 12 days ago
- Free to download with an account
Requires