
    +h{                        S SK r S SKJrJrJrJrJr  S SKrS SK	r	S SK
JrJr  SSKJrJr  SSKJrJr  SSKJr  SSKJrJrJrJr  SS	KJr  SS
KJr  SSKJr  SSK J!r!  \" 5       (       a  S SK"J#r#  O
 " S S5      r#\" 5       (       a  S SK$J%s  J&r'  Sr(OSr(\RR                  " \*5      r+Sr,    SS\\-   S\\\.\	R^                  4      S\\\-      S\\\0      4S jjr1 " S S\5      r2g)    N)CallableDictListOptionalUnion)T5EncoderModelT5TokenizerFast   )MultiPipelineCallbacksPipelineCallback)AutoencoderKLCosmosCosmosTransformer3DModel)EDMEulerScheduler)is_cosmos_guardrail_availableis_torch_xla_availableloggingreplace_example_docstring)randn_tensor)VideoProcessor   )DiffusionPipeline   )CosmosPipelineOutput)CosmosSafetyCheckerc                       \ rS rSrS rSrg)r   $   c                     [        S5      e)Nz|`cosmos_guardrail` is not installed. Please install it to use the safety checker for Cosmos: `pip install cosmos_guardrail`.)ImportError)selfargskwargss      o/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py__init__CosmosSafetyChecker.__init__%   s     O      N)__name__
__module____qualname____firstlineno__r#   __static_attributes__r&   r%   r"   r   r   $   s    	r%   r   TFa  
    Examples:
        ```python
        >>> import torch
        >>> from diffusers import CosmosTextToWorldPipeline
        >>> from diffusers.utils import export_to_video

        >>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Text2World"
        >>> pipe = CosmosTextToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
        >>> pipe.to("cuda")

        >>> prompt = "A sleek, humanoid robot stands in a vast warehouse filled with neatly stacked cardboard boxes on industrial shelves. The robot's metallic body gleams under the bright, even lighting, highlighting its futuristic design and intricate joints. A glowing blue light emanates from its chest, adding a touch of advanced technology. The background is dominated by rows of boxes, suggesting a highly organized storage system. The floor is lined with wooden pallets, enhancing the industrial setting. The camera remains static, capturing the robot's poised stance amidst the orderly environment, with a shallow depth of field that keeps the focus on the robot while subtly blurring the background for a cinematic effect."

        >>> output = pipe(prompt=prompt).frames[0]
        >>> export_to_video(output, "output.mp4", fps=30)
        ```
num_inference_stepsdevice	timestepssigmasc                    Ub  Ub  [        S5      eUb  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
X2S.UD6  U R                  n[        U5      nX14$ Ub  S[        [        R                  " U R                  5      R
                  R                  5       5      ;   nU(       d  [        SU R                   S35      eU R                  " S
XBS.UD6  U R                  n[        U5      nX14$ U R                  " U4S	U0UD6  U R                  nX14$ )a  
Calls the scheduler's `set_timesteps` method and retrieves timesteps from the scheduler after the call. Handles
custom timesteps. Any kwargs will be supplied to `scheduler.set_timesteps`.

Args:
    scheduler (`SchedulerMixin`):
        The scheduler to get timesteps from.
    num_inference_steps (`int`):
        The number of diffusion steps used when generating samples with a pre-trained model. If used, `timesteps`
        must be `None`.
    device (`str` or `torch.device`, *optional*):
        The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
    timesteps (`List[int]`, *optional*):
        Custom timesteps used to override the timestep spacing strategy of the scheduler. If `timesteps` is passed,
        `num_inference_steps` and `sigmas` must be `None`.
    sigmas (`List[float]`, *optional*):
        Custom sigmas used to override the timestep spacing strategy of the scheduler. If `sigmas` is passed,
        `num_inference_steps` and `timesteps` must be `None`.

Returns:
    `Tuple[torch.Tensor, int]`: A tuple where the first element is the timestep schedule from the scheduler and the
    second element is the number of inference steps.
zYOnly one of `timesteps` or `sigmas` can be passed. Please choose one to set custom valuesr.   zThe current scheduler class zx's `set_timesteps` does not support custom timestep schedules. Please check whether you are using the correct scheduler.)r.   r-   r/   zv's `set_timesteps` does not support custom sigmas schedules. Please check whether you are using the correct scheduler.)r/   r-   r-   r&   )

ValueErrorsetinspect	signatureset_timesteps
parameterskeys	__class__r.   len)	schedulerr,   r-   r.   r/   r!   accepts_timestepsaccept_sigmass           r"   retrieve_timestepsr=   I   s}   > !3tuu'3w/@/@AXAX/Y/d/d/i/i/k+ll .y/B/B.C Da b  	M)MfM''	!)n )) 
	 C(9(9):Q:Q(R(](](b(b(d$ee.y/B/B.C D_ `  	GvGG''	!)n )) 	 3MFMfM''	))r%   c            (       |  ^  \ rS rSrSrSr/ SQrS/r S;S\S\	S	\
S
\S\S\4U 4S jjjr    S<S\\\\   4   S\S\\R*                     S\\R,                     4S jjr        S=S\\\\   4   S\\\\\   4      S\S\S\\R2                     S\\R2                     S\S\\R*                     S\\R,                     4S jjr       S>S\SS S!\S"\S#\S\\R,                     S\\R*                     S$\\\R6                  \\R6                     4      S%\\R2                     S&\R2                  4S' jjr  S?S( jr\S) 5       r\S* 5       r \S+ 5       r!\S, 5       r"\S- 5       r#\RH                  " 5       \%" \&5      SSSSSS.S/S0SSSSSS1SSS%/S4S\\\\   4   S\\\\\   4      S!\S"\S#\S2\S3\'S4\S\\   S$\\\R6                  \\R6                     4      S%\\R2                     S\\R2                     S\\R2                     S5\\   S6\S7\\\(\\\)/S4   \*\+4      S8\\   S\4$S9 jj5       5       r,S:r-U =r.$ )@CosmosTextToWorldPipeline   a  
Pipeline for text-to-world generation using [Cosmos Predict1](https://github.com/nvidia-cosmos/cosmos-predict1).

This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).

Args:
    text_encoder ([`T5EncoderModel`]):
        Frozen text-encoder. Cosmos uses
        [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel); specifically the
        [t5-11b](https://huggingface.co/google-t5/t5-11b) variant.
    tokenizer (`T5TokenizerFast`):
        Tokenizer of class
        [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer).
    transformer ([`CosmosTransformer3DModel`]):
        Conditional Transformer to denoise the encoded image latents.
    scheduler ([`FlowMatchEulerDiscreteScheduler`]):
        A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
    vae ([`AutoencoderKLCosmos`]):
        Variational Auto-Encoder (VAE) Model to encode and decode videos to and from latent representations.
ztext_encoder->transformer->vae)latentsprompt_embedsnegative_prompt_embedssafety_checkerNtext_encoder	tokenizertransformervaer:   c           	      x  > [         TU ]  5         Uc
  [        5       nU R                  UUUUUUS9  [	        U SS 5      (       a   U R
                  R                  R                  OSU l        [	        U SS 5      (       a   U R
                  R                  R                  OSU l
        [        U R                  S9U l        g )N)rH   rE   rF   rG   r:   rD   rH      )vae_scale_factor)superr#   r   register_modulesgetattrrH   configtemporal_compression_ratiovae_scale_factor_temporalspatial_compression_ratiovae_scale_factor_spatialr   video_processor)r   rE   rF   rG   rH   r:   rD   r8   s          r"   r#   "CosmosTextToWorldPipeline.__init__   s     	!02N%#) 	 	
 ;B$t:T:TDHHOO66Z[ 	& V]]achjnUoUo(Q(Quv%-t?\?\]r%      promptmax_sequence_lengthr-   dtypec           
      H   U=(       d    U R                   nU=(       d    U R                  R                  n[        U[        5      (       a  U/OUnU R                  USUSSSSS9nUR                  nUR                  R                  5       R                  U5      nU R                  USSS9R                  nUR                  S   UR                  S   :  a]  [        R                  " Xh5      (       dB  U R
                  R                  US S 2US	-
  S24   5      n	[        R                  S
U SU	 35        U R                  UR                  U5      US9R                   n
U
R                  XCS9n
UR#                  S	S9R%                  5       n['        U5       H  u  pSXUS 24'   M     U
$ )N
max_lengthTptF)paddingr[   
truncationreturn_tensorsreturn_lengthreturn_offsets_mappinglongest)r]   r_   r   zXThe following part of your input was truncated because `max_sequence_length` is set to  z	 tokens: )attention_mask)rY   r-   )dimr   )_execution_devicerE   rY   
isinstancestrrF   	input_idsrd   booltoshapetorchequalbatch_decodeloggerwarninglast_hidden_statesumcpu	enumerate)r   rW   rX   r-   rY   text_inputstext_input_idsprompt_attention_maskuntruncated_idsremoved_textrB   lengthsilengths                 r"   _get_t5_prompt_embeds/CosmosTextToWorldPipeline._get_t5_prompt_embeds   s    14110**00'44&&nn *#( % 
 %.. + : : ? ? A D DV L..SW.Xbb  $(<(<R(@@UcIuIu>>66qJ]`aJadfJfGf7ghLNN'(	,A
 ))f%6K * 


 	 &((u(D'+++2668"7+IA()MVW*% , r%   Tr   negative_promptdo_classifier_free_guidancenum_videos_per_promptrB   rC   c
                    U=(       d    U R                   n[        U[        5      (       a  U/OUnUb  [        U5      n
OUR                  S   n
UcG  U R                  XXS9nUR                  u  pnUR                  SUS5      nUR                  X-  US5      nU(       a  Uc  U=(       d    Sn[        U[        5      (       a  X/-  OUnUb;  [        U5      [        U5      La$  [        S[        U5       S[        U5       S35      eU
[        U5      :w  a!  [        S	U S
[        U5       SU S
U
 S3	5      eU R                  X'XS9nUR                  u  pnUR                  SUS5      nUR                  X-  US5      nXV4$ )ab  
Encodes the prompt into text encoder hidden states.

Args:
    prompt (`str` or `List[str]`, *optional*):
        prompt to be encoded
    negative_prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts not to guide the image generation. If not defined, one has to pass
        `negative_prompt_embeds` instead. Ignored when not using guidance (i.e., ignored if `guidance_scale` is
        less than `1`).
    do_classifier_free_guidance (`bool`, *optional*, defaults to `True`):
        Whether to use classifier free guidance or not.
    num_videos_per_prompt (`int`, *optional*, defaults to 1):
        Number of videos that should be generated per prompt. torch device to place the resulting embeddings on
    prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
        provided, text embeddings will be generated from `prompt` input argument.
    negative_prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated negative text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt
        weighting. If not provided, negative_prompt_embeds will be generated from `negative_prompt` input
        argument.
    device: (`torch.device`, *optional*):
        torch device
    dtype: (`torch.dtype`, *optional*):
        torch dtype
r   )rW   rX   r-   rY   r   rc    z?`negative_prompt` should be the same type to `prompt`, but got z != .z`negative_prompt`: z has batch size z, but `prompt`: zT. Please make sure that passed `negative_prompt` matches the batch size of `prompt`.)rf   rg   rh   r9   rl   r~   repeatviewtype	TypeErrorr1   )r   rW   r   r   r   rB   rC   rX   r-   rY   
batch_size_seq_lens                r"   encode_prompt'CosmosTextToWorldPipeline.encode_prompt   s   L 1411'44&&VJ&,,Q/J  66v 7 M
 *//MA)004I1MM)..z/QSZ\^_M&+A+I-3O@J?\_@`@`j+<<fuO!d6l$:O&OUVZ[jVkUl mV~Q(  s?33 )/)::J3K_J` ax/
| <33  &*%?%?&X^ &@ &"
 388MA%;%B%B1F[]^%_"%;%@%@Acelnp%q"44r%        y   r   num_channels_latents   heightwidth
num_frames	generatorrA   returnc
                    U	b0  U	R                  XvS9U R                  R                  R                  -  $ US-
  U R                  -  S-   n
X0R
                  -  nX@R
                  -  nXXU4n[        U[        5      (       a*  [        U5      U:w  a  [        S[        U5       SU S35      e[        XXvS9n	XR                  R                  R                  -  $ )N)r-   rY   r   z/You have passed a list of generators of length z+, but requested an effective batch size of z@. Make sure the batch size matches the length of the generators.)r   r-   rY   )rk   r:   rO   	sigma_maxrQ   rS   rg   listr9   r1   r   )r   r   r   r   r   r   rY   r-   r   rA   num_latent_frameslatent_heightlatent_widthrl   s                 r"   prepare_latents)CosmosTextToWorldPipeline.prepare_latents:  s     ::V:9DNN<Q<Q<[<[[['!^0N0NNQRR"?"?? = ==3DUabi&&3y>Z+GA#i.AQ R&<'gi 
 u&V..8888r%   c           
        ^  US-  S:w  d	  US-  S:w  a  [        SU SU S35      eUbW  [        U 4S jU 5       5      (       d=  [        ST R                   SU Vs/ s H  ofT R                  ;  d  M  UPM     sn 35      eUb  Ub  [        S	U S
U S35      eUc  Uc  [        S5      eUbC  [        U[        5      (       d-  [        U[
        5      (       d  [        S[        U5       35      eg g g s  snf )Nr   r   z8`height` and `width` have to be divisible by 16 but are z and r   c              3   @   >#    U  H  oTR                   ;   v   M     g 7fN)_callback_tensor_inputs).0kr   s     r"   	<genexpr>9CosmosTextToWorldPipeline.check_inputs.<locals>.<genexpr>b  s      F
7Y!---7Ys   z2`callback_on_step_end_tensor_inputs` has to be in z, but found zCannot forward both `prompt`: z and `prompt_embeds`: z2. Please make sure to only forward one of the two.zeProvide either `prompt` or `prompt_embeds`. Cannot leave both `prompt` and `prompt_embeds` undefined.z2`prompt` has to be of type `str` or `list` but is )r1   allr   rg   rh   r   r   )r   rW   r   r   rB   "callback_on_step_end_tensor_inputsr   s   `      r"   check_inputs&CosmosTextToWorldPipeline.check_inputsW  sr    B;!urzQWX^W__dejdkklmnn-9# F
7YF
 C
 C
 DTEaEaDbbn  |^  pH  |^vw  ko  kG  kG  bGpq  |^  pH  oI  J  -";08N}o ^0 0  ^ 5w  FC)@)@TZ\`IaIaQRVW]R^Q_`aa Jb)@ pHs   C01C0c                     U R                   $ r   _guidance_scaler   s    r"   guidance_scale(CosmosTextToWorldPipeline.guidance_scaleu  s    ###r%   c                      U R                   S:  $ )Ng      ?r   r   s    r"   r   5CosmosTextToWorldPipeline.do_classifier_free_guidancey  s    ##c))r%   c                     U R                   $ r   )_num_timestepsr   s    r"   num_timesteps'CosmosTextToWorldPipeline.num_timesteps}  s    """r%   c                     U R                   $ r   )_current_timestepr   s    r"   current_timestep*CosmosTextToWorldPipeline.current_timestep  s    %%%r%   c                     U R                   $ r   )
_interruptr   s    r"   	interrupt#CosmosTextToWorldPipeline.interrupt  s    r%   r   g      @   pilr,   r   fpsoutput_typereturn_dictcallback_on_step_endr   c                 X   U R                   c  [        SU R                   S35      e[        U[        [
        45      (       a  UR                  nU R                  XXLU5        Xpl        SU l	        SU l
        U R                  nU R                   b  U R                   R                  U5        UbR  [        U[        5      (       a  U/OUnU H2  nU R                   R                  U5      (       a  M%  [        SU S35      e   U R                   R                  S5        Ub  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [!        U5      nOUR"                  S	   nU R%                  UUU R&                  U	UUUUS
9u  nn[)        U R*                  UU5      u  nnU R,                  R.                  nU R,                  R0                  R2                  nU R5                  UU	-  UUUU[6        R8                  UU
U5	      nUR;                  SSX4US9n[!        U5      X`R*                  R<                  -  -
  n[!        U5      U l        U RA                  US9 n[C        U5       GHS  u  nnU RD                  (       a  M  UU l	        URG                  UR"                  S	   5      R                  U5      nUn U R*                  RI                  U U5      n U R                  U5      n U R-                  U UUUUSS9S	   n!Un"U R&                  (       aG  U R-                  U UUUUSS9S	   n#[6        RJ                  " U#U!/5      n![6        RJ                  " U"U"/5      n"U R*                  RM                  U!UU"SS9S   n!U R*                  =RN                  S-  sl'        U R&                  (       a)  U!RQ                  S5      u  n#n$U$U RR                  U$U#-
  -  -   n!U R*                  RM                  U!UUSU!S9S	   nUb\  0 n%U H  n&[U        5       U&   U%U&'   M     U" U UUU%5      n'U'RW                  SU5      nU'RW                  SU5      nU'RW                  SU5      nU[!        U5      S-
  :X  d)  US-   U:  a0  US-   U R*                  R<                  -  S	:X  a  URY                  5         [Z        (       d  GM>  [\        R^                  " 5         GMV     SSS5        SU l	        US:X  Gd"  U R`                  R0                  Rb                  GbL  U R`                  R0                  Rb                  U R`                  R0                  Rd                  n)n([6        Rf                  " U(5      Ri                  SU R`                  R0                  Rj                  SSS5      SS2SS2SURm                  S5      24   R                  U5      n([6        Rf                  " U)5      Ri                  SU R`                  R0                  Rj                  SSS5      SS2SS2SURm                  S5      24   R                  U5      n)UU)-  U R*                  R0                  Rn                  -  U(-   nO"XR*                  R0                  Rn                  -  nU R`                  Rq                  UR                  U R`                  R.                  5      SS9S	   n*U R                   Gb)  U R                   R                  U5        U Rr                  Ru                  U*SS9n*U*S-  Rw                  [x        Rz                  5      n*/ n+U* H/  n,U R                   R}                  U,5      n,U+R                  U,5        M1     [x        R                  " U+5      Rw                  [x        R8                  5      S-  S-  S-
  n*[6        R                  " U*5      R                  S	SSSS5      n*U Rr                  Ru                  U*US9n*U R                   R                  S5        OU Rr                  Ru                  U*US9n*OUn*U R                  5         U(       d  U*4$ [        U*S9$ ! , (       d  f       GNd= f)a  
The call function to the pipeline for generation.

Args:
    prompt (`str` or `List[str]`, *optional*):
        The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
        instead.
    height (`int`, defaults to `720`):
        The height in pixels of the generated image.
    width (`int`, defaults to `1280`):
        The width in pixels of the generated image.
    num_frames (`int`, defaults to `121`):
        The number of frames in the generated video.
    num_inference_steps (`int`, defaults to `36`):
        The number of denoising steps. More denoising steps usually lead to a higher quality image at the
        expense of slower inference.
    guidance_scale (`float`, defaults to `7.0`):
        Guidance scale as defined in [Classifier-Free Diffusion
        Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` is defined as `w` of equation 2.
        of [Imagen Paper](https://huggingface.co/papers/2205.11487). Guidance scale is enabled by setting
        `guidance_scale > 1`.
    fps (`int`, defaults to `30`):
        The frames per second of the generated video.
    num_videos_per_prompt (`int`, *optional*, defaults to 1):
        The number of images to generate per prompt.
    generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
        A [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) to make
        generation deterministic.
    latents (`torch.Tensor`, *optional*):
        Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
        generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
        tensor is generated by sampling using the supplied random `generator`.
    prompt_embeds (`torch.Tensor`, *optional*):
        Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
        provided, text embeddings will be generated from `prompt` input argument.
    negative_prompt_embeds (`torch.FloatTensor`, *optional*):
        Pre-generated negative text embeddings. For PixArt-Sigma this negative prompt should be "". If not
        provided, negative_prompt_embeds will be generated from `negative_prompt` input argument.
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generated image. Choose between `PIL.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`CosmosPipelineOutput`] instead of a plain tuple.
    callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*):
        A function or a subclass of `PipelineCallback` or `MultiPipelineCallbacks` that is called at the end of
        each denoising step during the inference. with the following arguments: `callback_on_step_end(self:
        DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` will include a
        list of all tensors as specified by `callback_on_step_end_tensor_inputs`.
    callback_on_step_end_tensor_inputs (`List`, *optional*):
        The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
        will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
        `._callback_tensor_inputs` attribute of your pipeline class.

Examples:

Returns:
    [`~CosmosPipelineOutput`] or `tuple`:
        If `return_dict` is `True`, [`CosmosPipelineOutput`] is returned, otherwise a `tuple` is returned where
        the first element is a list with the generated images and the second element is a list of `bool`s
        indicating whether the corresponding generated image contains "not-safe-for-work" (nsfw) content.
Nz)You have disabled the safety checker for z. This is in violation of the [NVIDIA Open Model License Agreement](https://www.nvidia.com/en-us/agreements/enterprise-software/nvidia-open-model-license). Please ensure that you are compliant with the license agreement.Fz5Cosmos Guardrail detected unsafe text in the prompt: zR. Please ensure that the prompt abides by the NVIDIA Open Model License Agreement.rt   r   r   )rW   r   r   r   rB   rC   r-   rX   )rY   )total)hidden_statestimestepencoder_hidden_statesr   padding_maskr   )r   r   )r   pred_original_samplerA   rB   rC   latentrc   np)r      g     o@   r
   )frames)ErD   r1   r8   rg   r   r   tensor_inputsr   r   r   r   rf   rk   rh   check_text_safetyr   r9   rl   r   r   r=   r:   rG   rY   rO   in_channelsr   rm   float32	new_zerosorderr   progress_barru   r   expandscale_model_inputcatstep_step_indexchunkr   localspopupdateXLA_AVAILABLExm	mark_steprH   latents_meanlatents_stdtensorr   latent_channelssize
sigma_datadecoderT   postprocess_videoastyper   uint8check_video_safetyappendstack
from_numpypermutemaybe_free_model_hooksr   )-r   rW   r   r   r   r   r,   r   r   r   r   rA   rB   rC   r   r   r   r   rX   r-   prompt_listpr   r.   transformer_dtyper   r   num_warmup_stepsr   r|   tr   latent_model_input
noise_predsamplenoise_pred_uncondnoise_pred_condcallback_kwargsr   callback_outputsr   r   videovideo_batchvids-                                                r"   __call__"CosmosTextToWorldPipeline.__call__  s   l &;DNN;K LS T  *-=?U,VWW1E1S1S. 	&%@bc-!%''*""6*!*4VS*A*Avhv$A..@@CC(STUSV WX Y  % ""5) *VS"9"9JJvt$<$<VJ&,,Q/J +(,(H(H"7'#9 3  	
	
" *<DNNL_ag)h&	& !,,22#//66BB&&.. MM

 ((AvDU(V y>,?..BVBV,VV!)n%89\!),1>>)*&88GMM!$45889JK%,"%)^^%E%EFXZ[%\"%7%:%:;L%M"!--"4%*7!- % .  
 !33(,(8(8&8!).D%1$) )9 ) )% "',=z+J!KJ"YY'78F "^^00QTY0Z[\]
**a/*339C9I9I!9L6%!043F3F/\mJm3n!nJ ..--7T^ .  (3&(O?-3Xa[* @';D!Q'X$.229gFG$4$8$8-$XM-=-A-ABZ\r-s* I**A9I/IqSTuX\XfXfXlXlNlpqNq '') =LLN{ - :@ "&h&xx++7,0HHOO,H,H$((//JeJekLL.T!TXX__<<b!QG1N_PWP\P\]^P_N_H_aR[  LL-T!TXX__<<b!QG1N_PWP\P\]^P_N_H_aR[ 
 "K/$..2G2G2R2RRUaa!NN$9$9$D$DDHHOOGJJtxx~~$>EORSTUE"".##&&v.,,>>uRV>W,,RXX6  C--@@EC&&s+ ! -44RZZ@5H1LqP((/771aAF,,>>uR]>^##&&u-,,>>uR]>^E 	##%8O#511W :9s   I`#`
`))r   r   r   r   rS   rQ   rT   r   )NrV   NN)NTr   NNrV   NN)r   r   r   NNNN)NN)/r'   r(   r)   r*   __doc__model_cpu_offload_seqr   _optional_componentsr   r	   r   r   r   r   r#   r   rh   r   intr   rm   r-   rY   r~   rj   Tensorr   	Generatorr   r   propertyr   r   r   r   r   no_gradr   EXAMPLE_DOC_STRINGfloatr   r   r   r   r  r+   __classcell__)r8   s   @r"   r?   r?      sn   , =T,- /3^$^ #^ .	^
 !^ %^ ,^ ^> )-#&)-'+(c49n%( !( &	(
 $(Z <@,0%&049=#&)-'+Q5c49n%Q5 "%T#Y"78Q5 &*	Q5
  #Q5  -Q5 !) 6Q5 !Q5 &Q5 $Q5n '+)-MQ*.99 !9 	9
 9 9 $9 &9 E%//43H"HIJ9 %,,'9 
9D +/b< $ $ * * # # & &   ]]_12 )-;?#% #/0MQ*.049=%*  9B#&+M2c49n%M2 "%T#Y"78M2 	M2
 M2 M2 !M2 M2 M2  (}M2 E%//43H"HIJM2 %,,'M2  -M2 !) 6M2 c]M2  !M2" '(Cd+T124DF\\]
#M2( -1I)M2* !+M2 3 M2r%   r?   )NNNN)3r3   typingr   r   r   r   r   numpyr   rm   transformersr   r	   	callbacksr   r   modelsr   r   
schedulersr   utilsr   r   r   r   utils.torch_utilsr   rT   r   pipeline_utilsr   pipeline_outputr   cosmos_guardrailr   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr'   rp   r  r
  rh   r-   r  r=   r?   r&   r%   r"   <module>r!     s     8 8   8 A C + n n - - . 1 !""4  ))MM			H	% , *.15%)$(8*!#8* U3,-.8* S	"	8*
 T%[!8*vT2 1 T2r%   