@@ -370,6 +370,7 @@ pub struct GraphExecutor {
370370 resolved_uploads : Vec < ResolvedUpload > ,
371371 startup_next : usize ,
372372 startup_ready : bool ,
373+ diagnostic_choices : Vec < ( Vec < u32 > , Vec < String > ) > ,
373374 next_sequence : u64 ,
374375 completed : Fence ,
375376 poison : Option < Error > ,
@@ -469,6 +470,7 @@ impl GraphExecutor {
469470 resolved_uploads : Vec :: with_capacity ( upload_capacity) ,
470471 startup_next : 0 ,
471472 startup_ready : false ,
473+ diagnostic_choices : Vec :: new ( ) ,
472474 next_sequence : 1 ,
473475 completed : Fence ( 0 ) ,
474476 poison : None ,
@@ -534,21 +536,83 @@ impl GraphExecutor {
534536 if status != 0 {
535537 return Err ( format ! ( "startup tuning graph {:?} failed with status {status}" , graph. name) . into ( ) ) ;
536538 }
537- for ( buffer, host) in & outputs {
538- let consumers = self . manifest . graphs . iter ( ) . filter ( |consumer| {
539- consumer. tuned_bindings . iter ( ) . any ( |binding| binding. buffer == buffer. name )
540- } ) . map ( |consumer| consumer. name . as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
541- eprintln ! ( "Startup tuning output: device={} graph={:?} buffer={:?} dtype={:?} shape={:?} bytes={:02x?} consumers={consumers:?}" ,
542- self . manifest. device, graph. name, buffer. name, buffer. dtype, buffer. shape, host. bytes( ) ) ;
543- }
539+ let mut profiles = outputs. iter ( ) . filter_map ( |( _, host) | {
540+ <[ u8 ; 4 ] >:: try_from ( host. bytes ( ) ) . ok ( ) . map ( u32:: from_ne_bytes)
541+ } ) . collect :: < Vec < _ > > ( ) ;
542+ profiles. sort_unstable ( ) ;
543+ profiles. dedup ( ) ;
544+ let consumers = self . manifest . graphs . iter ( ) . filter ( |consumer| {
545+ consumer. tuned_bindings . iter ( ) . any ( |binding| binding. tuning_graph == graph. name )
546+ } ) . map ( |consumer| consumer. name . clone ( ) ) . collect ( ) ;
547+ self . diagnostic_choices . push ( ( profiles, consumers) ) ;
544548 self . startup_next += 1 ;
545549 Ok ( ( ) )
546550 }
547551
548552 pub ( super ) fn report_startup ( & self , started : Instant ) {
549553 if self . startup_next != 0 {
550554 eprintln ! ( "Startup tuning: {} graphs completed in {:.2}s" , self . startup_next, started. elapsed( ) . as_secs_f64( ) ) ;
555+ self . report_collective_choices ( ) ;
556+ }
557+ }
558+
559+ fn report_collective_choices ( & self ) {
560+ use std:: collections:: BTreeMap ;
561+ use std:: fmt:: Write ;
562+
563+ // Temporary interpretation of Qwen graph names and b12x packed selectors.
564+ fn mode ( value : u32 ) -> & ' static str {
565+ match value >> 16 {
566+ 0 => "Full" , 1 => "Payload RSAG" , 2 => "Bulk Push" ,
567+ 3 => "Bulk Pull" , 4 => "Pull" , _ => "Unknown" ,
568+ }
569+ }
570+ fn describe ( profiles : impl Iterator < Item = u32 > ) -> String {
571+ let mut modes: BTreeMap < & str , ( u32 , u32 ) > = BTreeMap :: new ( ) ;
572+ for value in profiles {
573+ let ctas = value & 0xffff ;
574+ let range = modes. entry ( mode ( value) ) . or_insert ( ( ctas, ctas) ) ;
575+ range. 0 = range. 0 . min ( ctas) ;
576+ range. 1 = range. 1 . max ( ctas) ;
577+ }
578+ modes. into_iter ( ) . map ( |( name, ( lo, hi) ) | {
579+ if lo == hi { format ! ( "{name} ({lo} CTAs)" ) }
580+ else { format ! ( "{name} ({lo}–{hi} CTAs)" ) }
581+ } ) . collect :: < Vec < _ > > ( ) . join ( ", " )
582+ }
583+ let mut totals = BTreeMap :: new ( ) ;
584+ let mut prefill = BTreeMap :: < usize , Vec < u32 > > :: new ( ) ;
585+ let mut decode = Vec :: new ( ) ;
586+ let mut shared = Vec :: new ( ) ;
587+ for ( profiles, consumers) in & self . diagnostic_choices {
588+ let name = if profiles. len ( ) == 1 { mode ( profiles[ 0 ] ) } else { "Mixed/unknown" } ;
589+ * totals. entry ( name) . or_insert ( 0usize ) += 1 ;
590+ if consumers. iter ( ) . any ( |name| name. starts_with ( "speculative" ) ) {
591+ decode. extend ( profiles. iter ( ) . copied ( ) ) ;
592+ }
593+ let sizes = consumers. iter ( ) . filter_map ( |name| {
594+ name. strip_prefix ( "prefill" ) . and_then ( |size| size. parse :: < usize > ( ) . ok ( ) )
595+ } ) . collect :: < Vec < _ > > ( ) ;
596+ if sizes. len ( ) > 1 {
597+ shared. extend ( profiles. iter ( ) . copied ( ) ) ;
598+ } else if let Some ( size) = sizes. first ( ) {
599+ prefill. entry ( * size) . or_default ( ) . extend ( profiles. iter ( ) . copied ( ) ) ;
600+ }
601+ }
602+ let mut text = format ! ( " Collective choices · device {} · diagnostic\n " , self . manifest. device) ;
603+ let counts = totals. iter ( ) . map ( |( name, count) | format ! ( "{name}: {count} groups" ) )
604+ . collect :: < Vec < _ > > ( ) . join ( " · " ) ;
605+ writeln ! ( text, " {counts}" ) . unwrap ( ) ;
606+ if !decode. is_empty ( ) {
607+ writeln ! ( text, " Decode/speculative {}" , describe( decode. into_iter( ) ) ) . unwrap ( ) ;
608+ }
609+ if !shared. is_empty ( ) {
610+ writeln ! ( text, " Shared across sizes {}" , describe( shared. into_iter( ) ) ) . unwrap ( ) ;
611+ }
612+ for ( size, profiles) in prefill {
613+ writeln ! ( text, " Prefill {size:>4} tokens {}" , describe( profiles. into_iter( ) ) ) . unwrap ( ) ;
551614 }
615+ eprint ! ( "{text}" ) ;
552616 }
553617
554618 pub ( super ) fn finish_startup ( & mut self ) -> Result < ( ) > {
0 commit comments