+
    œ°³jm ã                   óê  € R t ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^RI	H
t ^RIHtHt ^RIHt ^RIHtHtHt ^RIHt ^R	IHtHt ^R
IHt ^RIHtHt ^RIH t  ^RI!H"t"H#t#H$t$H%t% ^RI&H't' ^RI(H)t)H*t*H+t+H,t,H-t- ^RI.H/t/H0t0H1t1 ]! 4       '       d   ^RI2H3t3 ^RIH4t4 ]%Pj                  ! ]64      t7 ! R R]Pp                  4      t9 ! R R]94      t:R]9R]:/t; ! R R]Pp                  4      t< ! R R]4      t=]" ! R R] 4      4       t> ! R R ]>]4      t?]"! R!R"7       ! R# R$]?4      4       t@]"! R%R"7       ! R& R']?4      4       tA]"! R(R"7       ! R) R*]>4      4       tB]"! R+R"7       ! R, R-]>]4      4       tC. R.OtDR# )/zPyTorch BARK model.N)Únn)Ú
functional)Úinitialization)ÚCacheÚDynamicCache)ÚGenerationMixin)Ú#AlternatingCodebooksLogitsProcessorÚ!BarkEosPrioritizerLogitsProcessorÚSuppressTokensLogitsProcessor)Úcreate_bidirectional_mask)Ú!flash_attn_supports_top_left_maskÚis_flash_attn_available)ÚGradientCheckpointingLayer)ÚCausalLMOutputWithPastÚMaskedLMOutput)ÚPreTrainedModel)Úauto_docstringÚis_accelerate_availableÚis_torch_accelerator_availableÚlogging)Ú	AutoModel)ÚBarkCoarseConfigÚ
BarkConfigÚBarkFineConfigÚBarkSemanticConfigÚBarkSubModelConfig)ÚBarkCoarseGenerationConfigÚBarkFineGenerationConfigÚBarkSemanticGenerationConfig)Úget_target_dtype)Ú_flash_attention_forwardc                   óV   a a€ ] tR t^At oRV 3R lltR tR tRR ltR	R ltRt	Vt
V ;t# )
ÚBarkSelfAttentionc                óú  <€ \         SV `  4        VP                  V n        \        P                  ! VP                  4      V n        \        P                  ! VP                  4      V n        VP                  V n        VP                  V n	        V P                  V P                  ,          V n
        Wn        VP                  VP                  ,          ^ 8w  d'   \        RV P                   RV P                   R24      h\        P                  ! VP                  ^VP                  ,          VP                  R7      V n        \        P                  ! VP                  VP                  VP                  R7      V n        W n        W0n        V'       dl   VP&                  p\(        P*                  ! \(        P,                  ! WD3\.        R7      4      P1                  ^^WD4      p\        P2                  ! V4      V n        R# R# )é    z;embed_dim must be divisible by num_heads (got `embed_dim`: z and `num_heads`: z).©Úbias©ÚdtypeN)ÚsuperÚ__init__Údropoutr   ÚDropoutÚattn_dropoutÚresid_dropoutÚhidden_sizeÚ	embed_dimÚ	num_headsÚhead_dimÚconfigÚ
ValueErrorÚLinearr&   Úatt_projÚout_projÚ	is_causalÚ	layer_idxÚ
block_sizeÚtorchÚtrilÚonesÚboolÚviewÚBuffer)Úselfr3   r8   r9   r:   r&   Ú	__class__s   &&&&  €Úg/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/bark/modeling_bark.pyr*   ÚBarkSelfAttention.__init__E   sm  ø€ Ü‰ÑÔð —~‘~ˆŒÜŸJšJ v§~¡~Ó6ˆÔÜŸZšZ¨¯©Ó7ˆÔà×+Ñ+ˆŒØ×)Ñ)ˆŒØŸ™¨$¯.©.Õ8ˆŒØŒà×Ñ × 0Ñ 0Õ0°AÔ5ÜØMÈdÏnÉnÐM]ð ^Ø—N‘NÐ# 2ð'óð ô Ÿ	š	 &×"4Ñ"4°a¸&×:LÑ:LÕ6LÐSY×S^ÑS^Ô_ˆŒäŸ	š	 &×"4Ñ"4°f×6HÑ6HÈvÏ{É{Ô[ˆŒà"ŒØ"ŒßØ×*Ñ*ˆJÜ—:’:œeŸjšj¨*Ð)AÌÔNÓO×TÑTÐUVÐXYÐ[eÓrˆDÜŸ	š	 $›ˆDŽIñ ó    c                ó‚   € VP                  4       RR W#3,           pVP                  V4      pVP                  ^ ^^^4      # ©z:
Splits hidden_size dim into attn_head_size and num_heads
Néÿÿÿÿ)Úsizer?   Úpermute©rA   Útensorr1   Úattn_head_sizeÚ	new_shapes   &&&& rC   Ú_split_headsÚBarkSelfAttention._split_headse   sA   € ð —K‘K“M # 2Ð&¨)Ð)DÕDˆ	Ø—‘˜YÓ'ˆØ�~‰~˜a  A qÓ)Ð)rE   c                ó¦   € VP                  ^^4      P                  4       pVP                  VP                  4       RR W#,          3,           4      pV# ©zC
Merges attn_head_size dim and num_attn_heads dim into hidden_size
Néþÿÿÿ)Ú	transposeÚ
contiguousr?   rI   ©rA   rL   r1   rM   s   &&&&rC   Ú_merge_headsÚBarkSelfAttention._merge_headsm   sJ   € ð ×!Ñ! ! QÓ'×2Ñ2Ó4ˆØ—‘˜VŸ[™[›]¨3¨BÐ/°9Õ3MÐ2OÕOÓPˆàˆrE   c                ó¨  € \         P                  ! WP                  RR4      4      R\        P                  ! V P
                  4      ,          ,          pV P                  '       d~   VP                  R4      VP                  R4      rvVP                  V P                  RRWv,
          V1RV13,          ^ 8H  \         P                  ! VP                  4      P                  4      pVe	   WT,           p\        P                  P                  VRR7      pVP!                  VP                  4      pV P#                  V4      p\         P                  ! WS4      pW…3# )é   ç      ð?ºNNNN©ÚdimrH   rS   )r;   ÚmatmulrT   ÚmathÚsqrtr2   r8   rI   Úmasked_fillr&   Úfinfor(   Úminr   r   ÚsoftmaxÚtor-   )	rA   ÚqueryÚkeyÚvalueÚattention_maskÚattn_weightsÚquery_lengthÚ
key_lengthÚattn_outputs	   &&&&&    rC   Ú_attnÚBarkSelfAttention._attny   s
  € ä—|’| E¯=©=¸¸RÓ+@ÓAÀSÌ4Ï9Ê9ÐUY×UbÑUbÓKcÕEcÕdˆà�>�>ˆ>Ø',§z¡z°"£~°s·x±xÀ³|˜*ð (×3Ñ3Ø—	‘	˜!˜Q 
Õ 9¸JÐ FÈÈÈÐSÕTÐXYÑYÜ—’˜L×.Ñ.Ó/×3Ñ3óˆLð
 Ò%à'Õ8ˆLä—}‘}×,Ñ,¨\¸rÐ,ÓBˆØ#—‘ u§{¡{Ó3ˆØ×(Ñ(¨Ó6ˆô —l’l <Ó7ˆàÐ(Ð(rE   c                óF  € V P                  V4      P                  V P                  ^R7      w  rxp	V P                  WpP                  V P
                  4      pV P                  W€P                  V P
                  4      pV P                  W�P                  V P
                  4      p	Ve   VP                  W‰V P                  4      w  r‰V P                  WxW’4      w  r«V P                  W P                  V P
                  4      p
V P                  V
4      p
V P                  V
4      p
W«3# )é   r]   )r6   Úsplitr0   rO   r1   r2   Úupdater9   ro   rW   r7   r.   )rA   Úhidden_statesrj   Úpast_key_valuesÚ	use_cacheÚoutput_attentionsÚkwargsrg   rh   ri   rn   rk   s   &&&&&&,     rC   ÚforwardÚBarkSelfAttention.forward”   sì   € ð !ŸM™M¨-Ó8×>Ñ>¸t¿~¹~ÐSTÐ>ÓUÑˆ�Eà×!Ñ! %¯©¸¿¹ÓGˆØ×Ñ §^¡^°T·]±]ÓCˆØ×!Ñ! %¯©¸¿¹ÓGˆàÒ&Ø(×/Ñ/°¸D¿N¹NÓK‰JˆCà$(§J¡J¨u¸5Ó$QÑ!ˆà×'Ñ'¨·^±^ÀTÇ]Á]ÓSˆØ—m‘m KÓ0ˆØ×(Ñ(¨Ó5ˆàÐ(Ð(rE   )r6   r-   r&   r3   r+   r0   r2   r8   r9   r1   r7   r.   ©FN©N©NNFF)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r*   rO   rW   ro   rz   Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rB   Ú__classdict__s   @@rC   r"   r"   A   s$   ù‡ € ÷(ò@*ò
ô)÷6)ô )rE   r"   c                   óL   a a€ ] tR t^°t oRtV 3R ltR tR tRR ltRt	Vt
V ;t# )ÚBarkSelfFlashAttention2a8  
Bark flash attention module. This module inherits from `BarkSelfAttention` as the weights of the module stays
untouched. The only required change would be on the forward pass where it needs to correctly call the public API of
flash attention and deal with padding tokens in case the input contains any of them.
c                óF   <€ \         SV `  ! V/ VB  \        4       V n        R # r}   )r)   r*   r   Ú_flash_attn_uses_top_left_mask)rA   Úargsry   rB   s   &*,€rC   r*   Ú BarkSelfFlashAttention2.__init__·   s#   ø€ Ü‰Ò˜$Ð) &Ò)ô
 /PÓ.QˆÖ+rE   c                ó^   € VP                  4       RR W#3,           pVP                  V4      pV# rG   )rI   r?   rK   s   &&&& rC   rO   Ú$BarkSelfFlashAttention2._split_heads¿   s3   € ð —K‘K“M # 2Ð&¨)Ð)DÕDˆ	Ø—‘˜YÓ'ˆð ˆrE   c                óf   € VP                  VP                  4       RR W#,          3,           4      pV# rR   )r?   rI   rV   s   &&&&rC   rW   Ú$BarkSelfFlashAttention2._merge_headsÉ   s/   € ð —‘˜VŸ[™[›]¨3¨BÐ/°9Õ3MÐ2OÕOÓPˆØˆrE   c                óè  € VP                  4       w  rxp	V P                  V4      P                  V P                  ^R7      w  r«pV P	                  W P
                  V P                  4      p
V P	                  W°P
                  V P                  4      pV P	                  WÀP
                  V P                  4      pVe   VP                  W¼V P                  4      w  r¼\        W 4      p\        T
