@@ -518,4 +518,60 @@ mod tests {
518518 // Verify output magic
519519 assert_eq ! ( & output[ 0 ..4 ] , b"BGZ7" ) ;
520520 }
521+
522+ #[ test]
523+ #[ ignore] // Requires /tmp/openchat/openchat-3.5-0106.Q8_0.gguf
524+ fn test_stream_index_openchat_q8 ( ) {
525+ use std:: io:: { BufReader , BufWriter } ;
526+
527+ let path = "/tmp/openchat/openchat-3.5-0106.Q8_0.gguf" ;
528+ let file = match std:: fs:: File :: open ( path) {
529+ Ok ( f) => f,
530+ Err ( _) => { eprintln ! ( "SKIP: {} not found" , path) ; return ; }
531+ } ;
532+ let input_size = file. metadata ( ) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
533+ let mut reader = BufReader :: new ( file) ;
534+
535+ let out_path = "/tmp/openchat/openchat-3.5-0106.bgz7" ;
536+ let out = std:: fs:: File :: create ( out_path) . expect ( "create output" ) ;
537+ let mut writer = BufWriter :: new ( out) ;
538+
539+ let stats = stream_index_gguf (
540+ & mut reader,
541+ & mut writer,
542+ Some ( & |name, layer_type, orig, comp| {
543+ let ratio = if comp > 0 { orig as f64 / comp as f64 } else { 0.0 } ;
544+ eprintln ! ( " {:50} {:12?} {:>10} → {:>8} ({:.0}×)" ,
545+ name, layer_type, orig, comp, ratio) ;
546+ } ) ,
547+ ) . expect ( "stream_index_gguf" ) ;
548+
549+ drop ( writer) ;
550+ let out_size = std:: fs:: metadata ( out_path) . map ( |m| m. len ( ) ) . unwrap_or ( 0 ) ;
551+
552+ eprintln ! ( ) ;
553+ eprintln ! ( "=== OpenChat 3.5 Q8_0 → bgz17 Results ===" ) ;
554+ eprintln ! ( " Input: {:.2} GB ({})" , input_size as f64 / 1e9 , path) ;
555+ eprintln ! ( " Output: {:.2} MB ({})" , out_size as f64 / 1e6 , out_path) ;
556+ eprintln ! ( " Tensors: {} total, {} indexed, {} skipped" ,
557+ stats. tensors_total, stats. tensors_indexed, stats. tensors_skipped) ;
558+ eprintln ! ( " Original (f32): {:.2} MB" , stats. original_bytes as f64 / 1e6 ) ;
559+ eprintln ! ( " Compressed: {:.2} MB" , stats. compressed_bytes as f64 / 1e6 ) ;
560+ eprintln ! ( " Overall ratio: {:.1}×" , stats. overall_ratio( ) ) ;
561+ eprintln ! ( " Peak tensor: {:.2} MB" , stats. peak_tensor_bytes as f64 / 1e6 ) ;
562+ eprintln ! ( ) ;
563+
564+ let type_names = [ "Attention" , "FeedForward" , "Conv2D" , "Norm" , "Embedding" , "Skip" ] ;
565+ for ( i, name) in type_names. iter ( ) . enumerate ( ) {
566+ let ( count, orig, comp) = stats. by_type [ i] ;
567+ if count > 0 {
568+ let ratio = if comp > 0 { orig as f64 / comp as f64 } else { 0.0 } ;
569+ eprintln ! ( " {:<12} {:>3} tensors: {:>10.2} MB → {:>8.2} MB ({:.1}×)" ,
570+ name, count, orig as f64 / 1e6 , comp as f64 / 1e6 , ratio) ;
571+ }
572+ }
573+
574+ assert ! ( stats. tensors_indexed > 0 , "should index at least some tensors" ) ;
575+ assert ! ( stats. overall_ratio( ) > 10.0 , "ratio should be significant: {:.1}" , stats. overall_ratio( ) ) ;
576+ }
521577}
0 commit comments