Canonical instructions for AI coding agents in this repository. CLAUDE.md imports this file; keep shared agent guidance here.
- After editing any
.protoundertzrec/protos/, regenerate bindings withbash scripts/gen_proto.sh._pb2.py/_pb2.pyifiles are generated (gitignored); never edit them.
- If a tool you need (python, pip, pre-commit, protoc) is missing, look for a project conda env or venv and activate it; otherwise stop and ask. Do NOT install substitutes or new toolchains on your own.
- There is no editable install: run from the repo root with
PYTHONPATH=.. - One-time dev setup:
pip install -r requirements.txt, thenpre-commit install.
Use the gitignored experiments/ directory at the repo root for scratch scripts, throwaway configs, and experiment outputs; tests write temp data under tmp/. Never commit files from either.
- Framework:
unittest; tests live next to the code as<module>_test.py. - Full suite:
python tzrec/tests/run.py(--list_tests,--scope gpu|h20). Single test:python -m tzrec.modules.fm_test FactorizationMachineTest.test_fm_0. - Parameterize case tables with
@parameterized.expand(..., name_func=parameterized_name_func)fromtzrec/utils/test_util.py; create scratch dirs with itsmake_test_dir(). - Declare CI lanes with
@mark_ci_scope("gpu")/@mark_ci_scope("h20", "gpu")at class or method level only; module-level tagging is unsupported.
- Before committing: run
pre-commit run -a(ruff lint+format at line 88, license header insertion, codespell, mdformat, LF endings) and fix everything it reports; type-check withpython scripts/pyre_check.py(Pyre strict; proto-generated files and tests are excluded). - Never
# noqaa line-length violation; let ruff-format decide layout and do not fight it.
- Commit subject:
[tag] short imperative subject, tag one offeat,bugfix,refactor,ci,doc,chore,perf. The(#123)suffix is added by squash merge; do not add it yourself. - Keep commit bodies minimal: no bullet lists of changes. A
[bugfix]commit message must explain the root cause of the bug and how the fix works. - The PR body should be clear and informative, with a Test Plan section that describes how you tested the change. If there were multiple potential paths you could have taken, call them out succinctly and justify the one you took.
- Never include customer names or internal resource IDs in branch names, commit messages, or PR bodies.
- Unless specified otherwise, push the branch to a fork and open the PR against the main repository.
Docstrings and inline comments follow different rules; do not confuse them:
- Docstrings are mandatory (ruff-enforced): Google style on public and private classes, functions, and methods;
*_test.pyandtzrec/ops/are exempt, as are modules, packages,__init__, and dunders. Never strip or skimp docstrings to "minimize comments". - Inline
#comments are minimized: code should be self-explanatory; comment only non-obvious "why" context, one short line. No commented-out code, no change-history or tombstone comments. Use# TODO(username): ...and# NOTE: ...; do not introduce FIXME/XXX/HACK. Denser math commentary is fine intzrec/ops/kernels. - Code, comments, and docstrings are English-only (Chinese belongs in
docs/); prefer plain ASCII in new comments outsidetzrec/ops/. - Naming:
fgmeans feature generator (fg_mode,fg_handler,pyfg), never feature group. - Don't create trivial 1-2 line single-use helpers unless they significantly improve readability.
- Use the repo logger (
from tzrec.utils.logging_util import logger), notprint(), in library code;print()is acceptable only in CLI tools and benchmarks. - Assume the reader knows PyTorch and TorchRec. Match existing patterns; if uncertain, choose the simpler, more concise implementation.