TTTTV P                  '       d   V P                  MRV P                  V P                  VR7	      pV P                  WàP
                  V P                  4      pV P!                  V4      pV P#                  V4      pVR3# )rr   r]   Ng        )r+   Úuse_top_left_maskr8   Útarget_dtype)rI   r6   rs   r0   rO   r1   r2   rt   r9   r   r    Útrainingr+   r‹   r8   rW   r7   r.   )rA   ru   rj   rv   rw   rx   ry   Ú
batch_sizeÚ	query_lenÚ_rg   rh   ri   r”   rn   s   &&&&&&,        rC   rz   ÚBarkSelfFlashAttention2.forwardÒ   s9  € ð $1×#5Ñ#5Ó#7Ñ ˆ
˜qð !ŸM™M¨-Ó8×>Ñ>¸t¿~¹~ÐSTÐ>ÓUÑˆ�Eà×!Ñ! %¯©¸¿¹ÓGˆØ×Ñ §^¡^°T·]±]ÓCˆØ×!Ñ! %¯©¸¿¹ÓGˆàÒ&Ø(×/Ñ/°¸D¿N¹NÓK‰JˆCä'¨Ó4ˆä.ØØØØØØ$(§M§M M�D—L’L°sØ"×AÑAØ—n‘nØ%ô

ˆð ×'Ñ'¨·^±^ÀTÇ]Á]ÓSˆØ—m‘m KÓ0ˆØ×(Ñ(¨Ó5ˆà˜DÐ Ð rE   )r‹   r~   )r   r€   r�   r‚   Ú__doc__r*   rO   rW   rz   rƒ   r„   r…   r†   s   @@rC   r‰   r‰   °   s$   ù‡ € ñõRòò÷'!ô '!rE   r‰   ÚeagerÚflash_attention_2c                   ó8   a a€ ] tR tRt oV 3R ltR tRtVtV ;t# )ÚBarkMLPi  c                ó®  <€ \         SV `  4        \        P                  ! VP                  ^VP                  ,          VP
                  R7      V n        \        P                  ! ^VP                  ,          VP                  VP
                  R7      V n        \        P                  ! VP                  4      V n	        \        P                  ! 4       V n        R# )é   r%   N)r)   r*   r   r5   r/   r&   Úin_projr7   r,   r+   ÚGELUÚgelu©rA   r3   rB   s   &&€rC   r*   ÚBarkMLP.__init__  s‡   ø€ Ü‰ÑÔÜ—y’y ×!3Ñ!3°Q¸×9KÑ9KÕ5KÐRX×R]ÑR]Ô^ˆŒÜŸ	š	 ! f×&8Ñ&8Õ"8¸&×:LÑ:LÐSY×S^ÑS^Ô_ˆŒÜ—z’z &§.¡.Ó1ˆŒÜ—G’G“IˆŽ	rE   c                óŽ   € V P                  V4      pV P                  V4      pV P                  V4      pV P                  V4      pV# r}   )r¡   r£   r7   r+   )rA   ru   s   &&rC   rz   ÚBarkMLP.forward
  s@   € ØŸ™ ]Ó3ˆØŸ	™	 -Ó0ˆØŸ™ mÓ4ˆØŸ™ ]Ó3ˆØÐrE   )r+   r£   r¡   r7   ©	r   r€   r�   r‚   r*   rz   rƒ   r„   r…   r†   s   @@rC   rž   rž     s   ù‡ € õ÷ò rE   rž   c                   ó@   a a€ ] tR tRt oRV 3R lltRR ltRtVtV ;t# )Ú	BarkBlocki  c                óö  <€ \         SV `  4        V'       dd   \        P                  ! VP                  VP
                  R 7      V n        \        P                  ! VP                  VP
                  R 7      V n        MJ\        P                  ! VP                  4      V n        \        P                  ! VP                  4      V n        \        VP                  ,          ! WVR7      V n
        \        V4      V n        R# )r%   ©r8   r9   N)r)   r*   r   Ú	LayerNormr/   r&   Úlayernorm_1Úlayernorm_2ÚBARK_ATTENTION_CLASSESÚ_attn_implementationÚattnrž   Úmlp)rA   r3   r8   r9   rB   s   &&&&€rC   r*   ÚBarkBlock.__init__  s¤   ø€ Ü‰ÑÔçô  "Ÿ|š|¨F×,>Ñ,>ÀVÇ[Á[ÔQˆDÔÜ!Ÿ|š|¨F×,>Ñ,>ÀVÇ[Á[ÔQˆDÕä!Ÿ|š|¨F×,>Ñ,>Ó?ˆDÔÜ!Ÿ|š|¨F×,>Ñ,>Ó?ˆDÔä*¨6×+FÑ+FÖGØ°9ô
ˆŒ	ô ˜6“?ˆŽrE   c                óä   € V P                  V4      pV P                  VVVVVR 7      pV^ ,          p	VR,          p
W,           pWpP                  V P                  V4      4      ,           pV3V
,           # )©rv   rj   rw   rx   :rZ   NN)r®   r²   r³   r¯   )rA   ru   rv   rj   rw   rx   ry   Úintermediary_hidden_statesÚattn_outputsrn   Úoutputss   &&&&&&,    rC   rz   ÚBarkBlock.forward%  s‰   € ð &*×%5Ñ%5°mÓ%DÐ"à—y‘yØ&Ø+Ø)ØØ/ð !ó 
ˆð # 1•oˆØ˜rÕ"ˆà%2Õ%@Ð"Ø%?Ç(Á(Ø×ÑÐ7Ó8óC
õ &
Ð"ð +Ð,¨wÕ6Ð6rE   )r²   r®   r¯   r³   r|   r~   r¨   r†   s   @@rC   rª   rª     s   ù‡ € ÷#÷$7ô 7rE   rª   c                   óh   a a€ ] tR tRt oRtRt]V3R lV 3R ll4       tV 3R ltV3R lt	Rt
VtV ;t# )	ÚBarkPreTrainedModeliC  FTc                ó4   <€ V ^8„  d   QhRS[ P                  /# ©rr   Úreturn©r;   Údevice)Úformatr‡   s   "€rC   Ú__annotate__Ú BarkPreTrainedModel.__annotate__J  s   ø€ ÷ ñ ™Ÿ™ñ rE   c                ój  <€ \        V R4      '       g   \        SV `  # V P                  4        Fy  p\        VR4      '       g   K  \        VP                  R4      '       g   K5  VP                  P
                  f   KO  \        P                  ! VP                  P
                  4      u # 	  \        SV `  # )úu
