+
    œ°³jg—  ã                   óN  € ^ RI Ht ^ RIHt ^ RIHtHtHt ^ RIt^RI	H
t
HtHtHt ^RIHtHtHtHtHt ^RIHt ^RIHt ^R	IHt ^R
IHtHt ^RIHtHtH t  ^RI!H"t" ]'       d   ^RI#H$t$ ] PJ                  ! ]&4      t'] ! R R]4      4       t( ! R R]4      t) ! R R]4      t*R# )é    )ÚCallable)Ú	dataclass)ÚTYPE_CHECKINGÚAnyÚOptionalN)ÚDynamicCacheÚQuantizedCacheÚQuantizedLayerÚStaticCache)ÚGenerateDecoderOnlyOutputÚGenerationConfigÚGenerationMixinÚLogitsProcessorÚLogitsProcessorList)Ú ALL_STATIC_CACHE_IMPLEMENTATIONS)Ú!LOGITS_PROCESSOR_INPUTS_DOCSTRING)ÚStoppingCriteriaList)ÚALL_CACHE_NAMESÚGenerateNonBeamOutput)Úadd_start_docstringsÚis_diffusers_availableÚlogging)Ú,VibeVoiceAcousticTokenizerConv1dPaddingCache)ÚBaseStreamerc                   ó4   a € ] tR t^.t o RtRtV 3R ltRtV tR# )ÚVibeVoiceGenerateOutputzš
Outputs of VibeVoiceForConditionalGeneration.generate.

Args:
    audio (`list(torch.FloatTensor)` of length `batch_size`):
        The generated audio.
