From d80e669fe08e2851515ee73f9585447bc74fa3ed Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Thu, 12 Nov 2026 00:30:04 -0500 Subject: [PATCH] test(unified): cover the encoder half of the pose factorization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit factorized_pose_resists_room_shortcut_leakage builds its latents by hand — content = [scale, 1], full = [scale, room_x/3, 1] — so the skeleton branch's room-independence holds by construction. It verifies FactorizedPoseHead's algebra given a factorized latent, not that RfEncoder produces one, which is the gap #1438 describes. Add the missing half against the real encoder. z = g ⊙ gate + Wg·geo + bg, and encode_content returns g ⊙ gate with the window-mean token features and no additive room offset, so two windows differing only in geometry must produce the same content representation while their fused z differs. That is the complement of stale_windows_are_gated_toward_geometry_prior, which pins that z does move with geometry. Also record the existing test's scope in its doc comment and point at the new one. The test name is deliberately unchanged: ADR-281 cites it by name, and that ADR already states the toy scope ("on a toy that isolates the mechanism. MEASURED-CODE for the mechanism; not a pose-accuracy claim"), so renaming would break an accepted ADR's reference to describe something it already describes correctly. cargo test -p ruview-unified --no-default-features: 102 passed, 0 failed. Mutating encode_content to return cache.z (which carries the Wg·geo term) fails the new test, so it is sensitive to the property it names. --- v2/crates/ruview-unified/src/encoder.rs | 24 ++++++++++++++++++++++++ v2/crates/ruview-unified/src/heads.rs | 19 +++++++++++++------ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/v2/crates/ruview-unified/src/encoder.rs b/v2/crates/ruview-unified/src/encoder.rs index 78336edd78..6c4dd64ecd 100644 --- a/v2/crates/ruview-unified/src/encoder.rs +++ b/v2/crates/ruview-unified/src/encoder.rs @@ -389,6 +389,30 @@ mod tests { assert_ne!(fresh.z, moved.z); } + #[test] + fn content_representation_excludes_the_geometry_term() { + // z = g ⊙ gate + Wg·geo + bg; encode_content returns g ⊙ gate with the + // window-mean token features and no additive room offset. This is the + // complement of stale_windows_are_gated_toward_geometry_prior, which + // pins that z *does* move with geometry: together they are the + // factorization the pose head relies on. Exercised against the real + // encoder, so wiring geometry into the content path fails here. + let e = RfEncoder::new(EncoderConfig::default(), 7); + let tokens = toy_tokens(8); + let room_a = + TokenizedWindow { tokens: tokens.clone(), age_s: 0.25, geometry: [0.2; 6] }; + let room_b = TokenizedWindow { tokens, age_s: 0.25, geometry: [0.9; 6] }; + + // The fused representation separates the two rooms. + assert_ne!( + e.forward(&room_a.tokens, &[], WindowContext::from(&room_a)).z, + e.forward(&room_b.tokens, &[], WindowContext::from(&room_b)).z + ); + // The content representation cannot tell them apart. + assert_eq!(e.encode_content(&room_a), e.encode_content(&room_b)); + assert_eq!(e.encode_content(&room_a).len(), e.content_dim()); + } + #[test] fn masking_excludes_tokens_from_context() { let e = RfEncoder::new(EncoderConfig::default(), 5); diff --git a/v2/crates/ruview-unified/src/heads.rs b/v2/crates/ruview-unified/src/heads.rs index 0606a8dfab..8045398f51 100644 --- a/v2/crates/ruview-unified/src/heads.rs +++ b/v2/crates/ruview-unified/src/heads.rs @@ -561,12 +561,19 @@ mod tests { ); } - /// The RePos leakage experiment: in the training rooms, room position - /// correlates with body scale (small people in room A, tall in room B). - /// A monolithic absolute-pose head exploits the room feature as a - /// shortcut and collapses in an unseen room that breaks the - /// correlation; the factorized head's skeleton branch never sees room - /// features and generalizes. + /// The RePos leakage experiment, on synthetic latents: in the training + /// rooms, room position correlates with body scale (small people in room + /// A, tall in room B). A monolithic absolute-pose head exploits the room + /// feature as a shortcut and collapses in an unseen room that breaks the + /// correlation; the factorized head's skeleton branch is given a latent + /// without the room column and generalizes. + /// + /// Scope: the content and full latents here are hand-built + /// (`content = [scale, 1]`, `full = [scale, room_x/3, 1]`), so the + /// skeleton branch's room-independence is true by construction. What this + /// verifies is the head's algebra given such a factorization, not that the + /// encoder produces one. `RfEncoder`'s side of the contract is covered by + /// `encoder::tests::content_representation_excludes_the_geometry_term`. #[test] fn factorized_pose_resists_room_shortcut_leakage() { use crate::eval::mpjpe;