`torch.device`: The device on which the module is (assuming that all the module parameters are on the same
device).
Ú_hf_hookÚexecution_device)Úhasattrr)   rÁ   ÚmodulesrÇ   rÈ   r;   ©rA   ÚmodulerB   s   & €rC   rÁ   ÚBarkPreTrainedModel.deviceI  s€   ø€ ô �t˜Z×(Ò(Ü‘7‘>Ð!Ø—l‘l–nˆFä˜ 
×+Ô+Ü˜FŸO™OÐ-?×@Ô@Ø—O‘O×4Ñ4Ô@ä—|’| F§O¡O×$DÑ$DÓEÒEñ %ô ‰w‰~ÐrE   c                óp  <€ \         SV `  V4       \        V\        4      '       d�   VP                  '       d|   VP
                  P                  p\        P                  ! \        P                  ! W"3\        R 7      4      P                  ^^W"4      p\        P                  ! VP                  V4       R# R# R# )r'   N)r)   Ú_init_weightsÚ
isinstancer"   r8   r3   r:   r;   r<   r=   r>   r?   ÚinitÚcopy_r&   )rA   rÌ   r:   r&   rB   s   &&  €rC   rÏ   Ú!BarkPreTrainedModel._init_weights]  sƒ   ø€ Ü‰Ñ˜fÔ%Ü�fÔ/×0Ò0Ø××ÐØ#Ÿ]™]×5Ñ5�
Ü—z’z¤%§*¢*¨jÐ-EÌTÔ"RÓS×XÑXÐYZÐ\]Ð_iÓv�Ü—
’
˜6Ÿ;™;¨Ö-ñ  ñ 1rE   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # ©rr   r3   ©r   )rÂ   r‡   s   "€rC   rÃ   rÄ   C  s   ø‡ ‚ áÑò rE   © )r   r€   r�   r‚   Úsupports_gradient_checkpointingÚ_supports_flash_attnÚpropertyrÁ   rÏ   Ú__annotate_func__rƒ   r„   r…   r†   s   @@rC   r¼   r¼   C  s6   ù‡ € ð ',Ð#ØÐà÷ò ó ðõ&.÷5 … rE   r¼   c                   ót   a a€ ] tR tRt oR
tV 3R ltR tR tR t]	RV3R lR ll4       t
V3R ltR	tVtV ;t# )ÚBarkCausalModelig  c                óÎ  <€ \         SV `  V4       Wn        \        P                  ! VP
                  VP                  4      V n        \        P                  ! VP                  VP                  4      V n	        \        P                  ! VP                  4      V n        \        P                  ! \        VP                  4       Uu. uF  p\!        VR VR7      NK  	  up4      V n        \        P$                  ! VP                  VP&                  R7      V n        \        P*                  ! VP                  VP,                  RR7      V n        RV n        V P3                  4        R# u upi )Tr¬   r%   FN)r)   r*   r3   r   Ú	EmbeddingÚinput_vocab_sizer/   Úinput_embeds_layerr:   Úposition_embeds_layerr,   r+   ÚdropÚ
ModuleListÚrangeÚ
num_layersrª   Úlayersr­   r&   Úlayernorm_finalr5   Úoutput_vocab_sizeÚlm_headÚgradient_checkpointingÚ	post_init)rA   r3   ÚirB   s   && €rC   r*   ÚBarkCausalModel.__init__k  sú   ø€ Ü‰Ñ˜Ô ØŒô #%§,¢,¨v×/FÑ/FÈ×HZÑHZÓ"[ˆÔÜ%'§\¢\°&×2CÑ2CÀV×EWÑEWÓ%XˆÔ"ä—J’J˜vŸ~™~Ó.ˆŒ	ä—m’mÔ]bÐci×ctÑctÔ]uÓ$vÑ]uÐXY¤Y¨vÀÐQR×%SÑ]uÑ$vÓwˆŒä!Ÿ|š|¨F×,>Ñ,>ÀVÇ[Á[ÔQˆÔä—y’y ×!3Ñ!3°V×5MÑ5MÐTYÔZˆŒØ&+ˆÔ#ð 	�‰Öùò %ws   ÃE"c                ó   € R # r}   r×   ©rA   s   &rC   Úget_output_embeddingsÚ%BarkCausalModel.get_output_embeddings  s   € ñ rE   c                ó   € V P                   # r}   ©rá   rð   s   &rC   Úget_input_embeddingsÚ$BarkCausalModel.get_input_embeddings„  s   € Ø×&Ñ&Ð&rE   c                ó   € Wn         R # r}   rô   ©rA   Únew_embeddingss   &&rC   Úset_input_embeddingsÚ$BarkCausalModel.set_input_embeddings‡  s   € Ø"0ÖrE   c                ó€  <€ V ^8„  d   QhRS[ P                  R,          RS[R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[ P                  R,          RS[R,          R	S[R,          R
S[R,          RS[R,          RS[S[ P                  ,          S[,          /# )rr   Ú	input_idsNrv   rj   Úposition_idsÚlabelsÚinputs_embedsrw   rx   Úoutput_hidden_statesÚreturn_dictr¿   )r;   ÚTensorr   Ú
LongTensorr>   Útupler   )rÂ   r‡   s   "€rC   rÃ   ÚBarkCausalModel.__annotate__‹  sØ   ø€ ÷ x
ñ x
á—<‘< $Õ&ðx
ñ  �ðx
ñ Ÿ™ tÕ+ð	x
ñ
 —l‘l TÕ)ðx
ñ × Ñ  4Õ'ðx
ñ —|‘| dÕ*ðx
ñ ˜$•;ðx
ñ   $�;ðx
ñ # T�kðx
ñ ˜D•[ðx
ñ 
‰u�|‰|Õ	Ñ5Õ	5ñx
rE   c           	     ó  € Ve   TMV P                   P                  pV	e   T	MV P                   P                  p	Ve   TMV P                   P                  pV
e   T
MV P                   P                  p
R pVe   \        R4      hVe   Ve   \        R4      hVe   Vf   M&Ve   V P                  V4      pMVe   M\        R4      hVP                  4       R R pVR,          pV P                  '       d2   V P                  '       d    V'       d   \        P                  R4       RpV'       d   Vf   \        V P                   R7      pVe   VP                  4       M^ pVP                  V P                   P"                  P$                  4      pVf^   \&        P(                  ! VWï,           \&        P*                  V P                   P"                  P$                  R7      pVP-                  ^ 4      pVP                  V P                   P"                  P$                  4      pV P!                  V4      p\/        V P                   VVR7      pV P1                  VV,           4      pVVP                  R4      3,           pV'       d   RMR pV	'       d   RMR p\3        V P4                  4       FI  w  ppV	'       d   VV3,           pV! VVVVVR	7      pV^ ,          pV'       g   K8  VV^,          3,           pKK  	  V P7                  V4      pVP9                  V4      pV	'       d   VV3,           pV P;                  V4      pV
'       g7   \<        ;QJ d    . R
 R VVVV3 4       F  NK  	  5# ! R
 R VVVV3 4       4      # \?        VVVVVR7      # )NzXTraining is not implemented yet for Bark - ensure you do not pass `labels` to the model.úDYou cannot specify both input_ids and inputs_embeds at the same timeú5You have to specify either input_ids or inputs_embedszZ`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`...F)r3   ©r(   rÁ   ©r3   r   rj   r¶   c              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5ir}   r×   ©Ú.0Úvs   & rC   Ú	<genexpr>Ú*BarkCausalModel.forward.<locals>.<genexpr>ù  s   é € ð Ùb�a—’Óbùó   ‚Œ
)ÚlossÚlogitsrv   ru   Ú
attentionsrH   r×   ) r3   rx   r  rw   r  ÚNotImplementedErrorr4   rá   rI   rë   r•   ÚloggerÚwarning_oncer   Úget_seq_lengthrf   râ   ÚweightrÁ   r;   ÚarangeÚlongÚ	unsqueezer   rã   Ú	enumeraterç   rè   r?   rê   r  r   )rA   rý   rv   rj   rþ   rÿ   r   rw   rx   r  r  ry   r  Úinput_shapeÚ
seq_lengthÚpast_lengthÚposition_embedsru   Úoutput_shapeÚall_self_attentionsÚall_hidden_statesrí   Úblockr¹   r  s   &&&&&&&&&&&,             rC   rz   ÚBarkCausalModel.forwardŠ  sX  € ð 2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð "+Ò!6‘I¸D¿K¹K×<QÑ<Qˆ	Ø%0Ò%<‘kÀ$Ç+Á+×BYÑBYˆàˆØÒÜ%Øjóð ð Ò  ]Ò%>ÜÐcÓdÐdØÒ&¨?Ò+Bð ØÒ"Ø ×3Ñ3°IÓ>‰MØÒ&ØäÐTÓUÐUà#×(Ñ(Ó*¨3¨BÐ/ˆØ  •_ˆ
à×&×&Ð&¨4¯=¯=¨=ßÜ×#Ñ#Øpôð "�	ç˜Ò0Ü*°$·+±+Ô>ˆOà:IÒ:U�o×4Ñ4Ô6Ð[\ˆØ%×(Ñ(¨×)CÑ)C×)JÑ)J×)QÑ)QÓRˆàÒÜ Ÿ<š<ØØÕ(Ü—j‘jØ×1Ñ1×8Ñ8×?Ñ?ô	ˆLð (×1Ñ1°!Ó4ˆLà#—‘ t×'AÑ'A×'HÑ'H×'OÑ'OÓPˆØ×4Ñ4°\ÓBˆä2Ø—;‘;Ø'Ø)ô
ˆð Ÿ	™	 -°/Õ"AÓBˆØ" m×&8Ñ&8¸Ó&<Ð%>Õ>ˆç$5™b¸4Ðß"6™B¸DÐä! $§+¡+Ö.‰HˆAˆuß#Ø$5¸Ð8HÕ$HÐ!áØØ /Ø-Ø#Ø"3ôˆGð $ A�JˆMç Ñ Ø&9¸WÀQ½Z¸MÕ&IÒ#ñ /ð" ×,Ñ,¨]Ó;ˆà%×*Ñ*¨<Ó8ˆ÷  Ø 1°]Ð4DÕ DÐà—‘˜mÓ,ˆçß”5ñ Ø  &¨/Ð;LÐNaÑbó—5ð �5ñ Ø  &¨/Ð;LÐNaÑbóó ð ô &ØØØ+Ø+Ø*ô
ð 	
rE   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÕ   )r   )rÂ   r‡   s   "€rC   rÃ   r  g  s   ø‡ ‚ ÙÑò rE   )r3   rã   rë   rá   rè   rç   rê   râ   )Úaudio)
NNNNNNNNNN)r   r€   r�   r‚   Úoutput_modalitiesr*   rñ   rõ   rú   r   rz   rÛ   rƒ   r„   r…   r†   s   @@rC   rÝ   rÝ   g  sC   ù‡ € à"Ðõò(ò
'ò1ð ÷x
ñ x
ó ðx
÷I … rE   rÝ   z¯
    Bark semantic (or text) model. It shares the same architecture as the coarse model.
    It is a GPT-2 like autoregressive model with a language modeling head on top.
    )Úcustom_introc                   óR   a a€ ] tR tRt oRtRV3R lV 3R llltV3R ltRtVtV ;t	# )ÚBarkSemanticModeli  Úsemanticc          
      óÈ   <€ V ^8„  d   QhRS[ P                  RS[R,          RS[S[S[ P                  3,          R,          RS[ P                  R,          RS[ P
                  /# )rr   rý   Úsemantic_generation_configNÚhistory_promptrj   r¿   )r;   r  r   ÚdictÚstrr  )rÂ   r‡   s   "€rC   rÃ   ÚBarkSemanticModel.__annotate__  sp   ø€ ÷ fñ fá—<‘<ðfñ %AÀ4Õ$Gðfñ ™S¡%§,¡,Ð.Õ/°$Õ6ð	fñ
 Ÿ™ tÕ+ðfñ 
×	Ñ	ñfrE   c           
     óˆ  <€ Vf   \        R4      hVP                  ^ ,          pVP                  pWP                  ,           pVe2   VP	                  ^V,
          P                  4       VP                  4      pVeN   VR,          V) R p\        P                  P                  V^ V\        V4      ,
          3VP                  RR7      pM=\        P                  ! V3VP                  V P                  \        P                  R7      p\        P                   ! VR,          V^ R7      p\        P"                  ! VP$                  ..V,          \        P                  R7      P'                  V P                  4      p	\        P(                  ! V P+                  VR	RV13,          4      V P+                  VR	RV^,           13,          4      ,           V P+                  V	4      .^R7      p
\-        \/        VP0                  VP                  4      4      pVP3                  \-        \/        VP                  ^,           V P4                  P6                  4      4      4       \9        W±P                  R
7      pVP;                  RVP<                  4      p\?        VP@                  WÑP                  R7      p\B        SV `ˆ  ! \        PF                  ! Wg^,           3\        P                  V P                  R7      3RV
RWÎ.RV/VB pVP;                  RR4      '       d!   VPH                  R	V^,           R13,          pV# VR	V^,           R13,          pV# )a   
Generates text semantic tokens from an input prompt and an additional optional `Bark` speaker prompt.

Args:
    input_ids (`Optional[torch.Tensor]` of shape (batch_size, seq_len), *optional*):
        Input ids, i.e tokenized input sentences. Will be truncated up to
        semantic_generation_config.max_input_semantic_length tokens. Note that the output audios will be as
        long as the longest generation among the batch.
    semantic_generation_config (`BarkSemanticGenerationConfig`):
        Generation config indicating how to generate the semantic tokens.
    history_prompt (`Optional[dict[str,torch.Tensor]]`, *optional*):
        Optional `Bark` speaker prompt.
    attention_mask (`Optional[torch.Tensor]`, *optional*):
        Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:

        - 1 for tokens that are **not masked**,
        - 0 for tokens that are **masked**.

        [What are attention masks?](../glossary#attention-mask)
Returns:
    torch.LongTensor: Output semantic tokens.
Nú/`semantic_generation_config` has to be providedÚsemantic_promptÚconstant)ri   Úmode)rÁ   r(   r]   r'   r\   ©rÁ   Ú	min_eos_p)Úeos_token_idr;  rÁ   r
  r   Úlogits_processorÚgeneration_configÚreturn_dict_in_generateF)%r4   ÚshapeÚmax_input_semantic_lengthÚtext_encoding_offsetrb   r>   Útext_pad_tokenr   r   ÚpadÚlenÚsemantic_pad_tokenr;   ÚfullrÁ   ÚintÚrepeat_interleaverL   Úsemantic_infer_tokenrf   Úcatrá   Úlistrå   Úsemantic_vocab_sizeÚextendr3   ré   r
   Úgetr;  r	   r<  r)   Úgenerater=   Ú	sequences)rA   rý   r0  r1  rj   ry   r–   rA  Úsemantic_historyÚinfer_arrayr   Útokens_to_suppressÚ suppress_tokens_logits_processorr;  Úearly_stopping_logits_processorÚsemantic_outputrB   s   &&&&&,          €rC   rP  ÚBarkSemanticModel.generate  s  ø€ ð< &Ò-ÜÐNÓOÐOà—_‘_ QÕ'ˆ
à$>×$XÑ$XÐ!à× OÑ OÕOˆ	àÒ%Ø!×-Ñ-¨q°>Õ/A×.GÑ.GÓ.IÐKe×KtÑKtÓuˆIàÒ%Ø-Ð.?Õ@ÐB[ÐA[ÐA\Ð]ÐÜ!Ÿ}™}×0Ñ0Ø ØÐ-´Ð4DÓ0EÕEÐFØ0×CÑCØð	  1ó  Ñô  %ŸzšzØ*Ð,Ø*×=Ñ=Ø—{‘{Ü—i‘iô	 Ðô !×2Ò2Ð3CÀDÕ3IÈ:Ð[\Ô]Ðä—l’lØ(×=Ñ=Ð>Ð?À*ÕLÔTY×T]ÑT]ô
ç
‰"ˆT�[‰[‹/ð 	ô Ÿ	š	à×'Ñ'¨	°!Ð5OÐ6OÐ5OÐ2OÕ(PÓQØ×)Ñ)Ð*:¸1Ð>]Ð@YÐ\]Õ@]Ð>]Ð;]Õ*^Ó_õ`à×'Ñ'¨Ó4ðð
 ô
ˆô "ÜÐ,×@Ñ@ÐB\×BoÑBoÓpó
Ðð 	×!Ñ!Ü”Ð1×DÑDÀqÕHÈ$Ï+É+×JgÑJgÓhÓiô	
ô ,IÐI[×dtÑdtÔ+uÐ(à—J‘J˜{Ð,F×,PÑ,PÓQˆ	Ü*KØ3×@Ñ@ÈI×^nÑ^nô+
Ð'ô  ™'Ò*Ü�JŠJ˜
ÀÕ$AÐBÌ%Ï)É)Ð\`×\gÑ\gÔhñ
à'ð
ð ?Ð`ð
ð 9ð	
ð
 ñ
ˆð �:‰:Ð/°×7Ò7Ø-×7Ñ7¸Ð;TÐWXÕ;XÑ;ZÐ8ZÕ[ˆOð Ðð .¨aÐ1JÈQÕ1NÑ1PÐ.PÕQˆOØÐrE   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÕ   )r   )rÂ   r‡   s   "€rC   rÃ   r4    s   ø‡ ‚ ñ Ñò rE   r×   ©NNN)
r   r€   r�   r‚   Úbase_model_prefixrP  rÛ   rƒ   r„   r…   r†   s   @@rC   r-  r-    s    ù‡ € ð #Ð÷fõ f÷ … rE   r-  z½
    Bark coarse acoustics model.
    It shares the same architecture as the semantic (or text) model. It is a GPT-2 like autoregressive model with a
    language modeling head on top.
    c                   óh   a a€ ] tR tRt oRtR	V3R lR lltR
V3R lV 3R llltV3R ltRtVt	V ;t
# )ÚBarkCoarseModeliy  Úcoarse_acousticsc                óv   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[ RS[S[S[P                  3,          R,          /# )rr   Úmax_coarse_historyÚsemantic_to_coarse_ratior–   r0  Úcodebook_sizer1  N)rH  r2  r3  r;   r  )rÂ   r‡   s   "€rC   rÃ   ÚBarkCoarseModel.__annotate__„  sb   ø€ ÷ H4ñ H4áðH4ñ #&ðH4ñ ð	H4ñ
 %(ðH4ñ ðH4ñ ™S¡%§,¡,Ð.Õ/°$Õ6ñH4rE   c           
     ó   € VEeÖ   \         P                  ! VR,          R,          V^ R7      pVR,          P                  4       pVeA   \        ^VP                  ^ ,          4       F  p	W‰R3;;,          WY,          ,          uu&   K!  	  \         P
                  ! V^ ^4      P                  R4      pW„P                  ,           p\         P                  ! VR,          V^ R7      p\        \        P                  ! W,          4      4      p
\        V
VP                  ^,          VP                  ^,          ^,          ,
          \        \        P                  ! VP                  ^,          V,          4      4      .4      p\        \        W²,          4      4      pVRV) R13,          P                  4       pVRV) R13,          P                  4       pVRRR13,          pWx3# \         P                  ! . .V,          \         P                  V P                  R7      p\         P                  ! . .V,          \         P                  V P                  R7      pWx3# )	ao  
Preprocess the optional `Bark` speaker prompts before `self.generate`.

Args:
    max_coarse_history (`int`):
        Maximum size of coarse tokens used.
    semantic_to_coarse_ratio (`int`):
        Ratio of semantic to coarse frequency
    batch_size (`int`):
        Batch size, i.e the number of samples.
    semantic_generation_config (`BarkSemanticGenerationConfig`):
        Generation config indicating how to generate the semantic tokens.
    codebook_size (`int`):
        Codebook channel size, i.e. the size of the output vocabulary per codebook channel.
    history_prompt (`Optional[dict[str,torch.Tensor]]`):
        Optional `Bark` speaker prompt.
Returns:
    `tuple(torch.FloatTensor)`:
    - **x_semantic_history** (`torch.FloatTensor` -- Processed semantic speaker prompt.
    - **x_coarse_history** (`torch.FloatTensor`) -- Processed coarse speaker prompt.
Nr7  r]   Úcoarse_promptr\   r
  rH   rS   )r;   rI  Úclonerå   r@  rT   ÚreshaperM  rH  ÚnpÚfloorrd   ÚroundrL   rÁ   )rA   r`  ra  r–   r0  rb  r1  Úx_semantic_historyÚx_coarse_historyÚnÚmax_semantic_historyÚn_semantic_hist_providedÚn_coarse_hist_provideds   &&&&&&&      rC   Úpreprocess_historiesÚ$BarkCoarseModel.preprocess_histories„  s  € ð< Ó%Ü!&×!8Ò!8¸ÐHYÕ9ZÐ[_Õ9`ÐblÐrsÔ!tÐà-¨oÕ>×DÑDÓFÐð Ò(Ü˜qÐ"2×"8Ñ"8¸Õ";Ö<�Aà$¨ T×*¨mÕ.?Õ?Õ*ñ =ô
  %ŸšÐ/?ÀÀAÓF×NÑNÈrÓRÐà/×2`Ñ2`Õ`Ðä$×6Ò6Ð7GÈÕ7MÈzÐ_`ÔaÐô $'¤r§x¢xÐ0BÕ0]Ó'^Ó#_Ð ä'*à(Ø&×,Ñ,¨QÕ/Ð2D×2JÑ2JÈ1Õ2MÐPQÕ2QÕQÜœŸšÐ!1×!7Ñ!7¸Õ!:Ð=UÕ!UÓVÓWðó(Ð$ô &)¬Ð/GÕ/bÓ)cÓ%dÐ"à!3°AÐ8PÐ7PÑ7QÐ4QÕ!R×!VÑ!VÓ!XÐØ/°Ð4JÐ3JÑ3KÐ0KÕL×PÑPÓRÐà/°°3°B°3°Õ7Ðð "Ð3Ð3ô "'§¢¨r¨d°ZÕ.?ÄuÇyÁyÐY]×YdÑYdÔ!eÐÜ$Ÿ|š|¨R¨D°:Õ,=ÄUÇYÁYÐW[×WbÑWbÔcÐà!Ð3Ð3rE   c                ó  <€ V ^8„  d   QhRS[ P                  RS[R,          RS[R,          RS[RS[S[S[ P                  3,          R,          RS[R,          RS[ P                  S[	S[ P                  S[ P                  3,          ,          /# )	rr   rW  r0  NÚcoarse_generation_configrb  r1  Úreturn_output_lengthsr¿   )
r;   r  r   r   rH  r2  r3  r>   r  r  )rÂ   r‡   s   "€rC   rÃ   rc  Î  s¡   ø€ ÷ Iñ IáŸ™ðIñ %AÀ4Õ$GðIñ #=¸tÕ"Cð	Iñ
 ðIñ ™S¡%§,¡,Ð.Õ/°$Õ6ðIñ  $ d�{ðIñ 
×	Ñ	™E¡%×"2Ñ"2±E×4DÑ4DÐ"DÕEÕ	EñIrE   c                óî  <€ Vf   \        R4      hVf   \        R4      hVP                  pVP                  p	VP                  p
VP	                  WP
                  8H  VP                  4       VP                  VP                  ,          VP                  ,          p\        \        P                  ! W›,          4      4      pWP                  8g  P                  ^4      p\        P                  ! WÛ,          VP                  ,          4      p\        P                  ! WÓP                  ,          4      P                  4       p\        P                   ! V4      P#                  4       pVP$                  ^ ,          pV P'                  VV	VVVVR7      w  ppVP$                  ^,          p\        P(                  ! VV.4      p\        \        P*                  ! Wê,          4      4      p^ pVP$                  ^,          p\-        V4       EFÙ  pV\        \        VV,          4      4      ,           pVR\        P                   ! ^ VV,
          .4      R13,          pVRRV13,          p\.        P0                  ! V^ VVP$                  R,          ,
          3RVP                  4      p\        P(                  ! V\        P2                  ! VP4                  ..V,          V P6                  R7      VRV	) R13,          .4      p\9        VP$                  ^,          VP:                  V4      p\<        SV `|  ! V3RV.R	\A        W®V,
          4      R
V/VB pVP$                  ^,          pVPC                  RR4      '       d/   \        P(                  ! VVPD                  RVR13,          .4      pM#\        P(                  ! VVRVR13,          .4      pVP$                  ^,          V,
          p?EKÜ  	  VRVR13,          pV'       d   VV3# V# )a§  
Generates coarse acoustics tokens from input text semantic tokens and an additional optional `Bark` speaker
prompt.

Args:
    semantic_output (`torch.Tensor` of shape (batch_size, seq_len), *optional*):
        Input text semantic ids, i.e the output of `BarkSemanticModel.generate`.
    semantic_generation_config (`BarkSemanticGenerationConfig`):
        Generation config indicating how to generate the semantic tokens.
    coarse_generation_config (`BarkCoarseGenerationConfig`):
        Generation config indicating how to generate the coarse tokens.
    codebook_size (`int`, *optional*, defaults to 1024):
        Codebook channel size, i.e. the size of the output vocabulary per codebook channel.
    history_prompt (`Optional[dict[str,torch.Tensor]]`, *optional*):
        Optional `Bark` speaker prompt.
    return_output_lengths (`bool`, *optional*):
        Whether or not to return the output lengths. Useful when batching.
Returns:
    By default:
        torch.LongTensor: Output coarse acoustics tokens.
    If `return_output_lengths=True`:
        `Tuple(torch.Tensor, torch.Tensor): The output coarse acoustics tokens, and the length of each sample
        of the batch.
Nr6  ú-`coarse_generation_config` has to be provided)r1  r`  ra  r–   r0  rb  r\   r8  r:  r=  Úmax_new_tokensr>  r?  FrH   )#r4   Úmax_coarse_input_lengthr`  Úsliding_window_lenÚmasked_fill_rF  Úcoarse_semantic_pad_tokenÚcoarse_rate_hzÚsemantic_rate_hzÚn_coarse_codebooksrH  rh  ri  Úsumr;   rj  ÚmaxÚitemr@  rq  ÚhstackÚceilrå   ÚFrD  rL   Úcoarse_infer_tokenrÁ   r   rM  r)   rP  rd   rO  rQ  )rA   rW  r0  rt  rb  r1  ru  ry   ry  r`  rz  ra  rn  Úoutput_lengthsÚmax_generated_lenr–   rk  Úx_coarseÚbase_semantic_idxÚn_window_stepsÚtotal_generated_lenÚlen_coarse_historyr˜   Úsemantic_idxÚinput_coarseÚalternatingLogitsProcessorÚoutput_coarseÚinput_coarse_lenÚcoarse_outputrB   s   &&&&&&&,                     €rC   rP  ÚBarkCoarseModel.generateÎ  sÑ  ø€ ðF &Ò-ÜÐNÓOÐOà#Ò+ÜÐLÓMÐMà":×"RÑ"RÐØ5×HÑHÐØ5×HÑHÐð 	×$Ñ$Ø×LÑLÑLØ$×>Ñ>ô	
ð %×3Ñ3Ø(×9Ñ9õ:à&×9Ñ9õ:ð 	!ô
  #¤2§8¢8Ð,>Õ,YÓ#ZÓ[Ðà)×-_Ñ-_Ñ_×dÑdÐefÓgˆÜŸšØÕ5Ð8P×8cÑ8cÕcó
ˆô Ÿš ^×6aÑ6aÕ%aÓb×fÑfÓhˆä!ŸIšI nÓ5×:Ñ:Ó<Ðà$×*Ñ*¨1Õ-ˆ
à'+×'@Ñ'@Ø)Ø1Ø%=Ø!Ø'AØ'ð (Aó (
Ñ$Ð˜Hð /×4Ñ4°QÕ7ÐäŸ,š,Ð(:¸OÐ'LÓMˆäœRŸWšWÐ%6Õ%KÓLÓMˆàÐà%Ÿ^™^¨AÕ.Ðä�~×&ˆAØ,¬s´5Ð9LÐOgÕ9gÓ3hÓ/iÕiˆLð +¨1¬b¯fªf°a¸ÐH\Õ9\Ð5]Ó.^Ñ.`Ð+`ÕaˆLØ'¨Ð+CÐ,CÐ+CÐ(CÕDˆLÜŸ5š5ØØÐ+¨l×.@Ñ.@ÀÕ.DÕDÐEØØ(×BÑBó	ˆLô !Ÿ<š<à Ü—L’LÐ#;×#NÑ#NÐ"OÐ!PÐS]Õ!]Ðfj×fqÑfqÔrØ˜QÐ!3Ð 3Ñ 4Ð4Õ5ðóˆLô *MØ×"Ñ" 1Õ%Ø*×>Ñ>Øó*Ð&ô "™GÒ,Øñà"<Ð!=ðô  #Ð#5ÐK^Õ7^Ó_ðð #;ð	ð
 ñˆMð  ,×1Ñ1°!Õ4Ðà�z‰zÐ3°U×;Ò;Ü Ÿ<š<¨°=×3JÑ3JÈ1ÐN^ÑN_ÐK_Õ3`Ð(aÓb‘ä Ÿ<š<¨°=ÀÐDTÑDUÐAUÕ3VÐ(WÓX�Ø"*§.¡.°Õ"3Ð6HÕ"HÐãñW 'ðZ ! Ð$6Ñ$7Ð!7Õ8ˆç Ø  .Ð0Ð0àÐrE   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÕ   )r   )rÂ   r‡   s   "€rC   rÃ   rc  y  s   ø‡ ‚ ñ Ñò rE   r×   r}   )NNé   NN)r   r€   r�   r‚   r[  rq  rP  rÛ   rƒ   r„   r…   r†   s   @@rC   r]  r]  y  s.   ù‡ € ð +Ð÷H4ò H4÷TIõ I÷k … rE   r]  z«
    Bark fine acoustics model. It is a non-causal GPT-like model with `config.n_codes_total` embedding layers and
    language modeling heads, one for each codebook.
    c                   óÜ   a a€ ] tR tRt oRtRtV 3R ltR tR tR t	R t
