@@ -80,8 +80,6 @@ struct MseQuantizationResult {
8080 all_indices : BufferMut < u8 > ,
8181 norms : BufferMut < f32 > ,
8282 padded_dim : usize ,
83- /// Random permutation for non-power-of-2 dims (shared by MSE and QJL).
84- perm : Option < Vec < u16 > > ,
8583}
8684
8785/// Core quantization: extract f32 elements, build rotation, normalize/rotate/quantize all rows.
@@ -93,17 +91,9 @@ fn turboquant_quantize_core(
9391 let dimension = fsl. list_size ( ) as usize ;
9492 let num_rows = fsl. len ( ) ;
9593
96- let mut rotation = RotationMatrix :: try_new ( seed, dimension) ?;
94+ let rotation = RotationMatrix :: try_new ( seed, dimension) ?;
9795 let padded_dim = rotation. padded_dim ( ) ;
9896
99- // For non-power-of-2 dims, generate a random permutation to scatter
100- // zero-padded entries uniformly before the SRHT.
101- let perm = ( dimension < padded_dim)
102- . then ( || RotationMatrix :: gen_permutation ( seed. wrapping_add ( 42 ) , padded_dim) ) ;
103- if let Some ( ref p) = perm {
104- rotation = rotation. with_permutation ( p. clone ( ) ) ;
105- }
106-
10797 let f32_elements = extract_f32_elements ( fsl) ?;
10898
10999 let centroids = get_centroids ( padded_dim as u32 , bit_width) ?;
@@ -142,7 +132,6 @@ fn turboquant_quantize_core(
142132 all_indices,
143133 norms,
144134 padded_dim,
145- perm,
146135 } )
147136}
148137
@@ -177,23 +166,15 @@ fn build_turboquant_mse(
177166
178167 let rotation_signs = bitpack_rotation_signs ( & core. rotation ) ?;
179168
180- let mut array = TurboQuantArray :: try_new_mse (
169+ TurboQuantArray :: try_new_mse (
181170 fsl. dtype ( ) . clone ( ) ,
182171 codes,
183172 norms_array,
184173 centroids_array,
185174 rotation_signs,
186175 dimension,
187176 bit_width,
188- ) ?;
189-
190- // Store permutation for non-power-of-2 dims.
191- if let Some ( ref perm) = core. perm {
192- array. slots [ crate :: encodings:: turboquant:: array:: Slot :: Permutation as usize ] =
193- Some ( bitpack_permutation ( perm) ?) ;
194- }
195-
196- Ok ( array)
177+ )
197178}
198179
199180/// Encode a FixedSizeListArray into a MSE-only `TurboQuantArray`.
@@ -266,16 +247,7 @@ pub fn turboquant_encode_qjl(
266247
267248 // QJL uses a different rotation than the MSE stage to ensure statistical
268249 // independence between the quantization noise and the sign projection.
269- // The same permutation is shared: it's a property of the padded embedding
270- // space, not of the rotation itself.
271- let qjl_rotation = {
272- let rot = RotationMatrix :: try_new ( seed. wrapping_add ( 25 ) , dim) ?;
273- if let Some ( ref p) = core. perm {
274- rot. with_permutation ( p. clone ( ) )
275- } else {
276- rot
277- }
278- } ;
250+ let qjl_rotation = RotationMatrix :: try_new ( seed. wrapping_add ( 25 ) , dim) ?;
279251
280252 let num_rows = fsl. len ( ) ;
281253 let mut residual_norms_buf = BufferMut :: < f32 > :: with_capacity ( num_rows) ;
@@ -378,12 +350,3 @@ fn bitpack_rotation_signs(rotation: &RotationMatrix) -> VortexResult<ArrayRef> {
378350 let prim = PrimitiveArray :: new :: < u8 > ( buf. freeze ( ) , Validity :: NonNullable ) ;
379351 Ok ( bitpack_encode ( & prim, 1 , None ) ?. into_array ( ) )
380352}
381-
382- /// Bitpack a permutation of u16 indices for efficient storage.
383- fn bitpack_permutation ( perm : & [ u16 ] ) -> VortexResult < ArrayRef > {
384- let mut buf = BufferMut :: < u16 > :: with_capacity ( perm. len ( ) ) ;
385- buf. extend_from_slice ( perm) ;
386- let prim = PrimitiveArray :: new :: < u16 > ( buf. freeze ( ) , Validity :: NonNullable ) ;
387- let bit_width = ( perm. len ( ) as f64 ) . log2 ( ) . ceil ( ) as u8 ;
388- Ok ( bitpack_encode ( & prim, bit_width, None ) ?. into_array ( ) )
389- }
0 commit comments