Skip to content

Commit a437794

Browse files
authored
[skills] add notes about model implementation in our skills. (#14191)
add notes about model implementation in our skills.
1 parent a50c7a2 commit a437794

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

.ai/models.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Linked from `AGENTS.md`, `skills/model-integration/SKILL.md`, and `review-rules.
66
## Coding style
77

88
- All layer calls should be visible directly in `forward` — avoid helper functions that hide `nn.Module` calls.
9+
- Prefer descriptive variable names over short ones. For example, prefer spelling out `query` over `q`.
910
- Avoid graph breaks for `torch.compile` compatibility — do not insert NumPy operations in forward implementations and any other patterns that can break `torch.compile` compatibility with `fullgraph=True`.
1011
- No new mandatory dependency without discussion (e.g. `einops`). Optional deps guarded with `is_X_available()` and a dummy in `utils/dummy_*.py`.
1112

@@ -182,4 +183,8 @@ Boolean gate. If `False` (default), calling that method raises `ValueError`. All
182183
```
183184
See `transformer_flux.py`, `transformer_flux2.py`, `transformer_wan.py`, `unet_2d_condition.py`, and `pipeline_pixart_alpha.py` for reference usages. Never leave an unconditional `torch.float64` in the model.
184185

185-
6. **Using `torch.empty`.** - Do not use `torch.empty` to initialize parameters. Use `torch.zeros` or `torch.ones`, instead.
186+
6. **Using `torch.empty`.** - Do not use `torch.empty` to initialize parameters. Use `torch.zeros` or `torch.ones`, instead.
187+
188+
7. **Tensor contiguity.** - Non-contiguous tensors can degrade performance. Therefore, try to maintain contiguity
189+
of the tensors whenever possible. A non-contiguous tensor is usually produced because of the operations. A common
190+
example is a `flatten()` followed by a `transpose()`. This sequence is known to produce non-contiguous layouts. So, prefer calling `contiguous()` on the output tensor to maintain performance.

0 commit comments

Comments
 (0)