RR	 ltRV3R
 lR llt]RV3R lR ll4       t]P                   ! 4       RV3R lR ll4       tV3R ltRtVtV ;t# )ÚBarkFineModeliZ  Úfine_acousticsÚcodebook_idxc                óª  <€ \         SV `  V4       Wn        / V n        \	        V P                  P
                  V P                  P                  ,
          4       F!  pR V^,            R2V P                  RV R2&   K#  	  \        P                  ! \	        VP
                  4       Uu. uF.  p\        P                  ! VP                  VP                  4      NK0  	  up4      V n        \        P                  ! VP                  VP                  4      V n        \        P                  ! VP                   4      V n        \        P                  ! \	        VP$                  4       Uu. uF  p\'        VRVR7      NK  	  up4      V n        \        P*                  ! VP                  4      V n        \        P                  ! \	        VP                  VP
                  4       Uu. uF0  p\        P.                  ! VP                  VP0                  RR7      NK2  	  up4      V n        RV n        VP
                  V n        V P7                  4        R# u upi u upi u upi )zinput_embeds_layers.z.weightz	lm_heads.Fr¬   r%   N)r)   r*   r3   Ú_tied_weights_keysrå   Ún_codes_totalÚn_codes_givenr   rä   rß   rà   r/   Úinput_embeds_layersr:   râ   r,   r+   rã   ræ   rª   rç   r­   rè   r5   ré   Úlm_headsrë   rì   )rA   r3   rí   r˜   rB   s   &&  €rC   r*   ÚBarkFineModel.__init__e  sÏ  ø€ ä‰Ñ˜Ô ØŒØ"$ˆÔÜ�t—{‘{×0Ñ0°4·;±;×3LÑ3LÕLÖMˆAØ@TÐUVÐYZÕUZÐT[Ð[bÐ>cˆD×#Ñ# i°¨s°'Ð$:Ó;ñ Nô
 $&§=¢=ÜPUÐV\×VjÑVjÔPkÓlÑPkÈ1ŒR�\Š\˜&×1Ñ1°6×3EÑ3EÖFÑPkÑló$
