Rulepython
Code Style Rule
Rules beyond pre-commit (ruff format/lint).
Code Style Rules
Rules beyond pre-commit (ruff format/lint).
Design Patterns
- Prefer composition over inheritance: Avoid deep class hierarchies
- Good:
Engineholds aCheckpointerinstance - Avoid:
CheckpointableEngine(Engine)→FSDPCheckpointableEngine(CheckpointableEngine)
- Good:
- Keep inheritance shallow (≤2 levels when possible)
- Use mixins sparingly; prefer explicit delegation
Logging
- Use
areal.utils.logging.getLogger(name)with PascalCase descriptive name, NOTprintor stdliblogging- Good:
getLogger("RLVRWorkflow"),getLogger("ArchonEngine"),getLogger("GSM8KReward") - Avoid:
getLogger(__name__)or dotted paths likegetLogger("areal.engine.fsdp")
- Good:
- Log levels:
- DEBUG: Detailed tracing (avoid in hot paths)
- INFO: Milestones (training start, checkpoint saved)
- WARNING: Recoverable issues
- ERROR: Failures requiring attention
Performance Patterns
- Avoid GPU-CPU sync:
.item(),.tolist(),print(tensor)cause sync - Prefer batch operations: Avoid Python loops over tensor elements
- In-place ops: Use when safe, but careful with autograd (
.add_()vs+)
Naming Conventions
| Type | Pattern | Example |
| ---------------- | ------------- | ----------------------------------- |
| Config dataclass | XxxConfig | GRPOConfig, FSDPConfig |
| Engine class | XxxEngine | FSDPEngine, ArchonEngine |
| Workflow class | XxxWorkflow | RLVRWorkflow, MultiTurnWorkflow |
| Reward function | xxx_reward | math_reward, code_reward |
Tensor Conventions
- Shape convention:
[batch, seq_len, hidden]or document clearly - Use
torch.Sizeassertions for shape validation in debug - Prefer explicit dtype/device over implicit conversion
Import Style
- Group: stdlib, third-party, areal (ruff handles order)
- Avoid
from x import *(CLAUDE.md rule) - Prefer explicit imports over module-level imports for large modules