# Codebase Rules This repo has accumulated several near-duplicate implementations and a few hidden shape/device assumptions. Use the rules below for any further cleanup or feature work. ## Ownership and layout - Put shared GP-NeRF / Semantic-Frustum transformer pieces in `gpnerf/transformer_blocks.py`. - Keep `gpnerf/transformer_network.py` focused on GP-NeRF assembly logic. - Keep `s_frustum/transformer.py` focused on frustum-specific logic only. - Prefer extending existing modules over copy-pasting whole files. ## Device and distributed rules - Never hardcode `.cuda()` in model or dataloader utilities; use `.to(device)`. - Never hardcode output directories; resolve them from `args.rootdir`. - Convert to `SyncBatchNorm` only inside the distributed wrapping path, before `DistributedDataParallel`. ## Shape and indexing rules - Do not hardcode image sizes such as `320x240` or feature sizes such as `160x120`; infer them from tensors. - Assume flattened pixel indices are zero-based unless a caller explicitly says otherwise. - When projecting semantic features, derive any downsampled index mapping from the current feature map stride instead of dataset-specific constants. ## Transformer rules - Use the fused PyTorch SDPA path for standard self-attention whenever possible. - If a block needs explicit attention weights for density sampling, keep that path isolated from the main attention implementation. - Avoid channel-wise hacks like `repeat_interleave(8)`; compute grouping from the actual tensor shapes. ## Validation rules - Any change touching render paths should be covered by at least one synthetic shape test. - Any change touching sampling or semantic distillation should be checked for: device placement, index bounds, and `N_importance == 0`.