ˆÔ ô &(§\¢\°&×2CÑ2CÀV×EWÑEWÓ%XˆÔ"ä—J’J˜vŸ~™~Ó.ˆŒ	ä—m’mÜFKÈF×L]ÑL]ÔF^Ó_ÑF^ÀŒY�v¨¸!×<ÑF^Ñ_ó
ˆŒô  "Ÿ|š|¨F×,>Ñ,>Ó?ˆÔäŸšô ˜v×3Ñ3°V×5IÑ5IÔJóáJ�Aô —	’	˜&×,Ñ,¨f×.FÑ.FÈU×SÙJñó
ˆŒð ',ˆÔ#Ø#×1Ñ1ˆÔð 	�‰Öùò- mùò `ùòs   Â$4IÅ IÇ6Ic                ó   € V P                   # r}   ©rŸ  rð   s   &rC   rõ   Ú"BarkFineModel.get_input_embeddingsˆ  s   € à×'Ñ'Ð'rE   c                ó   € Wn         R # r}   r£  rø   s   &&rC   rú   Ú"BarkFineModel.set_input_embeddingsŒ  s   € à#1Ö rE   c                ó   € V P                   # r}   ©r   rð   s   &rC   rñ   Ú#BarkFineModel.get_output_embeddings�  s   € à�}‰}ÐrE   c                ó   € Wn         R # r}   r¨  )rA   Únew_output_embeddingss   &&rC   Úset_output_embeddingsÚ#BarkFineModel.set_output_embeddings”  s   € à-ŽrE   c                ó2  € V P                  4       p\        P                  ! V Uu. uF  pV P                  WQW#4      NK  	  up4      pV P	                  V4       V^ ,          P
                  P                  ^ ,          pV P                  4       er   V P                  P                  '       gV   V P                  4       p\        P                  ! V Uu. uF  q€P                  W�4      NK  	  up4      p	V P                  V	4       V P                  4       # u upi u upi ©r$   )rõ   r   rä   Ú_get_resized_embeddingsrú   r  r@  rñ   r3   Útie_word_embeddingsÚ_get_resized_lm_headr¬  )
rA   Únew_num_tokensÚpad_to_multiple_ofÚmean_resizingÚold_embeddings_listÚold_embeddingsÚnew_embeddings_listÚold_lm_head_listÚold_lm_headÚnew_lm_head_lists
   &&&&      rC   Ú_resize_token_embeddingsÚ&BarkFineModel._resize_token_embeddings˜  sý   € Ø"×7Ñ7Ó9ÐÜ Ÿmšmñ ':óá&9�Nð ×,Ñ,¨^ÐM_ÖoÙ&9ñó
Ðð 	×!Ñ!Ð"5Ô6Ø,¨QÕ/×6Ñ6×<Ñ<¸QÕ?ˆð ×%Ñ%Ó'Ò3¸D¿K¹K×<[×<[Ð<[Ø#×9Ñ9Ó;ÐÜ!Ÿ}š}Ù[kÓlÑ[kÈK×*Ñ*¨;ÖGÑ[kÑló Ðð ×&Ñ&Ð'7Ô8à×(Ñ(Ó*Ð*ùò!ùò ms   ¥DÃDc                ób   <€ V ^8„  d   QhRS[ R,          RS[ R,          RS[RS[P                  /# )rr   r³  Nr´  rµ  r¿   )rH  r>   r   rß   )rÂ   r‡   s   "€rC   rÃ   ÚBarkFineModel.__annotate__­  s?   ø€ ÷ 0ñ 0á˜d�
ð0ñ   $�Jð0ñ ð	0ñ
 
�‰ñ0rE   c                óÎ  € V P                  WV4      pVf   Vf   V# V^ ,          P                  P                  ^ ,          V P                  n        V^ ,          P                  P                  ^ ,          V P                  n        V^ ,          P                  P                  ^ ,          V n        V^ ,          P                  P                  ^ ,          V n        V P                  4        V# )aõ  
Resizes input token embeddings matrix of the model if `new_num_tokens != config.vocab_size`.

Takes care of tying weights embeddings afterwards if the model class has a `tie_weights()` method.

Arguments:
    new_num_tokens (`int`, *optional*):
        The number of new tokens in the embedding matrix. Increasing the size will add newly initialized
        vectors at the end. Reducing the size will remove vectors from the end. If not provided or `None`, just
        returns a pointer to the input tokens `torch.nn.Embedding` module of the model without doing anything.
    pad_to_multiple_of (`int`, *optional*):
        If set will pad the embedding matrix to a multiple of the provided value.

        This is especially useful to enable the use of Tensor Cores on NVIDIA hardware with compute capability
        `>= 7.5` (Volta), or on TPUs which benefit from having sequence lengths be a multiple of 128. For more
        details about this, or help on choosing the correct value for resizing, refer to this guide:
        https://docs.nvidia.com/deeplearning/performance/dl-performance-matrix-multiplication/index.html#requirements-tc
    mean_resizing (`bool`):
        Whether to initialize the added embeddings from a multivariate normal distribution that has old embeddings' mean and
        covariance or to initialize them with a normal distribution that has a mean of zero and std equals `config.initializer_range`.

        Setting `mean_resizing` to `True` is useful when increasing the size of the embeddings of causal language models,
        where the generated tokens' probabilities won't be affected by the added embeddings because initializing the new embeddings with the
        old embeddings' mean will reduce the kl-divergence between the next token probability before and after adding the new embeddings.
        Refer to this article for more information: https://nlp.stanford.edu/~johnhew/vocab-expansion.html

Return:
    `torch.nn.Embedding`: Pointer to the input tokens Embeddings Module of the model.
)r¼  r  r@  r3   ré   Ú
vocab_sizeÚtie_weights)rA   r³  r´  rµ  Úmodel_embedss   &&&& rC   Úresize_token_embeddingsÚ%BarkFineModel.resize_token_embeddings­  s»   € ðF ×4Ñ4°^ÐYfÓgˆØÒ!Ð&8Ò&@ØÐð )5°Q­×(>Ñ(>×(DÑ(DÀQÕ(Gˆ�‰Ô%Ø!-¨a¥×!7Ñ!7×!=Ñ!=¸aÕ!@ˆ�‰ÔØ!-¨a¥×!7Ñ!7×!=Ñ!=¸aÕ!@ˆÔØ& q�/×0Ñ0×6Ñ6°qÕ9ˆŒð 	×ÑÔàÐrE   c                ó^  <€ V ^8„  d   QhRS[ RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[P                  R,          RS[R,          R	S[R,          R
S[R,          RS[S[P                  ,          S[,          /
# )rr   rš  rý   Nrj   rþ   rÿ   r   rx   r  r  r¿   )rH  r;   r  r  r>   r  r   )rÂ   r‡   s   "€rC   rÃ   r¿  à  sÄ   ø€ ÷ l
ñ l
áðl
ñ —<‘< $Õ&ðl
ñ Ÿ™ tÕ+ð	l
ñ
 —l‘l TÕ)ðl
ñ × Ñ  4Õ'ðl
ñ —|‘| dÕ*ðl
ñ   $�;ðl
ñ # T�kðl
ñ ˜D•[ðl
ñ 
‰u�|‰|Õ	™~Õ	-ñl
rE   c
           
     ó  € Ve   TMV P                   P                  pVe   TMV P                   P                  pV	e   T	MV P                   P                  p	RpVe   \	        R4      hV^ 8X  d   \        R4      hVe   Ve   \        R4      hVf   Vf   \        R4      hVe†   \        V P                  4       UUu. uF&  w  rÍV! VRRV3,          4      P                  R4      NK(  	  ppp\        P                  ! VRR7      pVRRRRV^,           13,          P                  RR7      pVP                  4       RR pV^,          pVP                  V P                  P                  P                   4      pVfX   \        P"                  ! ^ V\        P$                  V P                  P                  P                   R7      pVP                  ^ 4      pVP                  V P                  P                  P                   4      pV P                  V4      p\'        V P                   VVR	7      pV P)                  VV,           4      pVVP                  R4      3,           pV'       d   RMRpV'       d   RMRp\        V P*                  4       FG  w  ppV'       d   VV3,           pV! VVVR
7      pV^ ,          pV'       g   K6  VV^,          3,           pKI  	  V P-                  V4      pVP/                  V4      pV'       d   VV3,           pV P0                  WP                   P2                  ,
          ,          ! V4      pV	'       g5   \4        ;QJ d    . R RVVV3 4       F  NK  	  5# ! R RVVV3 4       4      # \7        VVVVR7      # u uppi )z´
codebook_idx (`int`):
    Index of the codebook that will be predicted.
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
    NOT IMPLEMENTED YET.
NzTraining is not implemented yetzRCannot predict 0th codebook - 0th codebook should be predicted by the coarse modelr  r	  r\   r]   r
  r  )rj   rx   c              3   ó0   "  € T F  qf   K  Vx € K  	  R # 5ir}   r×   r  s   & rC   r  Ú(BarkFineModel.forward.<locals>.<genexpr>E  s   é € ÐlÑ$Z˜qŸšÓ$Zùr  )r  r  ru   r  rH   r×   )r3   rx   r  r  r  r4   r  rŸ  r  r;   rK  r€  rI   rf   râ   r  rÁ   r  r  r   rã   rç   rè   r?   r   rž  r  r   )rA   rš  rý   rj   rþ   rÿ   r   rx   r  r  ry   r  rí   rá   r  r   r"  ru   r#  r$  r%  r&  r¹   r  s   &&&&&&&&&&,             rC   rz   ÚBarkFineModel.forwardß  sS  € ð( 2CÒ1NÑ-ÐTX×T_ÑT_×TqÑTqÐà$8Ò$DÑ È$Ï+É+×JjÑJjð 	ð &1Ò%<‘kÀ$Ç+Á+×BYÑBYˆàˆØÒÜ%Ð&GÓHÐHà˜1ÔÜÐqÓrÐràÒ  ]Ò%>ÜÐcÓdÐdàÒ Ò!6ÜÐTÓUÐUàÒ ô .7°t×7OÑ7OÔ-Pôá-PÑ)�Añ # 9¨Q°°1¨WÕ#5Ó6×@Ñ@ÀÖDÙ-Pð ñ ô "ŸIšI m¸Ô<ˆMØ)¨!¨Q°Ð3E°\ÀAÕ5EÐ3EÐ*EÕF×JÑJÈrÐJÓRˆMà#×(Ñ(Ó*¨3¨BÐ/ˆØ  •^ˆ
à%×(Ñ(¨×)CÑ)C×)JÑ)J×)QÑ)QÓRˆàÒÜ Ÿ<š<Ø�:¤U§Z¡Z¸×8RÑ8R×8YÑ8Y×8`Ñ8`ôˆLð (×1Ñ1°!Ó4ˆLà#—‘ t×'AÑ'A×'HÑ'H×'OÑ'OÓPˆØ×4Ñ4°\ÓBˆä2Ø—;‘;Ø'Ø)ô
ˆð Ÿ	™	 -°/Õ"AÓBˆØ" m×&8Ñ&8¸Ó&<Ð%>Õ>ˆç$5™b¸4Ðß"6™B¸DÐä! $§+¡+Ö.‰HˆAˆuß#Ø$5¸Ð8HÕ$HÐ!áØØ-Ø"3ôˆGð $ A�JˆMç Ñ Ø&9¸WÀQ½Z¸MÕ&IÒ#ñ /ð ×,Ñ,¨]Ó;ˆØ%×*Ñ*¨<Ó8ˆ÷  Ø 1°]Ð4DÕ DÐà—‘˜|¯k©k×.GÑ.GÕGÖHÈÓWˆçß”5Ñl T¨6Ð3DÐFYÑ$ZÓl—5Ðl�5Ñl T¨6Ð3DÐFYÑ$ZÓlÓlÐläØØØ+Ø*ô	
ð 	
ùóys   Â:,N c                óÀ   <€ V ^8„  d   QhRS[ P                  RS[R,          RS[R,          RS[RS[RS[S[S[ P                  3,          R,          RS[ P                  /# )	rr   r“  r0  Nrt  Úfine_generation_configrb  r1  r¿   )	r;   r  r   r   r   rH  r2  r3  r  )rÂ   r‡   s   "€rC   rÃ   r¿  O  s‚   ø€ ÷ Fñ Fá—|‘|ðFñ %AÀ4Õ$GðFñ #=¸tÕ"Cð	Fñ
 !9ðFñ ðFñ ™S¡%§,¡,Ð.Õ/°$Õ6ðFñ 
×	Ñ	ñFrE   c           	     óî  € Vf   \        R4      hVf   \        R4      hVf   \        R4      hVP                  RVP                  4      pVP                  p	VP                  p
VP                  VP                  ^ ,          RVP                  4      p\        P                  ! WP                  ,
          V4      pVP                  ^ ,          pVe3   \        P                  ! VR,          P                  R,          V^ R7      pMRpVP                  p\        P                  ! V^ VP                  V,
          3RV4      pVeI   \        P                   ! VR	V	) R1R	3,          V.^R7      pVR	V	) R1R	3,          P                  ^,          pM^ p^ pVP                  ^,          V
8  d8   W®P                  ^,          ,
          p\        P                  ! V^ ^ ^ V3RVR
7      pVP                  ^,          W¯,
          ,
          V	,          p\#        \$        P&                  ! V4      4      p\)        ^ V4      ^,           p\+        V4       EFË  p\-        VV	,          VP                  ^,          V
,
          .4      p\-        VVV	,          ,           VP                  ^,          V	,
          .4      pVV,
          pVR	VVV
,           1R	3,          p\+        WÔP                  4       Fð  pV P/                  VV4      P0                  pVe   VR8X  d)   VR	VR1RV13,          p\        P2                  ! VR4      pMsVR	R	RV13,          V,          p\        P4                  ! VRR7      R	VV
13,          pVP7                  RV34      p\        P8                  ! V^R7      P                  VR4      pVP;                  \        P<                  4      pVVR	VR1V3&   ??Kò  	  \+        WÔP                  4       F'  pVR	VR1V3,          VR	VVV
V,
          ,           1V3&   K)  	  ?EKÎ  	  VP?                  ^^4      R	R	VR13,          pV^ 8”  d   VR	R	RV) 13,          pVP                  R,          VP                  R,          8w  d   \        R4      hV# )aà  
Generates fine acoustics tokens from input coarse acoustics tokens and an additional optional `Bark` speaker
prompt.

Args:
    coarse_output (`torch.Tensor` of shape (batch_size, seq_len)):
        Input coarse acoustics ids, i.e the output of `BarkCoarseModel.generate`.
    semantic_generation_config (`BarkSemanticGenerationConfig`):
        Generation config indicating how to generate the semantic tokens.
    coarse_generation_config (`BarkCoarseGenerationConfig`):
        Generation config indicating how to generate the coarse tokens.
    fine_generation_config (`BarkFineGenerationConfig`):
        Generation config indicating how to generate the fine tokens.
    codebook_size (`int`, *optional*, defaults to 1024):
        Codebook channel size, i.e. the size of the output vocabulary per codebook channel.
    history_prompt (`Optional[dict[str,torch.Tensor]]`, *optional*):
        Optional `Bark` speaker prompt.
Returns:
    torch.LongTensor: Output fine acoustics tokens.
Nr6  rw  z+`fine_generation_config` has to be providedÚtemperatureÚfine_promptr]   r8  r\   )r9  ri   r[   )Únum_samplesz-input and output should have the same seq_lenrH   rS   ) r4   rO  rÎ  Úmax_fine_history_lengthÚmax_fine_input_lengthr?   r@  r  r;   Ú	remainderrM  rI  ÚTr…  rD  Ún_fine_codebooksrK  rH  rh  r„  r�  rå   rd   rz   r  Úargmaxre   rg  Úmultinomialrf   Úint32rT   )rA   r“  r0  rt  rÌ  rb  r1  ry   rÎ  rÑ  rÒ  r–   Úx_fine_historyÚn_coarseÚ
fine_inputÚ	n_historyÚn_remove_from_endÚn_loopsÚn_outerÚ	start_idxÚstart_fill_idxÚrel_start_fill_idxÚinput_bufferÚn_innerr  Úrelevant_logitsÚcodebook_predsÚprobss   &&&&&&&,                    rC   rP  ÚBarkFineModel.generateN  st  € ð> &Ò-ÜÐNÓOÐOà#Ò+ÜÐLÓMÐMà!Ò)ÜÐJÓKÐKð
 —j‘j Ð0F×0RÑ0RÓSˆà"8×"PÑ"PÐØ 6× LÑ LÐð &×*Ñ*¨=×+>Ñ+>¸qÕ+AÀ2ÐG_×GrÑGrÓsˆô Ÿš¨×8fÑ8fÕ(fÐhuÓvˆØ"×(Ñ(¨Õ+ˆ
àÒ%Ü"×4Ò4°^ÀMÕ5R×5TÑ5TÐUYÕ5ZÐ\fÐlmÔn‰Nð "ˆNà+×>Ñ>ˆô —U’UØØÐ&×7Ñ7¸(ÕBÐCØØó	
ˆ
ð Ò%ÜŸš N°1Ð7NÐ6NÑ6OÐQRÐ3RÕ$SÐU_Ð#`ÐfgÔhˆJð ' qÐ+BÐ*BÑ*CÀQÐ'FÕG×MÑMÈaÕP‰IàˆIàÐà×Ñ˜AÕÐ!6Ô6Ø 5×8HÑ8HÈÕ8KÕ KÐÜŸš˜z¨A¨q°!Ð5FÐ+GÈjÐ`mÔnˆJð !×&Ñ& qÕ)Ð-BÕ-NÕOÐSjÕjˆÜ”b—g’g˜gÓ&Ó'ˆÜ�a˜“/ AÕ%ˆä˜W—~ˆGÜ˜WÐ'>Õ>À
×@PÑ@PÐQRÕ@SÐVkÕ@kÐlÓmˆIä Ø˜WÐ'>Õ>Õ>À
×@PÑ@PÐQRÕ@SÐVmÕ@mÐnóˆNð "0°)Õ!;ÐØ% a¨°YÐAVÕ5VÐ)VÐXYÐ&YÕZˆLÜ  ×+RÑ+RÖS�ØŸ™ g¨|Ó<×CÑC�ØÒ&¨+¸Ô*<Ø&,¨QÐ0BÑ0CÀ^ÀmÀ^Ð-SÕ&T�OÜ%*§\¢\°/À2Ó%F‘Nà&,¨Q°°>°M°>Ð-AÕ&BÀ[Õ&P�OäŸIšI o¸2Ô>¸qÐBTÐUjÐBjÐ?jÕk�Eà!ŸM™M¨2¨}Ð*=Ó>�Eä%*×%6Ò%6°uÈ!Ô%L×%QÑ%QÐR\Ð^`Ó%a�NØ!/×!2Ñ!2´5·;±;Ó!?�Ø@N�˜QÐ 2Ñ 3°WÐ<Ñ=ØšNñ Tô$ ! ×+RÑ+RÖS�ð ! Ð$6Ñ$7¸Ð!@ÕAð Ø�~¨Ð:OÐRdÕ:dÕ(eÐeÐgnÐnóñ Tó ñ= &ð@  ×)Ñ)¨!¨QÓ/°°1°i±jÐ0@ÕAˆ
Ø˜qÔ Ø# A qÐ*=Ð,=Ð+=Ð*=Ð$=Õ>ˆJà×Ñ˜BÕ =×#6Ñ#6°rÕ#:Ô:ÜÐLÓMÐMàÐrE   c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÕ   )r   )rÂ   r‡   s   "€rC   rÃ   r¿  Z  s   ø‡ ‚ ñ Ñò rE   )rœ  r3   rã   rë   rŸ  rè   rç   r   r�  ré   râ   rÁ  )NT)NNT)NNNNNNNN)NNNr–  N)r   r€   r�   r‚   r[  Úmain_input_namer*   rõ   rú   rñ   r¬  r¼  rÄ  r   rz   r;   Úno_gradrP  rÛ   rƒ   r„   r…   r†   s   @@rC   r˜  r˜  Z  sƒ   ù‡ € ð )Ðà$€Oõ!òF(ò2òò.ô+÷*0ò 0ðd ÷l
ñ l
ó ðl
ð\ ‡]‚]ƒ_÷Fñ Fó ðF÷k … rE   r˜  a7  
    The full Bark model, a text-to-speech model composed of 4 sub-models:
    - [`BarkSemanticModel`] (also referred to as the 'text' model): a causal auto-regressive transformer model that
      takes
    as input tokenized text, and predicts semantic text tokens that capture the meaning of the text.
    - [`BarkCoarseModel`] (also referred to as the 'coarse acoustics' model), also a causal autoregressive transformer,
    that takes into input the results of the last model. It aims at regressing the first two audio codebooks necessary
    to `encodec`.
    - [`BarkFineModel`] (the 'fine acoustics' model), this time a non-causal autoencoder transformer, which iteratively
    predicts the last codebooks based on the sum of the previous codebooks embeddings.
    - having predicted all the codebook channels from the [`EncodecModel`], Bark uses it to decode the output audio
      array.

    It should be noted that each of the first three modules can support conditional speaker embeddings to condition the
    output sound according to specific predefined voice.
    c                   óÚ   a a€ ] tR tRt oV 3R lt]V3R lR l4       t]V3R lV 3R ll4       tRV3R lR llt	RR	 lt
]P                  ! 4       RV3R
 lR ll4       tV3R ltRtVtV ;t# )Ú	BarkModeliØ  c                ó8  <€ \         SV `  V4       \        VP                  4      V n        \        VP                  4      V n        \        VP                  4      V n
        \        P                  ! VP                  4      V n        Wn        V P!                  4        R # r}   )r)   r*   r-  Úsemantic_configr.  r]  Úcoarse_acoustics_configr^  r˜  Úfine_acoustics_configr™  r   Úfrom_configÚcodec_configÚcodec_modelr3   rì   r¤   s   &&€rC   r*   ÚBarkModel.__init__í  sp   ø€ Ü‰Ñ˜Ô ä)¨&×*@Ñ*@ÓAˆŒÜ /°×0NÑ0NÓ OˆÔÜ+¨F×,HÑ,HÓIˆÔä$×0Ò0°×1DÑ1DÓEˆÔàŒà�‰ÖrE   c                ó    <€ V ^8„  d   QhRS[ /# r¾   )r>   )rÂ   r‡   s   "€rC   rÃ   ÚBarkModel.__annotate__û  s   ø€ ÷ ñ ™Tñ rE   c                ó   € R # )Tr×   )Úclss   &rC   Úcan_generateÚBarkModel.can_generateú  s   € ñ rE   c                ó4   <€ V ^8„  d   QhRS[ P                  /# r¾   rÀ   )rÂ   r‡   s   "€rC   rÃ   r÷    s   ø€ ÷ Fñ F™Ÿ™ñ FrE   c                ó‚  <€ \        V P                  R4      '       g   \        SV `  # V P                  P	                  4        Fy  p\        VR4      '       g   K  \        VP
                  R4      '       g   K5  VP
                  P                  f   KO  \        P                  ! VP
                  P                  4      u # 	  R# )rÆ   rÇ   rÈ   N)rÉ   r.  r)   rÁ   rÊ   rÇ   rÈ   r;   rË   s   & €rC   rÁ   ÚBarkModel.device  s   ø€ ô �t—}‘} j×1Ò1Ü‘7‘>Ð!Ø—m‘m×+Ñ+Ö-ˆFä˜ 
×+Ô+Ü˜FŸO™OÐ-?×@Ô@Ø—O‘O×4Ñ4Ô@ä—|’| F§O¡O×$DÑ$DÓEÒEó .rE   c                ó.   <€ V ^8„  d   QhRS[ R,          /# )rr   Úaccelerator_idN)rH  )rÂ   r‡   s   "€rC   rÃ   r÷    s   ø€ ÷ ,%ñ ,%á˜d�
ñ,%rE   c                óž  € \        4       '       d   ^ RIHp M\        R4      hRp\	        4       '       d)   \
        P                  P                  4       P                  p\
        P                  ! V RV 24      p\        \
        V4      pV P                  P                  R8w  d"   V P                  R4       VP                  4        V! V P                  P                  V4      w  V P                  n        pRpV P                  V P                  V P                   3 F  p	V! W•VR7      w  rxK  	  W€n        V! V P$                  WXR7      w  rxW€n        R# )a‘  
Offloads all sub-models to CPU using accelerate, reducing memory usage with a low impact on performance. This
method moves one whole sub-model at a time to the accelerator when it is used, and the sub-model remains in accelerator until the next sub-model runs.

Args:
    accelerator_id (`int`, *optional*, defaults to 0):
        accelerator id on which the sub-models will be loaded and offloaded.
)Úcpu_offload_with_hookz1`enable_model_cpu_offload` requires `accelerate`.ÚcudaÚ:ÚcpuN)Úprev_module_hook)r   Ú
accelerater  ÚImportErrorr   r;   ÚacceleratorÚcurrent_acceleratorÚtyperÁ   Úgetattrrf   Úempty_cacher.  rá   r^  r™  Úfine_acoustics_hookrô  Úcodec_model_hook)
rA   r   ry   r  Údevice_typerÁ   Útorch_accelerator_moduler˜   ÚhookÚcpu_offloaded_models
   &&,       rC   Úenable_cpu_offloadÚBarkModel.enable_cpu_offload  s  € ô #×$Ò$Þ8äÐQÓRÐRàˆÜ)×+Ò+Ü×+Ñ+×?Ñ?ÓA×FÑFˆKÜ—’  ¨Q¨~Ð.>Ð?Ó@ˆä#*¬5°+Ó#>Ð Ø�;‰;×Ñ˜uÔ$Ø�G‰G�EŒNØ$×0Ñ0Ô2ñ /DÀDÇMÁM×DdÑDdÐflÓ.mÑ+ˆ�‰Ô(¨!àˆà�M‰MØ×!Ñ!Ø×Ñó$
Ðñ
 ,Ð,?ÐZ^Ô_‰GˆA‰tñ$
ð $(Ô á'¨×(8Ñ(8¸&ÔX‰ˆð !%ÖrE   c                óÌ  € VP                  ^ ^4      pV P                  P                  P                  V4      pVer   \	        W24       UUu. uF!  w  rEVRRV13,          P                  ^ 4      NK#  	  pppV Uu. uF+  q@P                  P                  V4      P                  4       NK-  	  ppV# V P                  P                  V4      pVP                  ^4      pV# u uppi u upi )z:Turn quantized audio codes into audio array using encodec.Nr\   )rT   rô  Ú	quantizerÚdecodeÚzipr  ÚdecoderÚsqueeze)rA   Úfine_outputr‡  ÚembÚsampleÚlÚoutÚ	audio_arrs   &&&     rC   Úcodec_decodeÚBarkModel.codec_decodeB  sÚ   € ð "×+Ñ+¨A¨qÓ1ˆØ×Ñ×(Ñ(×/Ñ/°Ó<ˆàÒ%ô BEÀSÔAYÔZÑAY±+°6�6˜!˜R˜a˜R˜%•=×*Ñ*¨1Ö-ÑAYˆCÑZÙRUÓVÑRUÈ×)Ñ)×1Ñ1°&Ó9×AÑAÖCÑRUˆIÐVð
 Ðð ×"Ñ"×*Ñ*¨3Ó/ˆCØŸ™ A›ˆIàÐùó [ùÚVs   Á
'CÁ81C!c                ó®   <€ V ^8„  d   QhRS[ P                  R,          RS[S[S[ P                  3,          R,          RS[R,          RS[ P
                  /# )rr   rý   Nr1  ru  r¿   )r;   r  r2  r3  r>   r  )rÂ   r‡   s   "€rC   rÃ   r÷  U  s_   ø€ ÷ Oñ Oá—<‘< $Õ&ðOñ ™S¡%§,¡,Ð.Õ/°$Õ6ðOñ  $ d�{ð	Oñ 
×	Ñ	ñOrE   c                óP  € \        R/ V P                  P                  B p\        R/ V P                  P                  B p\        R/ V P                  P                  B pRVP                  RR4      RVP                  RR4      /p/ p	/ p
VP                  4        F¦  w  r¼VP                  R4      '       d   V\        R4      R pWÈV&   K0  VP                  R4      '       d   V\        R4      R pWÉV&   K[  VP                  R4      '       d   V\        R4      R pWÊV&   K†  W¸9  d   WÈV&   W¹9  d   WÉV&   Wº9  g   K¢  WÊV&   K¨  	  RV9   d   VP                  R4       V P                  P                  ! V3RVR	V/VB pRV	9   d   V	P                  R4       V P                  P                  ! V3RVR	VR
VRV P                  P                  RV/V	B pRpV'       d   Vw  rïWöP                  ,          pRV
9   d   V
P                  R4       V P                   P                  ! V3RVR	VR
VRVRV P                  P                  /V
B p\#        V RR4      eE   V P$                  P'                  4        V P(                  P+                  V P,                  4      V n        V P/                  VV4      p\#        V RR4      e   V P0                  P'                  4        V'       dK   V Uu. uF  p\        V4      NK  	  pp\2        P4                  P6                  P9                  VR^ R7      pVV3# V# u upi )aV  
Generates audio from an input prompt and an additional optional `Bark` speaker prompt.

Args:
    input_ids (`Optional[torch.Tensor]` of shape (batch_size, seq_len), *optional*):
        Input ids. Will be truncated up to 256 tokens. Note that the output audios will be as long as the
        longest generation among the batch.
    history_prompt (`Optional[dict[str,torch.Tensor]]`, *optional*):
        Optional `Bark` speaker prompt. Note that for now, this model takes only one speaker prompt per batch.
    kwargs (*optional*): Remaining dictionary of keyword arguments. Keyword arguments are of two types:

        - Without a prefix, they will be entered as `**kwargs` for the `generate` method of each sub-model.
        - With a *semantic_*, *coarse_*, *fine_* prefix, they will be input for the `generate` method of the
        semantic, coarse and fine respectively. It has the priority over the keywords without a prefix.

        This means you can, for example, specify a generation strategy for all sub-models except one.
    return_output_lengths (`bool`, *optional*):
        Whether or not to return the waveform lengths. Useful when batching.
Returns:
    By default:
        - **audio_waveform** (`torch.Tensor` of shape (batch_size, seq_len)): Generated audio waveform.
    When `return_output_lengths=True`:
        Returns a tuple made of:
        - **audio_waveform** (`torch.Tensor` of shape (batch_size, seq_len)): Generated audio waveform.
        - **output_lengths** (`torch.Tensor` of shape (batch_size)): The length of each waveform in the batch
Example:

```python
>>> from transformers import AutoProcessor, BarkModel

>>> processor = AutoProcessor.from_pretrained("suno/bark-small")
>>> model = BarkModel.from_pretrained("suno/bark-small")

>>> # To add a voice preset, you can pass `voice_preset` to `BarkProcessor.__call__(...)`
>>> voice_preset = "v2/en_speaker_6"

>>> inputs = processor("Hello, my dog is cute, I need him in my life", voice_preset=voice_preset)

>>> audio_array = model.generate(**inputs, semantic_max_new_tokens=100)
>>> audio_array = audio_array.cpu().numpy().squeeze()
```
rj   Nr;  Ú	semantic_Úcoarse_Úfine_r>  r1  r0  rt  rb  ru  rÌ  r  r  T)Úbatch_firstÚpadding_valuer×   )r   r>  rï  r   rð  r   rñ  ÚpopÚitemsÚ
startswithrE  r.  rP  r^  rb  r  r™  r  r  Úoffloadrô  rf   rÁ   r"  r  r   ÚutilsÚrnnÚpad_sequence)rA   rý   r1  ru  ry   r0  rt  rÌ  Úkwargs_semanticÚkwargs_coarseÚkwargs_finerh   ri   rW  r“  r‡  Úoutputr)  r  s   &&&&,              rC   rP  ÚBarkModel.generateT  sf  € ôh &BÑ%kÀD×DZÑDZ×DjÑDjÑ%kÐ"Ü#=Ñ#oÀ×@VÑ@V×@nÑ@nÑ#oÐ Ü!9Ñ!i¸D×<RÑ<R×<hÑ<hÑ!iÐð ˜fŸj™jÐ)9¸4Ó@Ø˜Ÿ™ K°Ó6ð
ˆð
 ˆØˆØ Ÿ,™,ž.‰JˆCØ�~‰~˜k×*Ò*Øœ#˜kÓ*Ð,Ð-�Ø', Ó$Ø—‘ 	×*Ò*Øœ#˜i›.Ð*Ð+�Ø%*˜cÓ"Ø—‘ ×(Ò(Øœ#˜g›,˜.Ð)�Ø#(˜CÓ ð Ô-Ø+0 CÑ(ØÔ+Ø). #Ñ&ØÖ)Ø', Ó$ñ% )ð*  /Ô1Ø×ÑÐ 3Ô4ØŸ-™-×0Ò0Øñ
à)ð
ð (Bð
ð ñ	
ˆð  -Ô/Ø×ÑÐ1Ô2Ø×-Ñ-×6Ò6Øñ
à)ð
ð (Bð
ð &>ð	
ð
 ×0Ñ0×>Ñ>ð
ð #8ð
ð ñ
ˆð ˆß Ø,9Ñ)ˆMà+×/ZÑ/ZÕZˆNð  +Ô-Ø�O‰OÐ/Ô0Ø×$Ñ$×-Ò-Øñ
à)ð
ð (Bð
ð &>ð	
ð
 $:ð
ð ×0Ñ0×>Ñ>ð
ð ñ
ˆô �4Ð.°Ó5ÒAð ×$Ñ$×,Ñ,Ô.Ø#×/Ñ/×2Ñ2°4·;±;Ó?ˆDÔð ×!Ñ! &¨.Ó9ˆä�4Ð+¨TÓ2Ò>à×!Ñ!×)Ñ)Ô+ç Ù8=Ó>¹¨fœc &žk¹ˆNÐ>Ü—H‘H—L‘L×-Ñ-¨eÀÐUVÐ-ÓWˆEØ˜.Ð(Ð(àˆùò	 ?s   ËL#c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # rÕ   rÖ   )rÂ   r‡   s   "€rC   rÃ   r÷  Ø  s   ø‡ ‚ ñ& Ñò' rE   )r^  rô  r  r3   r™  r  r.  r¯  r}   rZ  )r   r€   r�   r‚   r*   Úclassmethodrú  rÚ   rÁ   r  r"  r;   rë  rP  rÛ   rƒ   r„   r…   r†   s   @@rC   rí  rí  Ø  st   ù‡ € õ*ð ÷ó ðð ÷Fò Fó ðF÷",%ò ,%ô\ð$ ‡]‚]ƒ_÷Oñ Oó ðO÷{ … rE   rí  )r˜  r-  r]  rí  r¼   rÝ   )Erš   r`   Únumpyrh  r;   r   Útorch.nnr   r…  Ú r   rÑ   Úcache_utilsr   r   Ú
generationr   Úgeneration.logits_processr   r	   r
   Úmasking_utilsr   Úmodeling_flash_attention_utilsr   r   Úmodeling_layersr   Úmodeling_outputsr   r   Úmodeling_utilsr   r/  r   r   r   r   Úautor   Úconfiguration_barkr   r   r   r   r   Úgeneration_configuration_barkr   r   r   Úintegrations.flash_attentionr   r    Ú
get_loggerr   r  ÚModuler"   r‰   r°   rž   rª   r¼   rÝ   r-  r]  r˜  rí  Ú__all__r×   rE   rC   Ú<module>rK     s·  ðñ ã ã Û Ý Ý $å &ß .Ý )÷ñ õ
 7ß hÝ 9ß FÝ -÷ó õ ÷õ ÷ñ ñ ×ÒÝ@ÝJð 
×	Ò	˜HÓ	%€ôl)˜Ÿ	™	ô l)ô^I!Ð/ô I!ðZ ÐØÐ0ðÐ ôˆb�i‰iô ô .7Ð*ô .7ðb ô.˜/ó .ó ð.ôF\
Ð)¨?ô \
ñ~ ðôôj˜ó jóðjñZ ðôôW�oó WóðWñt ðôôuÐ'ó uóðuñp ðôô$zÐ# _ó zó%ð$zòz‚rE   