Nc                óX   <€ V ^8„  d   Qh/ S[ S[P                  ,          R,          ;R&   # )é   NÚaudio)ÚlistÚtorchÚFloatTensor)ÚformatÚ__classdict__s   "€Ús/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/vibevoice/generation_vibevoice.pyÚ__annotate__Ú$VibeVoiceGenerateOutput.__annotate__.   s"   ø‡ ‚ ñ ‘×!Ñ!Õ" TÕ)Ñ0ò ó    © )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r$   s   @r%   r   r   .   s   ø‡ € ñð -1€E÷ ƒ r(   r   c                   ób   a € ] tR t^;t o RtRV 3R lR llt]! ]4      V 3R lR l4       tRt	V t
R# )	Ú!VibeVoiceTokenConstraintProcessora‹  
Constrains token generation to only diffusion-related tokens during audio generation, as the role of the
language model is to emit:
- another audio-diffusion placeholder (which triggers the diffusion head to synthesize the next acoustic latent)
- or an EOS token (which signals the end of the audio generation).
The actual audio comes from the diffusion head, not from sampling the vocabulary.
Nc                óP   <€ V ^8„  d   QhRS[ S[,          RS[RS[P                  /# )r   Úvalid_token_idsÚ
vocab_sizeÚdevice)r    Úintr!   r8   )r#   r$   s   "€r%   r&   Ú.VibeVoiceTokenConstraintProcessor.__annotate__D   s*   ø€ ÷ 2ñ 2©©S­	ð 2¹sð 2ÉEÏLÉLñ 2r(   c                ó|   € \         P                  ! V3\        R 4      4      pRWA&   VP                  V4      V n        R# )z-infg        N)r!   ÚfullÚfloatÚtoÚlogits_mask)Úselfr6   r7   r8   r?   s   &&&& r%   Ú__init__Ú*VibeVoiceTokenConstraintProcessor.__init__D   s1   € ä—j’j * ´°f³Ó>ˆØ'*ˆÑ$Ø&Ÿ>™>¨&Ó1ˆÖr(   c                óh   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  /# )r   Ú	input_idsÚscoresÚreturn)r!   Ú
LongTensorr"   )r#   r$   s   "€r%   r&   r:   K   s5   ø€ ÷ )ñ )¡%×"2Ñ"2ð )¹E×<MÑ<Mð )ÑRW×RcÑRcñ )r(   c                ó&   € W P                   ,           # ©N©r?   )r@   rD   rE   s   &&&r%   Ú__call__Ú*VibeVoiceTokenConstraintProcessor.__call__J   s   € à×(Ñ(Õ(Ð(r(   rJ   rI   )r*   r+   r,   r-   r.   rA   r   r   rK   r0   r1   r2   s   @r%   r4   r4   ;   s.   ø‡ € ñ÷2ò 2ñ Ð;Ó<÷)ó =ö)r(   r4   c                   ó$  a a€ ] tR t^Ot oRtV3R lV 3R lltV3R lV 3R llt]V3R lR l4       tV3R lR	 lt	RV3R
 lR llt
RV3R lR lltV3R lR ltV3R lR ltV3R lR ltV3R lR ltV3R lR ltRV3R lR lltRtVtV ;t# )ÚVibeVoiceGenerationMixinaP  
Generation mixin for VibeVoice.

The classifier-free guidance (CFG) logic (the negative/unconditional branch and the diffusion sampling)
is adapted from the original VibeVoice implementation, where it all lives inline in a single `generate`
method:
https://github.com/vibevoice-community/VibeVoice/blob/07cb79feadd2d3fd7f47530d4c964a12857936a0/vibevoice/modular/modeling_vibevoice_inference.py#L327
Here it is factored into helpers, and the negative-branch helpers mirror what the positive branch does in
`_sample` (prepare inputs -> forward -> update model kwargs -> append the new token).
c                ó    <€ V ^8„  d   QhRS[ /# )r   rF   )r   )r#   r$   s   "€r%   r&   Ú%VibeVoiceGenerationMixin.__annotate__[   s   ø€ ÷ 	ñ 	Ñ8Kñ 	r(   c                óH  <€ \         SV `  ! V/ VB pV P                  P                  V P                  P                  V P                  P
                  V P                  P                  .pVP                  \        W@P                  P                  V P                  R 7      4       V# )©r8   )ÚsuperÚ_get_logits_processorÚconfigÚaudio_bos_token_idÚaudio_eos_token_idÚaudio_token_idÚeos_token_idÚappendr4   r7   r8   )r@   ÚargsÚkwargsÚ
processorsÚvalid_tokensÚ	__class__s   &*,  €r%   rT   Ú.VibeVoiceGenerationMixin._get_logits_processor[   s�   ø€ Ü‘WÒ2°DÐC¸FÑCˆ
à�K‰K×*Ñ*Ø�K‰K×*Ñ*Ø�K‰K×&Ñ&Ø�K‰K×$Ñ$ð	
ˆð 	×ÑÔ;¸LÏ+É+×J`ÑJ`Ðim×itÑitÔuÔvØÐr(   c                óJ   <€ V ^8„  d   QhRS[ R,          RS[S[ S[3,          /# )r   Úgeneration_configNrF   )r   ÚtupleÚdict)r#   r$   s   "€r%   r&   rP   f   s-   ø€ ÷ 5/ñ 5/Ù!1°DÕ!8ð5/á	Ñ¡Ð%Õ	&ñ5/r(   c                óP  <€ VP                  RR4      pVP                  RR4      pVP                  RR4      p\        SV `  ! V3/ VB w  rT;'       g    \        VRR4      pVf   V P	                  V4      pVf   \        R4      h\        VR4      '       d%   \        VR4      '       d   \        VR	4      '       g#   \        R
\        V4      P                   R24      hWqn	        W1n
        T;'       g    \        VRR4      ;'       g    ^
Vn        VP                  f   RVn        W3# )ab  
This method overrides [~generation.utils.GenerationMixin._prepare_generation_config].

It extracts VibeVoice-specific parameters for the generation config.

VibeVoice-specific parameters include:
- `noise_scheduler`: A custom noise scheduler instance. Optional: if not provided, a default one is built
    from `noise_scheduler_class`/`noise_scheduler_config` on the generation config (requires `diffusers`).
- `monitor_progress`: Whether to display a progress bar tracking audio generation. Defaults to `False`.
- `num_diffusion_steps`: Number of diffusion steps for audio latent sampling. Defaults to `10`.
Úmonitor_progressFÚnum_diffusion_stepsNÚnoise_schedulera2  VibeVoice generation requires a `noise_scheduler`. Either pass one to `generate(...)`, e.g. `diffusers.DPMSolverMultistepScheduler(beta_schedule='squaredcos_cap_v2', prediction_type='v_prediction')`, or set `noise_scheduler_class` (and optionally `noise_scheduler_config`) on the model's generation config.Úset_timestepsÚstepÚ	timestepszThe provided noise_scheduler (z†) is not compatible with VibeVoice generation. It must implement `set_timesteps` and `step` methods, and have a `timesteps` attribute.g      ð?)ÚpoprS   Ú_prepare_generation_configÚgetattrÚ_build_default_noise_schedulerÚ
ValueErrorÚhasattrÚtyper*   rh   rf   rg   Úguidance_scale)	r@   rb   r\   rf   rg   Únoise_scheduler_kwargÚmodel_kwargsrh   r_   s	   &&,     €r%   rm   Ú3VibeVoiceGenerationMixin._prepare_generation_configf   sL  ø€ ð  "Ÿ:™:Ð&8¸%Ó@ÐØ$Ÿj™jÐ)>ÀÓEÐØ &§
¡
Ð+<¸dÓ CÐä*/©'Ò*LÐM^Ñ*iÐbhÑ*iÑ'Ðð 0×fÐf´7Ð;LÐN_ÐaeÓ3fˆØÒ"Ø"×AÑAÐBSÓTˆOØÒ"Üð}óð ô �O _×5Ò5Ü˜¨×0Ò0Ü˜¨×5Ò5äØ0´°oÓ1F×1OÑ1OÐ0Pð Qvð vóð ð -<Ô)Ø-=Ô*à×`Ð`¤7Ð+<Ð>SÐUYÓ#Z×`Ð`Ð^`ð 	Ô-ð ×+Ñ+Ò3Ø/2ÐÔ,Ø Ð.Ð.r(   c                ó    <€ V ^8„  d   QhRS[ /# )r   rb   ©r   )r#   r$   s   "€r%   r&   rP   ž   s   ø€ ÷ 3ñ 3Ñ:Jñ 3r(   c                óè   € \        V R R4      p\        4       '       g   \        RV R24      h^ RIp \        W!4      p\        T RRR	R
R/4      pT! R/ TB #   \         d    \        RT R24      hi ; i)Únoise_scheduler_classÚDPMSolverMultistepSchedulerz(The default VibeVoice noise scheduler (`z�`) requires `diffusers`. Install it with `pip install diffusers`, or pass a custom `noise_scheduler` instance to `generate(...)`.Nz Could not find noise scheduler `zŒ` in `diffusers`. Set `noise_scheduler_class` on the generation config to a valid `diffusers` scheduler, or pass a custom `noise_scheduler`.Únoise_scheduler_configÚbeta_scheduleÚsquaredcos_cap_v2Úprediction_typeÚv_predictionr)   )rn   r   ÚImportErrorÚ	diffusersÚAttributeErrorrp   )rb   Úscheduler_class_namer‚   Úscheduler_classÚscheduler_configs   &    r%   ro   Ú7VibeVoiceGenerationMixin._build_default_noise_scheduler�   sº   € ä&Ð'8Ð:QÐSpÓqÐä%×'Ò'ÜØ:Ð;OÐ:Pð Qpð póð ó
 	ð	Ü% iÓFˆOô #ØØ$ØÐ1Ð3DÀnÐUó
Ðñ
 Ñ2Ð!1Ñ2Ð2øô ô 	ÜØ2Ð3GÐ2Hð Iqð qóð ð	ús   ²A ÁA1c          
      óp   <€ V ^8„  d   QhRS[ RS[RS[P                  RS[S[P
                  S[3,          /# )r   Ú
batch_sizerb   r8   rF   )r9   r   r!   r8   rc   rG   rd   )r#   r$   s   "€r%   r&   rP   ·   sG   ø€ ÷ ;9ñ ;9áð;9ñ ,ð;9ñ —‘ð	;9ñ
 
‰u×Ñ¡Ð%Õ	&ñ;9r(   c           	     óä  € R\         P                  ! V^3V P                  P                  \         P                  VR7      R\         P
                  ! V^3\         P                  VR7      /pV P                  ! V3/ VB w  rVV P                  RW`P                  P                  R7      w   rvV P                  VRVR7       VR,          pVP                  R4      RJ ;'       d    VP                  RJp	VP                  R	4      RJ ;'       d    VP                  RJp
V P                  VV	V
RVR,          VP                  ^,          R
7      pV P                  VVRVVP                  ^,
          RR7       W†3# )a!  
Set up the unconditional branch used for classifier-free guidance (CFG).

This mirrors the positive branch's own setup in `generate`/`_sample` (resolve the generation config,
prepare the model inputs and KV cache), applied to the negative branch. See the class docstring for the
original implementation.

Returns the initial negative `input_ids` and prepared `model_kwargs` for the negative pass.
The negative sequence starts with a single `audio_bos_token_id` token and its KV cache is
sized to match the positive generation's maximum length.
rD   ©Údtyper8   Úattention_maskN)ru   Úbos_token_idTrR   Ú
max_lengthÚ
min_length)rb   Úhas_default_max_lengthÚhas_default_min_lengthÚmodel_input_nameÚinputs_tensorÚinput_ids_lengthÚ#_previous_max_negative_cache_length)Úmax_length_attr_name)r!   r<   rU   rV   ÚlongÚonesrm   Ú_prepare_model_inputsÚ_prepare_special_tokensÚgetr�   r�   Ú_prepare_generated_lengthÚshapeÚ_prepare_cache_for_generation)r@   r‰   rb   r8   Únegative_kwargsÚnegative_generation_configÚnegative_model_kwargsÚ_Únegative_input_idsÚnegative_has_default_max_lengthÚnegative_has_default_min_lengths   &&&&       r%   Ú_prepare_negative_generationÚ5VibeVoiceGenerationMixin._prepare_negative_generation·   s–  € ð& œŸš Z° O°T·[±[×5SÑ5SÔ[`×[eÑ[eÐntÔuØœeŸjšj¨*°a¨ÄÇ
Á
ÐSYÔZð
ˆð
 =A×<[Ò<[Øñ=
Ø!0ñ=
Ñ9Ð"ð '+×&@Ñ&@ØÐ4Ç;Á;×CaÑCað 'Aó '
Ñ#ˆˆ1ð 	×$Ñ$Ð%?ÀÈfÐ$ÔUØ,¨[Õ9Ðà×Ñ Ó-°Ð5×kÐkÐ:T×:_Ñ:_ÐgkÐ:kð 	(ð ×Ñ Ó-°Ð5×kÐkÐ:T×:_Ñ:_ÐgkÐ:kð 	(ð &*×%CÑ%CØ8Ø#BØ#BØ(Ø)¨+Õ6Ø/×5Ñ5°aÕ8ð &Dó &
Ð"ð 	×*Ñ*Ø&Ø!ØØØ&×1Ñ1°AÕ5Ø!Fð 	+ô 	
ð "Ð8Ð8r(   c                óB   <€ V ^8„  d   QhRS[ RS[RS[RS[RS[RS[RR/# )	r   rb   ru   Úgeneration_moder‰   Úmax_cache_lengthr—   rF   N)r   rd   r   r9   Ústr)r#   r$   s   "€r%   r&   rP   ô   sc   ø€ ÷ BLñ BLá+ðBLñ ðBLñ ð	BLñ
 ðBLñ ðBLñ "ðBLð 
ñBLr(   c                ól  € RpVP                  V4      pVeA   VP                  e   \        RV R24      h\        V\        4      '       d   \        R4      hR# VP
                  RJ d   R# VP                  \        9   dy   VP                  e   \        WQP                  4      p\        VP                  VP                  4      V,          p	V P                  VP                  V	VVP                  VR7      W'&   R# VP                  R8X  dl   VP                  e   VP                  M/ p
V
P                  R	V P                  P!                  R
R7      4       V
P#                  RR4      p\%        RRV/V
B W'&   R# R	V P                  P!                  R
R7      /pVP                  R8X  d   R
VR&   \'        R/ VB W'&   R# )a½  
This method overrides [~generation.utils.GenerationMixin._prepare_cache_for_generation].

The base implementation memorizes the longest static cache length requested so far on the fixed
`self._previous_max_cache_length` attribute, so that later calls are served by a cache of that same shape
(avoiding a `torch.compile` recompilation). VibeVoice runs a second, independent generation pass for the
classifier-free guidance negative branch, whose cache is much shorter than the positive branch's (the
negative branch starts from a single token instead of the full prompt). The added `max_length_attr_name`
argument lets the caller pick which attribute holds that memo (`"_previous_max_cache_length"` for the
positive branch, `"_previous_max_negative_cache_length"` for the negative one), so the negative cache is
not over-allocated to the positive branch's length. Only the code paths exercised by VibeVoice are kept:
decoder-only dynamic and static caches.
Úpast_key_valuesNzMPassing both `cache_implementation` (used to initialize certain caches) and `zB` (a Cache object) is unsupported. Please use only one of the two.z]Passing a tuple of `past_key_values` is not supported anymore. Please use a `Cache` instance.F)Úcache_implementationr‰   Úmax_cache_lenÚprefill_chunk_sizer—   Ú	quantizedrU   T©ÚdecoderÚbackendÚquantoÚ	offloadedÚ
offloadingr)   )rœ   r¯   rp   Ú
isinstancerc   Ú	use_cacher   r°   ÚmaxÚ	num_beamsÚnum_return_sequencesÚ_prepare_static_cacher±   Úcache_configÚ
setdefaultrU   Úget_text_configrl   r	   r   )r@   rb   ru   rª   r‰   r«   r—   Ú
cache_nameÚuser_defined_cacheÚcache_batch_sizer¿   rµ   Údynamic_cache_kwargss   &&&&&&&      r%   rŸ   Ú6VibeVoiceGenerationMixin._prepare_cache_for_generationô   sË  € ð, 'ˆ
ð *×-Ñ-¨jÓ9ÐØÒ)Ø ×5Ñ5ÒAÜ ØcÐdnÐcoð pTð Tóð ô Ð,¬e×4Ò4Ü Øsóð ñ ð ×&Ñ&¨%Ó/Ùà×1Ñ1Ô5UÔUð !×.Ñ.Ò:Ü#&Ð'7×9XÑ9XÓ#YÐ Ü"Ð#4×#>Ñ#>Ð@Q×@fÑ@fÓgÐjtÕtÐØ'+×'AÑ'AØ%6×%KÑ%KØ+Ø.Ø#4×#GÑ#GØ%9ð (Bó (ˆLÓ$ð ×3Ñ3°{ÔBØ=N×=[Ñ=[Ò=gÐ,×9Ò9ÐmoˆLØ×#Ñ# H¨d¯k©k×.IÑ.IÐRVÐ.IÓ.WÔXØ"×&Ñ& y°(Ó;ˆGÜ'5Ñ'V¸gÐ'VÈÑ'VˆLÓ$ð %-¨d¯k©k×.IÑ.IÐRVÐ.IÓ.WÐ#XÐ Ø ×5Ñ5¸ÔDØ59Ð$ \Ñ2Ü'3Ñ'KÐ6JÑ'KˆLÓ$r(   c                óL   <€ V ^8„  d   QhRS[ RS[RS[RS[R,          RS[ RS[/# )r   r¯   r‰   r°   r±   Nr—   rF   )r¬   r9   r   )r#   r$   s   "€r%   r&   rP   8  sK   ø€ ÷ ,ñ ,á!ð,ñ ð,ñ ð	,ñ
   $�Jð,ñ "ð,ñ 
ñ,r(   c                ó2  € RV9   p\        WR4      p\        W74      p\        V P                  P	                  RR7      VVR7      p	VeC   V P                  4       p
V
e/   V
w  r¼V	P                  VVVV P                  V P                  R7       \        WV4       V	# )a/  
This method overrides [~generation.utils.GenerationMixin._prepare_static_cache].

Same behavior as the base method (a fresh `StaticCache` per call, sized to the longest length requested so
far so that `torch.compile` does not recompile on later calls), except the memorized length is stored under
the attribute named by `max_length_attr_name` instead of always `self._previous_max_cache_length`. This lets
the CFG negative branch track its own (much shorter) length. Only the decoder-only path used by VibeVoice
is kept.

Returns the resulting cache object.
r·   Tr³   )rU   r°   r¸   )r‰   Ú	num_headsÚhead_dimrŒ   r8   éÿÿÿÿ)
rn   r»   r   rU   rÁ   Ú_get_static_cache_init_shapeÚearly_initializationrŒ   r8   Úsetattr)r@   r¯   r‰   r°   r±   r—   Úoffload_cacheÚprevious_max_lenÚeffective_lengthÚcacheÚ
init_shaperÉ   rÊ   s   &&&&&&       r%   r¾   Ú.VibeVoiceGenerationMixin._prepare_static_cache8  s®   € ð& $Ð';Ñ;ˆÜ" 4¸rÓBÐÜ˜}Ó?ÐäØ—;‘;×.Ñ.°tÐ.Ó<Ø*Ø$ô
ˆð
 Ò)ð ×:Ñ:Ó<ˆJØÒ%Ø&0Ñ#�	Ø×*Ñ*Ø)Ø'Ø%ØŸ*™*ØŸ;™;ð +ô ô 	�Ð,<Ô=Øˆr(   c                ó.   <€ V ^8„  d   QhRS[ R,          /# )r   Úcompile_configNrx   )r#   r$   s   "€r%   r&   rP   f  s   ø€ ÷ ,ñ ,Ñ:JÈTÕ:Qñ ,r(   c                ó
  € T;'       g    V P                  4       p\        V R4      '       d   \        V RR4      V8w  d;   Wn        \        P
                  ! V P                  3/ VP                  4       B V n        V P                  # )aU  
Return a `torch.compile`'d version of `self.__call__` dedicated to the CFG negative branch.

This mirrors [`~PreTrainedModel.get_compiled_call`] but stores the compiled callable under a
separate attribute (`self._negative_compiled_call`). The negative branch keeps its own
`StaticCache`, with a different length than the positive branch's.
Ú_negative_compiled_callÚ_last_negative_compile_configN)	Ú_default_compile_configrq   rn   rÙ   r!   ÚcompilerK   Úto_dictrØ   )r@   rÖ   s   &&r%   Ú_get_negative_compiled_callÚ4VibeVoiceGenerationMixin._get_negative_compiled_callf  so   € ð (×IÐI¨4×+GÑ+GÓ+Iˆä˜Ð7×8Ò8Ü�tÐ<¸dÓCÀ~ÔUà1?Ô.Ü+0¯=ª=¸¿¹Ñ+cÈ.×J`ÑJ`ÓJbÑ+cˆDÔ(Ø×+Ñ+Ð+r(   c                óX   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RR/# )r   Údiffusion_start_maskr¤   r¢   rF   N)r!   ÚTensorrG   rd   )r#   r$   s   "€r%   r&   rP   w  s=   ø€ ÷ $ñ $á#Ÿl™lð$ñ "×,Ñ,ð$ñ  $ð	$ð
 
ñ$r(   c           
     óÆ  € VR,          p\         P                  ! V4      p^VR&   \         P                  ! VP                  R4      WT4      VR&   VR,          p\         P                  ! V\         P                  ! W`P
                  P                  4      V4      VR&   VP                  R4      Ee4   VP                  R^^^4      pVR,          P                   EF  p\        V\        4      '       d   K  VP                  f   K,  VP                  f   K<  VP                  VP                  P                  4      p	\         P                  ! W˜P                  R,          VP                  RRRR1R3,          4      VP                  RRRR1R3&   \         P                  ! W˜P                  R,          VP                  RRRR1R3,          4      VP                  RRRR1R3&   EK  	  R# R# )z²
When `audio_bos_token_id` is generated for a subset of sequences, reset those sequences'
negative KV cache to a single-token context so the unconditional CFG pass starts fresh.
r�   ºNNNr®   NrË   )rã   rË   )rã   rã   :r   é   Nrã   )r!   Ú
zeros_likeÚwhereÚ	unsqueezeÚ	full_likerU   rV   rœ   ÚviewÚlayersr¹   r
   ÚkeysÚvaluesr>   r8   )
r@   rà   r¤   r¢   r�   Úreset_attention_maskÚlast_input_idÚmask_4dÚlayerÚlayer_mask_4ds
   &&&&      r%   Ú%_reset_negative_cache_for_audio_startÚ>VibeVoiceGenerationMixin._reset_negative_cache_for_audio_startw  s�  € ð /Ð/?Õ@ˆä$×/Ò/°Ó?ÐØ&'Ð˜UÑ#ä27·+²+Ø ×*Ñ*¨2Ó.Ð0Dó3
ÐÐ.Ñ/ð +¨5Õ1ˆä$)§K¢KØ ¤%§/¢/°-ÇÁ×A_ÑA_Ó"`Ðboó%
Ð˜5Ñ!ð !×$Ñ$Ð%6Ó7ÓCØ*×/Ñ/°°A°q¸!Ó<ˆGà.Ð/@ÕA×HÕH�Ü˜e¤^×4Ò4ÙØ—:‘:Ô)¨e¯l©lÔ.FØ$+§J¡J¨u¯z©z×/@Ñ/@Ó$A�MÜ/4¯{ª{Ø%§z¡z°,Õ'?ÀÇÁÈAÈqÐRTÑRUÐWXÈLÕAYó0�E—J‘J˜q ! R¡S¨!˜|Ñ,ô 27·²Ø%§|¡|°LÕ'AÀ5Ç<Á<ÐPQÐSTÐVXÑVYÐ[\ÐP\ÕC]ó2�E—L‘L  A r¡s¨A Ô.ó Iñ Dr(   c                ó¢   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  R,          RS[ P                  RS[RS[RS[/# )	r   Údiffusion_maskÚnext_tokensÚinputs_embedsNr¤   r¢   Únegative_forwardrF   )r!   rá   rG   r"   rd   r   rc   )r#   r$   s   "€r%   r&   rP   �  su   ø€ ÷ $Mñ $MáŸ™ð$Mñ ×%Ñ%ð$Mñ ×(Ñ(¨4Õ/ð	$Mñ
 "×,Ñ,ð$Mñ  $ð$Mñ #ð$Mñ 
ñ$Mr(   c                óZ  € VP                  RR4      pV'       d   ^MRpV P                  ! V3RV/VB p	V	P                  R4      f   Ve
   W9R&   RV	R&   V! R/ V	BRR/B p
V
P                  VRR3,          pV P                  W¥R	R
7      p\        P
                  ! WBR,          .RR7      pW´V3# )a¾  
Advance the negative (unconditional) CFG branch by one step.

This mirrors the positive branch's per-step logic in `_sample`: build the model inputs with
`prepare_inputs_for_generation`, run the forward pass, advance the cache/kwargs with
`_update_model_kwargs_for_generation`, and append the new token. It is run here as a separate branch with
its own `negative_input_ids` and KV cache. See the class docstring for the original implementation.
rº   TNÚnext_sequence_lengthr÷   rD   Úreturn_dictrã   F©Úis_encoder_decoder©Údimr)   rË   ©rã   N)rœ   Úprepare_inputs_for_generationÚlast_hidden_stateÚ#_update_model_kwargs_for_generationr!   Úcat)r@   rõ   rö   r÷   r¤   r¢   rø   rº   rú   Únegative_model_inputsÚnegative_outputsÚnegative_conditions   &&&&&&&     r%   Ú_step_negative_branchÚ.VibeVoiceGenerationMixin._step_negative_branch�  sã   € ð" *×-Ñ-¨k¸4Ó@ˆ	ß$-™q°4Ðà $× BÒ BØñ!
Ø5Ið!
ØMbñ!
Ðð !×$Ñ$ _Ó5Ò=À-ÒB[Ø5B /Ñ2Ø15Ð! +Ñ.á+ÑVÐ.CÑVÐQUÒVÐØ-×?Ñ?ÀÐPRÐTUÐ@UÕVÐà $× HÑ HØÈð !Ió !
Ðô #ŸYšYÐ(:ÈÕ<PÐ'QÐWYÔZÐØ!Ð7LÐLÐLr(   c                óz   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RS[RS[RS[ P                  /# )r   Úpositive_conditionr  rh   rg   rs   rF   )r!   r"   r   r9   r=   )r#   r$   s   "€r%   r&   rP   Ã  sY   ø€ ÷ 6ñ 6á!×-Ñ-ð6ñ "×-Ñ-ð6ñ ð	6ñ
 !ð6ñ ð6ñ 
×	Ñ	ñ6r(   c                ó   € \        V P                  P                  P                  4       4      P                  p\
        P                  ! W.^ R7      P                  V4      p\
        P                  ! VP                  ^ ,          V P                  P                  P                  4      P                  V4      pVP                  VR7       \        V4      ^,          p	VP                   FÓ  p
\
        P                  ! VRV	 VRV	 .^ R7      pV P                  P                  WºP!                  VP                  ^ ,          4      P                  V4      VR7      p\
        P"                  ! WÉ^ R7      w  rÞWåWÞ,
          ,          ,           p\
        P                  ! Wÿ.^ R7      pVP%                  WÊV4      P&                  pKÕ  	  VRV	 P)                  ^4      # )a  
Run the diffusion denoising loop with classifier-free guidance. Adapted from `sample_speech_tokens` in the
original implementation: https://github.com/vibevoice-community/VibeVoice/blob/07cb79feadd2d3fd7f47530d4c964a12857936a0/vibevoice/modular/modeling_vibevoice_inference.py#L700
rþ   )Únum_inference_stepsN)Ú	condition)ÚnextÚmodelÚdiffusion_headÚ
parametersr8   r!   r  r>   Úrandnrž   rU   Úaudio_configÚhidden_sizeri   Úlenrk   ÚrepeatÚsplitrj   Úprev_samplerç   )r@   r  r  rh   rg   rs   Údiffusion_head_devicer  Únoisy_audio_latentÚhalfÚtimestepÚcombinedÚepsÚcond_epsÚ
uncond_epsÚ
guided_epss   &&&&&&          r%   Ú_sample_audio_latentÚ-VibeVoiceGenerationMixin._sample_audio_latentÃ  s€  € ô !% T§Z¡Z×%>Ñ%>×%IÑ%IÓ%KÓ L× SÑ SÐÜ—I’IÐ1ÐFÈAÔN×QÑQÐRgÓhˆ	Ü"Ÿ[š[¨¯©¸Õ);¸T¿[¹[×=UÑ=U×=aÑ=aÓb×eÑeÐfoÓpÐØ×%Ñ%Ð:MÐ%ÔNÜÐ%Ó&¨!Õ+ˆà'×1Ô1ˆHÜ—y’yÐ"4°U°dÐ";Ð=OÐPUÐQUÐ=VÐ!WÐ]^Ô_ˆHØ—*‘*×+Ñ+ØŸ/™/¨(¯.©.¸Õ*;Ó<×?Ñ?ÀÓIÐU^ð ,ó ˆCô $)§;¢;¨s¸aÔ#@Ñ ˆHà#¸Õ8MÕ&NÕNˆJÜ—)’)˜ZÐ4¸!Ô<ˆCØ!0×!5Ñ!5°cÐEWÓ!X×!dÑ!dÒñ 2ð " % 4Ð(×2Ñ2°1Ó5Ð5r(   c          
      ón   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RS[R,          RS[/# )r   Úaudio_latentrõ   r‰   Úacoustic_cacheNrF   )r!   r"   rá   r9   r   r   )r#   r$   s   "€r%   r&   rP   â  sM   ø€ ÷ 
ñ 
á×'Ñ'ð
ñ Ÿ™ð
ñ ð	
ñ
 EÀtÕKð
ñ 
ñ
r(   c                óR  € WP                   P                  P                  VP                  4      ,          V P                   P                  P                  VP                  4      ,
          pVP                  4       '       gS   \        P                  ! V.VP                  R,          O5!  P                  VP                  VP                  4      pWVV&   MTpV P                   P                  P                  VP                  V P                   P                  P                  4      VRR7      # )z+Decode `audio_latent` to an audio waveform.:rä   NNT©Úpadding_cacherº   )r  Úlatent_scaling_factorr>   r8   Úlatent_bias_factorÚallr!   Úzerosrž   rŒ   Úaudio_towerÚdecode)r@   r&  rõ   r‰   r'  Úscaled_latentÚpadded_latents   &&&&&  r%   Ú_decode_audio_latentÚ-VibeVoiceGenerationMixin._decode_audio_latentâ  sð   € ð %§z¡z×'GÑ'G×'JÑ'JØ×Ñó(
õ 
à�J‰J×)Ñ)×,Ñ,¨\×-@Ñ-@ÓAõBˆð ×!Ñ!×#Ò#Ü!ŸKšK¨
ÐM°]×5HÑ5HÈÕ5LÓM×PÑPØ×$Ñ$ m×&9Ñ&9óˆMð -:˜.Ò)à)ˆMØ�z‰z×%Ñ%×,Ñ,Ø×Ñ˜TŸZ™Z×3Ñ3×:Ñ:Ó;Ø(Øð -ó 
ð 	
r(   c                óŠ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[RS[RS[R,          RS[S[ P                  ,          /# )	r   rD   Úlogits_processorÚstopping_criteriarb   Úsynced_gpusÚstreamerr   rF   )r!   rG   r   r   r   Úboolr   r   )r#   r$   s   "€r%   r&   rP   ú  sp   ø€ ÷ r#ñ r#á×#Ñ#ðr#ñ .ðr#ñ 0ð	r#ñ
 ,ðr#ñ ðr#ñ ˜>Õ*ðr#ñ 
¡×!1Ñ!1Õ	1ñr#r(   c           
     óÔ  a€ VP                   pVP                  p	VP                  p
VP                  pVP                  pVP
                  p\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      pVP                  pV'       d   V'       d   RMRpV'       d   V'       d   RMRpV'       d   V	'       d   RMRpV'       d   V
'       d   RMRpVP                  ^ ,          pRp\        P                  ! V\        P                  VP                  R7      pVe   VP                  VP                  4      pV P                  SV4      '       d   V P                  VP                   4      MV P"                  pRpV P%                  VVSVP&                  '       * R7      pVP(                  pVP*                  pVP,                  pV'       d   \.        P1                  R4       RRRppp\3        V4       U u. uF  p . NK  	  p!p VP                  ^,          p"V P5                  VWAP                  R7      w  p#p$V P                  SV4      '       d   V P7                  VP                   4      MV P"                  p%VP                  R,          p&SR	,          P9                  RR
7      p'\        P:                  ! VP<                  V',
          \        P>                  ! V'VP<                  V&,
          4      4      p(V'       d2   \@        PB                  ! \E        V(PG                  4       4      RRR7      p)MRp)V PI                  VWQP                  R7      '       Edœ   V)e   V)PK                  ^4       V'       d   SR,          '       d   ^MRp*V PL                  ! V3RV*/SB p+V+PO                  RR4       V+PO                  RR4       VV+R&   V PQ                  4       ;_uu_ 4        V! R/ V+BRR/B pRRR4       RpV PS                  XSV PT                  PV                  R7      oV'       d   V'       d   Kû  VPX                  R,          P                  R\        PZ                  VP                  R7      p,V! VV,4      p-V'       d]   V'       d   VV-3,          pV'       d   VV,3,          pV	'       d   VVP\                  3,          pV
'       d   VVP^                  3,          p\        P`                  ! V-RR
7      p.V'       d   V.V,          V^V,
          ,          ,           p.\        Pb                  ! VV.R,          .RR
7      pVe    VPe                  V.Pg                  4       4       V Pi                  4       ! V.4      Pk                  ^4      p/VPm                  4       V.V PT                  Pn                  8H  ,          p0V Pq                  V0V#V$4       VPm                  4       V.V PT                  Pr                  8H  ,          p1V1P                  4       '       Ed»   V Pu                  V1V.VV#V$V%4      w  p2p#p$VPv                  V1RR3,          p3V Py                  V3V2VVVPz                  4      p4V P}                  V4V1VV4      p5V5P~                  p\�        V1Pƒ                  RR7      P…                  R4      4       F=  w  p6p7V!V7P‡                  4       ,          P‰                  V5PŠ                  V6,          4       K?  	  V PŒ                  P�                  V5PŠ                  VRR7      p8V8P�                  V1P                  V8P�                  P                  4      ,          p9V PŒ                  P“                  V44      p:V PŒ                  P•                  V94      p;V:V;P                  V:P                  4      ,           p<V<P                  V/P                  4      V/V1&   V8P~                  pT/pV"^,          p"VV! VV4      ( ,          pVPG                  4       ^ 8H  p?EK¿  V)e   V)P—                  4        Ve   VP™                  4        V! U=u. uF%  p=V='       d   \        Pb                  ! V=RR
7      MRNK'  	  p>p=V'       d   Rp?\        ;QJ d#    V3R l\š         4       F  '       g   K   RM	  RM! V3R l\š         4       4      '       d#   \�        V3R l\š         4       4      p@SV@,          p?\Ÿ        VVVVVV?V>R7      # V># u up i   + '       g   i     EL÷; iu up=i ) z™
This method overrides [~generation.utils.GenerationMixin._sample].
To ease maintenance, modifications are marked with the comment "VibeVoice specific".
c              3   ó:   "  € T F  p\        VR 4      x € K  	  R# 5i)rY   N)rq   )Ú.0Úcriterias   & r%   Ú	<genexpr>Ú3VibeVoiceGenerationMixin._sample.<locals>.<genexpr>  s   é € Ð'lÑZkÈh¬°¸.×(IÐ(IÓZkùs   ‚TFNr‹   )Úis_first_iterationzˆVibeVoice generation does not support sampling-based token selection. Tokens will be selected using argmax regardless of do_sample=True.rR   r�   rþ   zGenerating audioz tokens)ÚtotalÚdescÚunitrº   rú   Úinput_valuesÚpadding_maskr÷   rû   rü   rã   )ÚcopyrŒ   r8   )Úas_tupler)  c              3   ó,   <"  € T F	  qS9   x € K  	  R # 5irI   r)   ©r=  Ú	cache_keyru   s   & €r%   r?  r@  Ü  s   øé € ÐN¹o° Ö,»oùs   ƒc              3   ó8   <"  € T F  qS9   g   K  Vx € K  	  R # 5irI   r)   rJ  s   & €r%   r?  r@  Ý  s   øé € Ð i¹O¨yÐ\hÑOh§¢»Oùs   ƒ�
)Ú	sequencesrE   ÚlogitsÚ
attentionsÚhidden_statesr®   r   r)   rË   )rã   rË   rã   r   )PÚ_pad_token_tensorÚoutput_attentionsÚoutput_hidden_statesÚoutput_scoresÚoutput_logitsÚreturn_dict_in_generateÚanyÚ	do_samplerž   r!   r™   r˜   r8   r>   Ú_valid_auto_compile_criteriaÚget_compiled_callrÖ   rK   Ú_prefillÚis_assistantrh   rf   rg   ÚloggerÚwarning_onceÚranger§   rÝ   ÚsumÚminr�   rè   r   Útqdmr9   r»   Ú_has_unfinished_sequencesÚupdater  rl   Ú_optimize_model_for_decoder  rU   rý   rN  Úfloat32rO  rP  Úargmaxr  ÚputÚcpuÚget_input_embeddingsrç   r:  rV   rò   rX   r  r  r#  rs   r3  r*  Ú	enumerateÚnonzeroré   ÚitemrZ   r   r  Úsemantic_tokenizer_encoderÚlatentsÚmulti_modal_projectorÚsemantic_connectorÚcloseÚendr   r  r   )Ar@   rD   r6  r7  rb   r8  r9  ru   Úpad_token_idrR  rS  rT  rU  rV  Úhas_eos_stopping_criteriarX  rE   Ú
raw_logitsÚdecoder_attentionsÚdecoder_hidden_statesr‰   Úthis_peer_finishedÚunfinished_sequencesÚmodel_forwardÚprefill_consumedÚoutputsrh   rf   rg   r'  Úsemantic_cacher÷   r£   Úaudio_chunksÚcur_lenr¤   r¢   rø   Úinitial_lengthÚinitial_length_per_sampleÚmax_step_per_sampleÚprogress_barrú   Úmodel_inputsÚnext_token_logitsÚnext_token_scoresrö   Únext_inputs_embedsrà   rõ   r  r  r&  Úaudio_outputÚiÚ
sample_idxÚsemantic_outputsÚsemantic_featuresÚacoustic_embedÚsemantic_embedÚdiffusion_embedsÚchunksÚgenerated_audiorÒ   rK  sA   &&&&&&&l                                                         r%   Ú_sampleÚ VibeVoiceGenerationMixin._sampleú  s  ø€ ð )×:Ñ:ˆØ-×?Ñ?ÐØ0×EÑEÐØ)×7Ñ7ˆØ)×7Ñ7ˆØ"3×"KÑ"KÐß$'£CÑ'lÑZkÓ'l§C§C¢CÑ'lÑZkÓ'lÓ$lÐ!Ø%×/Ñ/ˆ	÷ 0·M‘Èˆß3¿‘RÈDˆ
ß$;×@Q™RÐX\Ðß'>×CW¡Ð^bÐð —_‘_ QÕ'ˆ
Ø"ÐÜ$Ÿzšz¨*¼E¿J¹JÈy×O_ÑO_Ô`Ðð Ò#Ø'Ÿ?™?¨9×+;Ñ+;Ó<ˆLð ×0Ñ0°Ð?P×QÒQð ×"Ñ"Ð#4×#CÑ#CÔDà—‘ð 	ð !ÐØ—-‘-ØØØØ#4×#AÑ#AÔAð	  ó 
ˆð ,×;Ñ;ˆØ,×=Ñ=ÐØ/×CÑCÐßÜ×ÑðUôð 9=¸dÀD¨˜ˆÜ$)¨*Ô$5Ó6Ñ$5˜q›Ñ$5ˆÐ6Ø—/‘/ !Õ$ˆð 59×4UÑ4UØÐ)×2BÑ2Bð 5Vó 5
Ñ1ÐÐ1ð
 ×0Ñ0°Ð?P×QÒQð ×,Ñ,Ð->×-MÑ-MÔNà—‘ð 	ð #Ÿ™¨Õ,ˆØ$0Ð1AÕ$B×$FÑ$FÈ2Ð$FÓ$NÐ!Ü#ŸišiØ×(Ñ(Ð+DÕDÜ�OŠOÐ5Ð7H×7SÑ7SÐVdÕ7dÓeó
Ð÷ Ü"Ÿ<š<¬cÐ2E×2IÑ2IÓ2KÓ.LÐSeÐluÔv‰LàˆLð ×,Ñ,Ð-?À×UeÑUeÐ,×fÓfàÒ'Ø×#Ñ# AÔ&÷  Ø,8¸×,EÔ,E¡qÈ4Ð$Ø#×AÒAØñ Ø4Hð ØLXñ �ð
 × Ñ  °Ô6à× Ñ  °Ô6Ø0=�˜_Ñ-à×4Ñ4×6Õ6Ù+ÑM¨lÑMÈÒM�G÷ 7à#ÐØ×CÑCØØØ#'§;¡;×#AÑ#Að Dó ˆL÷
 ×1Ùð !(§¡¨xÕ 8× ;Ñ ;ÀÌUÏ]É]Ðcl×csÑcsÐ ;Ó tÐñ !1°Ð<MÓ NÐ÷ 'ß ØÐ0Ð2Õ2�Fß ØÐ#4Ð"6Õ6�Jß$Ø&¨7×+=Ñ+=Ð*?Õ?Ð&ß'Ø)¨g×.CÑ.CÐ-EÕEÐ)ô  Ÿ,š,Ð'8¸bÔAˆK÷ )Ø)Ð,@Õ@À<ÐSTÐWkÕSkÕClÕl�ô Ÿ	š	 9¨k¸'Õ.BÐ"CÈÔLˆIØÒ#Ø—‘˜[Ÿ_™_Ó.Ô/ð "&×!:Ñ!:Ô!<¸[Ó!I×!SÑ!SÐTUÓ!VÐð $8×#<Ñ#<Ó#>À+ÐQU×Q\ÑQ\×QoÑQoÑBoÕ#pÐ Ø×6Ñ6Ð7KÐM_ÐavÔwð 2×6Ñ6Ó8¸KÈ4Ï;É;×KeÑKeÑ<eÕfˆNØ×!Ñ!×#Ó#ØPT×PjÑPjØ"ØØ!Ø&Ø)Ø$óQÑMÐ"Ð$6Ð8Mð &-×%>Ñ%>¸~ÈrÐSTÐ?TÕ%UÐ"Ø#×8Ñ8Ø&Ø&Ø#Ø'Ø%×4Ñ4ó �ð  $×8Ñ8¸À~ÐWaÐcqÓr�Ø!-×!;Ñ!;�Ü%.¨~×/EÑ/EÈuÐ/EÓ/U×/ZÑ/ZÐ[]Ó/^Ö%_‘M�A�zØ  §¡Ó!2Õ3×:Ñ:¸<×;MÑ;MÈaÕ;PÖQñ &`ð $(§:¡:×#HÑ#HØ ×&Ñ&Ø"0Ø"ð $Ió $Ð ð
 %5×$<Ñ$<¸^×=NÑ=NÐO_×OgÑOg×OnÑOnÓ=oÕ$pÐ!Ø!%§¡×!AÑ!AÀ,Ó!O�Ø!%§¡×!>Ñ!>Ð?PÓ!Q�Ø#1°N×4EÑ4EÀn×F[ÑF[Ó4\Õ#\Ð Ø5E×5HÑ5HÐI[×IbÑIbÓ5cÐ" >Ñ2Ø!1×!?Ñ!?�à.ˆMØ�q�LˆGð $8Ñ;LÈYÐX^Ó;_Ð:_Õ#_Ð Ø!5×!9Ñ!9Ó!;¸qÑ!@Ðó ð Ò#Ø×ÑÔ ð ÒØ�L‰LŒNñ XdÓdÑWcÈV¿œ5Ÿ9š9 V°Õ4ÀDÒHÑWcˆÐd÷ #ØˆEß‹sÔN½oÓN�s�sŠsÔN½oÓN×NÒNÜ Ô i½OÓ iÓi�	Ø$ YÕ/�ä*Ø#ØØ!Ø-Ø3Ø %Ø%ôð ð #Ð"ùò] 7÷X 7×6Ð6üòZ es   Ç8cÏcàc%à$c%ãc"	)rÙ   rØ   )Ú_previous_max_cache_length)FN)r*   r+   r,   r-   r.   rT   rm   Ústaticmethodro   r§   rŸ   r¾   rÝ   rò   r  r#  r3  r“  r0   r1   Ú__classcell__)r_   r$   s   @@r%   rN   rN   O   s    ù‡ € ñ	÷	ó 	÷5/ó 5/ðn ÷3ó ð3÷2;9ð ;9÷zBLò BL÷H,ò ,÷\,ð ,÷"$ð $÷L$Mð $M÷L6ð 6÷>
ð 
÷0r#÷ r#ò r#r(   rN   )+Úcollections.abcr   Údataclassesr   Útypingr   r   r   r!   Úcache_utilsr   r	   r
   r   Ú
generationr   r   r   r   r   Úgeneration.configuration_utilsr   Úgeneration.logits_processr   Úgeneration.stopping_criteriar   Úgeneration.utilsr   r   Úutilsr   r   r   ÚBvibevoice_acoustic_tokenizer.modeling_vibevoice_acoustic_tokenizerr   Úgeneration.streamersr   Ú
get_loggerr*   r]  r   r4   rN   r)   r(   r%   Ú<module>r¥     s�   ðõ %Ý !ß /Ñ /ã ç TÓ T÷õ õ OÝ JÝ @ß Fß JÑ Jõ÷
 Ý4ð 
×	Ò	˜HÓ	%€ð ô	1Ð7ó 	1ó ð	1ô)¨ô )ô(]
#˜ö ]
#r(   