@@ -17,7 +17,7 @@ use crate::util::padding;
17
17
/// Quantized embedding matrix.
18
18
pub struct QuantizedArray {
19
19
quantizer : PQ < f32 > ,
20
- quantized : Array2 < u8 > ,
20
+ quantized_embeddings : Array2 < u8 > ,
21
21
norms : Option < Array1 < f32 > > ,
22
22
}
23
23
@@ -237,7 +237,9 @@ impl QuantizedArray {
237
237
238
238
impl Storage for QuantizedArray {
239
239
fn embedding ( & self , idx : usize ) -> CowArray1 < f32 > {
240
- let mut reconstructed = self . quantizer . reconstruct_vector ( self . quantized . row ( idx) ) ;
240
+ let mut reconstructed = self
241
+ . quantizer
242
+ . reconstruct_vector ( self . quantized_embeddings . row ( idx) ) ;
241
243
if let Some ( ref norms) = self . norms {
242
244
reconstructed *= norms[ idx] ;
243
245
}
@@ -246,7 +248,10 @@ impl Storage for QuantizedArray {
246
248
}
247
249
248
250
fn shape ( & self ) -> ( usize , usize ) {
249
- ( self . quantized . rows ( ) , self . quantizer . reconstructed_len ( ) )
251
+ (
252
+ self . quantized_embeddings . rows ( ) ,
253
+ self . quantizer . reconstructed_len ( ) ,
254
+ )
250
255
}
251
256
}
252
257
@@ -280,15 +285,15 @@ impl ReadChunk for QuantizedArray {
280
285
let mut quantized_embeddings_vec = vec ! [ 0u8 ; n_embeddings * quantizer. quantized_len( ) ] ;
281
286
read. read_exact ( & mut quantized_embeddings_vec)
282
287
. map_err ( |e| ErrorKind :: io_error ( "Cannot read quantized embeddings" , e) ) ?;
283
- let quantized = Array2 :: from_shape_vec (
288
+ let quantized_embeddings = Array2 :: from_shape_vec (
284
289
( n_embeddings, quantizer. quantized_len ( ) ) ,
285
290
quantized_embeddings_vec,
286
291
)
287
292
. map_err ( Error :: Shape ) ?;
288
293
289
294
Ok ( QuantizedArray {
290
295
quantizer,
291
- quantized ,
296
+ quantized_embeddings ,
292
297
norms,
293
298
} )
294
299
}
@@ -306,7 +311,7 @@ impl WriteChunk for QuantizedArray {
306
311
Self :: write_chunk (
307
312
write,
308
313
& self . quantizer ,
309
- self . quantized . view ( ) ,
314
+ self . quantized_embeddings . view ( ) ,
310
315
self . norms . as_ref ( ) . map ( Array1 :: view) ,
311
316
)
312
317
}
@@ -401,11 +406,11 @@ where
401
406
rng,
402
407
) ;
403
408
404
- let quantized = quantizer. quantize_batch ( embeds. as_view ( ) ) ;
409
+ let quantized_embeddings = quantizer. quantize_batch ( embeds. as_view ( ) ) ;
405
410
406
411
QuantizedArray {
407
412
quantizer,
408
- quantized ,
413
+ quantized_embeddings ,
409
414
norms,
410
415
}
411
416
}
@@ -414,7 +419,7 @@ where
414
419
/// Memory-mapped quantized embedding matrix.
415
420
pub struct MmapQuantizedArray {
416
421
quantizer : PQ < f32 > ,
417
- quantized : Mmap ,
422
+ quantized_embeddings : Mmap ,
418
423
norms : Option < Mmap > ,
419
424
}
420
425
@@ -429,12 +434,12 @@ impl MmapQuantizedArray {
429
434
ArrayView1 :: from_shape_ptr ( ( n_embeddings, ) , norms. as_ptr ( ) as * const f32 ) )
430
435
}
431
436
432
- unsafe fn quantized ( & self ) -> ArrayView2 < u8 > {
437
+ unsafe fn quantized_embeddings ( & self ) -> ArrayView2 < u8 > {
433
438
let n_embeddings = self . shape ( ) . 0 ;
434
439
435
440
ArrayView2 :: from_shape_ptr (
436
441
( n_embeddings, self . quantizer . quantized_len ( ) ) ,
437
- self . quantized . as_ptr ( ) ,
442
+ self . quantized_embeddings . as_ptr ( ) ,
438
443
)
439
444
}
440
445
}
@@ -498,7 +503,7 @@ impl MmapQuantizedArray {
498
503
499
504
impl Storage for MmapQuantizedArray {
500
505
fn embedding ( & self , idx : usize ) -> CowArray1 < f32 > {
501
- let quantized = unsafe { self . quantized ( ) } ;
506
+ let quantized = unsafe { self . quantized_embeddings ( ) } ;
502
507
503
508
let mut reconstructed = self . quantizer . reconstruct_vector ( quantized. row ( idx) ) ;
504
509
if let Some ( norms) = unsafe { self . norms ( ) } {
@@ -510,7 +515,7 @@ impl Storage for MmapQuantizedArray {
510
515
511
516
fn shape ( & self ) -> ( usize , usize ) {
512
517
(
513
- self . quantized . len ( ) / self . quantizer . quantized_len ( ) ,
518
+ self . quantized_embeddings . len ( ) / self . quantizer . quantized_len ( ) ,
514
519
self . quantizer . reconstructed_len ( ) ,
515
520
)
516
521
}
@@ -537,12 +542,12 @@ impl MmapChunk for MmapQuantizedArray {
537
542
None
538
543
} ;
539
544
540
- let quantized =
545
+ let quantized_embeddings =
541
546
Self :: mmap_quantized_embeddings ( read, n_embeddings, quantizer. quantized_len ( ) ) ?;
542
547
543
548
Ok ( MmapQuantizedArray {
544
549
quantizer,
545
- quantized ,
550
+ quantized_embeddings ,
546
551
norms,
547
552
} )
548
553
}
@@ -560,7 +565,7 @@ impl WriteChunk for MmapQuantizedArray {
560
565
QuantizedArray :: write_chunk (
561
566
write,
562
567
& self . quantizer ,
563
- unsafe { self . quantized ( ) } ,
568
+ unsafe { self . quantized_embeddings ( ) } ,
564
569
unsafe { self . norms ( ) } ,
565
570
)
566
571
}
@@ -649,7 +654,7 @@ mod tests {
649
654
cursor. seek ( SeekFrom :: Start ( 0 ) ) . unwrap ( ) ;
650
655
let arr = QuantizedArray :: read_chunk ( & mut cursor) . unwrap ( ) ;
651
656
assert_eq ! ( arr. quantizer, check_arr. quantizer) ;
652
- assert_eq ! ( arr. quantized , check_arr. quantized ) ;
657
+ assert_eq ! ( arr. quantized_embeddings , check_arr. quantized_embeddings ) ;
653
658
}
654
659
655
660
#[ test]
0 commit comments