
    +h                        S SK r S SKJrJr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Jr  SSKJr  SS	KJr  SS
KJrJrJr  SSK J!r!  SSK"J#r#  \" 5       (       a  S SK$J%s  J&r'  Sr(OSr(\RR                  " \*5      r+Sr,   SS\-S\.S\.S\.4S jjr/    SS\\-   S\\\0\Rb                  4      S\\\-      S\\\.      4S jjr2 " S S\5      r3g)    N)AnyCallableDictListOptionalTupleUnion)AutoTokenizerGlmModel   )MultiPipelineCallbacksPipelineCallback)PipelineImageInputVaeImageProcessor)AutoencoderKLCogView4Transformer2DModel)DiffusionPipeline)FlowMatchEulerDiscreteScheduler)is_torch_xla_availableloggingreplace_example_docstring)randn_tensor   )CogView4PipelineOutputTFaw  
    Examples:
        ```python
        >>> import torch
        >>> from diffusers import CogView4ControlPipeline

        >>> pipe = CogView4ControlPipeline.from_pretrained("THUDM/CogView4-6B-Control", torch_dtype=torch.bfloat16)
        >>> control_image = load_image(
        ...     "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png"
        ... )
        >>> prompt = "A bird in space"
        >>> image = pipe(prompt, control_image=control_image, height=1024, width=1024, guidance_scale=3.5).images[0]
        >>> image.save("cogview4-control.png")
        ```
base_seq_len
base_shift	max_shiftreturnc                 "    X-  S-  nXC-  U-   nU$ )Ng      ? )image_seq_lenr   r   r   mmus         p/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/pipelines/cogview4/pipeline_cogview4_control.pycalculate_shiftr%   <   s"     
	%#-A	
	#BI    num_inference_stepsdevice	timestepssigmasc                 b   S[        [        R                  " U R                  5      R                  R                  5       5      ;   nS[        [        R                  " U R                  5      R                  R                  5       5      ;   nUbY  UbV  U(       d   U(       d  [        SU R                   S35      eU R                  " SX4US.UD6  U R                  n[        U5      nX14$ UbQ  UcN  U(       d  [        SU R                   S35      eU R                  " SX2S.UD6  U R                  n[        U5      nX14$ UcQ  UbN  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.
r)   r*   zThe current scheduler class z's `set_timesteps` does not support custom timestep or sigma schedules. Please check whether you are using the correct scheduler.)r)   r*   r(   zx's `set_timesteps` does not support custom timestep schedules. Please check whether you are using the correct scheduler.)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    )
setinspect	signatureset_timesteps
parameterskeys
ValueError	__class__r)   len)	schedulerr'   r(   r)   r*   kwargsaccepts_timestepsaccepts_sigmass           r$   retrieve_timestepsr9   H   s   > $s7+<+<Y=T=T+U+`+`+e+e+g'hhW%6%6y7N7N%O%Z%Z%_%_%a!bbN!3 .y/B/B.C Dj k  	\)6\U[\''	!)n, ))+ 
	6> .y/B/B.C Da b  	M)MfM''	!)n )) 
	v1.y/B/B.C D_ `  	GvGG''	!)n )) 	 3MFMfM''	))r&   c            3       "  ^  \ rS rSrSr/ rSr/ SQrS\S\	S\
S\S	\4
U 4S
 jjr    S:S\\\\   4   S\S\\R(                     S\\R*                     4S jjr        S;S\\\\   4   S\\\\\   4      S\S\S\\R0                     S\\R0                     S\\R(                     S\\R*                     S\4S jjrS<S jr  S=S jr  S>S jr\S 5       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SS$SSSSSSS%S&SSSS'/S4S\\\\\   4      S\\\\\   4      S(\'S)\\   S*\\   S+\S,\\\      S-\\\(      S.\(S\S/\\\RR                  \\RR                     4      S'\\RT                     S\\RT                     S\\RT                     S0\\+\\4      S1\+\\4   S2\S3\S4\\,\\-4      S5\\\.\\\,/S4   \/\04      S6\\   S\S7\\1\+4   4.S8 jj5       5       r2S9r3U =r4$ )?CogView4ControlPipeline   a  
Pipeline for text-to-image generation using CogView4.

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

Args:
    vae ([`AutoencoderKL`]):
        Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.
    text_encoder ([`GLMModel`]):
        Frozen text-encoder. CogView4 uses [glm-4-9b-hf](https://huggingface.co/THUDM/glm-4-9b-hf).
    tokenizer (`PreTrainedTokenizer`):
        Tokenizer of class
        [PreTrainedTokenizer](https://huggingface.co/docs/transformers/main/en/main_classes/tokenizer#transformers.PreTrainedTokenizer).
    transformer ([`CogView4Transformer2DModel`]):
        A text conditioned `CogView4Transformer2DModel` to denoise the encoded image latents.
    scheduler ([`SchedulerMixin`]):
        A scheduler to be used in combination with `transformer` to denoise the encoded image latents.
ztext_encoder->transformer->vae)latentsprompt_embedsnegative_prompt_embeds	tokenizertext_encodervaetransformerr5   c                   > [         TU ]  5         U R                  XX4US9  [        U SS 5      (       a/  S[	        U R
                  R                  R                  5      S-
  -  OSU l        [        U R                  S9U l
        g )N)r@   rA   rB   rC   r5   rB      r      )vae_scale_factor)super__init__register_modulesgetattrr4   rB   configblock_out_channelsrG   r   image_processor)selfr@   rA   rB   rC   r5   r3   s         r$   rI    CogView4ControlPipeline.__init__   s|     	hq 	 	
 W^^bdikoVpVpc$((//*L*L&MPQ&Q Rvw0$BWBWXr&   N   promptmax_sequence_lengthr(   dtypec           	         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9nUR                  nU R                  USSS9R                  nUR                  S   UR                  S   :  a]  [        R                  " Xg5      (       dB  U R
                  R                  US S 2US-
  S24   5      n[        R                  SU S	U 35        UR                  S   n	S
U	S
-  -
  S
-  n
U
S:  ad  [        R                  " UR                  S   U
4U R
                  R                  UR                  UR                  S9n[        R                   " X/SS9nU R                  UR#                  U5      SS9R$                  S   nUR#                  XCS9nU$ )NlongestTpt)padding
max_length
truncationadd_special_tokensreturn_tensors)rX   r\   r   zXThe following part of your input was truncated because `max_sequence_length` is set to  z	 tokens:    r   )
fill_valuerT   r(   dim)output_hidden_statesrT   r(   )_execution_devicerA   rT   
isinstancestrr@   	input_idsshapetorchequalbatch_decodeloggerwarningfullpad_token_idr(   cattohidden_states)rO   rR   rS   r(   rT   text_inputstext_input_idsuntruncated_idsremoved_textcurrent_length
pad_lengthpad_idsr>   s                r$   _get_glm_embeds'CogView4ControlPipeline._get_glm_embeds   s    14110**00'44&&nn*# % 
 %....SW.Xbb  $(<(<R(@@UcIuIu>>66qJ]`aJadfJfGf7ghLNN'(	,A (--a0NR/0B6
>jj%%a(*5>>66$**%,,	G #YY'@aHN)).*;*;F*CZ^)_mmnpq%((u(Dr&   Tr   negative_promptdo_classifier_free_guidancenum_images_per_promptr>   r?   c
                    U=(       d    U R                   n[        U[        5      (       a  U/OUnUb  [        U5      n
OUR                  S   n
Uc  U R                  XXx5      nUR                  S5      n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)Xx5      nUR                  S5      nUR                  SUS5      nUR                  X-  US5      nXV4$ )a  
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_images_per_prompt (`int`, *optional*, defaults to 1):
        Number of images 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
    max_sequence_length (`int`, defaults to `1024`):
        Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.
r   r   r]    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`.)re   rf   rg   r4   ri   r{   sizerepeatviewtype	TypeErrorr2   )rO   rR   r}   r~   r   r>   r?   r(   rT   rS   
batch_sizeseq_lens               r$   encode_prompt%CogView4ControlPipeline.encode_prompt   s   P 1411'44&&VJ&,,Q/J  00f\M$$Q'%,,Q0EqI%**:+MwXZ[&+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  &*%9%9/`f%n",11!4G%;%B%B1F[]^%_"%;%@%@Acelnp%q"44r&   c	                 $   Ub  UR                  U5      $ UU[        U5      U R                  -  [        U5      U R                  -  4n	[        U[        5      (       a*  [        U5      U:w  a  [        S[        U5       SU S35      e[        XXeS9nU$ )Nz/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.)	generatorr(   rT   )rr   intrG   rf   listr4   r2   r   )
rO   r   num_channels_latentsheightwidthrT   r(   r   r=   ri   s
             r$   prepare_latents'CogView4ControlPipeline.prepare_latents0  s    ::f%%  K4000J$///	
 i&&3y>Z+GA#i.AQ R&<'gi  u&Vr&   c
                 ^   [        U[        R                  5      (       a  OU R                  R	                  XUS9nUR
                  S   n
U
S:X  a  UnOUnUR                  USUR
                  S   U-  S9nUR                  XgS9nU(       a!  U	(       d  [        R                  " U/S-  5      nU$ )N)r   r   r   r   )ra   output_size)r(   rT   rE   )	rf   rj   TensorrN   
preprocessri   repeat_interleaverr   rq   )rO   imager   r   r   r   r(   rT   r~   
guess_modeimage_batch_size	repeat_bys               r$   prepare_image%CogView4ControlPipeline.prepare_imageB  s     eU\\**((33EPU3VE ;;q>q "I .I''	qekkRSnW`F`'a4&zIIugk*Er&   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  oT 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bA  [        U[        5      (       d,  [        U[
        5      (       d  [        S[        U5       35      eUb  Ub  [        S	U SU S35      eUb  Ub  [        SU SU S35      eUbE  UbA  UR                  UR                  :w  a&  [        SUR                   SUR                   S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krO   s     r$   	<genexpr>7CogView4ControlPipeline.check_inputs.<locals>.<genexpr>q  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 z and `negative_prompt_embeds`: z'Cannot forward both `negative_prompt`: zu`prompt_embeds` and `negative_prompt_embeds` must have the same shape when passed directly, but got: `prompt_embeds` z != `negative_prompt_embeds` )r2   allr   rf   rg   r   r   ri   )	rO   rR   r   r   r}   "callback_on_step_end_tensor_inputsr>   r?   r   s	   `        r$   check_inputs$CogView4ControlPipeline.check_inputsd  s:    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"8"D0 9*++]_ 
 &+A+M9/9J K*++]_ 
 $)?)K""&<&B&BB --:-@-@,A B.445Q8  C *L$5 pHs   E&1E&c                     U R                   $ r   _guidance_scalerO   s    r$   guidance_scale&CogView4ControlPipeline.guidance_scale  s    ###r&   c                      U R                   S:  $ )Nr   r   r   s    r$   r~   3CogView4ControlPipeline.do_classifier_free_guidance  s    ##a''r&   c                     U R                   $ r   )_num_timestepsr   s    r$   num_timesteps%CogView4ControlPipeline.num_timesteps  s    """r&   c                     U R                   $ r   )_attention_kwargsr   s    r$   attention_kwargs(CogView4ControlPipeline.attention_kwargs      %%%r&   c                     U R                   $ r   )_current_timestepr   s    r$   current_timestep(CogView4ControlPipeline.current_timestep  r   r&   c                     U R                   $ r   )
_interruptr   s    r$   	interrupt!CogView4ControlPipeline.interrupt  s    r&   2   g      @)r   r   pilr=   control_imager   r   r'   r)   r*   r   r   original_sizecrops_coords_top_leftoutput_typereturn_dictr   callback_on_step_endr   r   c                    [        U[        [        45      (       a  UR                  nU=(       d-    U R                  R
                  R                  U R                  -  nU=(       d-    U R                  R
                  R                  U R                  -  nU=(       d    XE4nXE4nU R                  UUUUUUU5        Xl	        UU l
        SU l        SU l        Ub  [        U[        5      (       a  SnO3Ub!  [        U[        5      (       a  [        U5      nOUR                   S   nU R"                  nU R%                  UUU R&                  U
UUUUS9u  pU R                  R
                  R(                  S-  nU R+                  UUUUU
-  U
UU R,                  R.                  S9nUR                   SS u  pESnU R,                  R1                  U5      R2                  R5                  5       nUU-
  U R,                  R
                  R6                  -  nU R9                  UU
-  UUU[:        R<                  UUU5      n[:        R>                  " U/UR.                  US	9n[:        R>                  " U/UR.                  US	9n[:        R>                  " U/UR.                  US	9nURA                  UU
-  S5      nURA                  UU
-  S5      nURA                  UU
-  S5      nX@R                  -  XPR                  -  -  U R                  R
                  RB                  S-  -  nUc6  [D        RF                  " U RH                  R
                  RJ                  S
U5      O[D        RL                  " U5      nURO                  [D        RP                  5      RO                  [D        R<                  5      nUc"  XpRH                  R
                  RJ                  -  OUn[S        UU RH                  R
                  RU                  SS5      U RH                  R
                  RU                  SS5      U RH                  R
                  RU                  SS5      5      n[W        U RH                  UUXxUS9u  pv[        U5      U l,        U R                  R.                  n[[        [        U5      X`RH                  R\                  -  -
  S5      nU R_                  US9 n [a        U5       GH  u  n!n"U Rb                  (       a  M  U"U l        [:        Rd                  " X/SS9Rg                  U5      n#U"Ri                  UR                   S   5      n$U R	                  U#UU$UUUUSS9S   n%U R&                  (       a/  U R	                  U#UU$UUUUSS9S   n&U&U Rj                  U%U&-
  -  -   n'OU%n'U RH                  Rm                  U'U"USS9S   nUbs  0 n(U H  n)[o        5       U)   U(U)'   M     U" U U!U RH                  Rp                  U!   U(5      n*U*Rs                  SU5      nU*Rs                  SU5      nU*Rs                  SU5      nU![        U5      S-
  :X  d)  U!S-   U:  a0  U!S-   U RH                  R\                  -  S:X  a  U Ru                  5         [v        (       d  GM  [x        Rz                  " 5         GM     SSS5        SU l        US:X  de  URg                  U R,                  R.                  5      U R,                  R
                  R6                  -  nU R,                  R}                  USUS9S   n+OUn+U R~                  R                  U+US9n+U R                  5         U(       d  U+4$ [        U+S9$ ! , (       d  f       N= f)a  
Function invoked when calling 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`.
    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`).
    height (`int`, *optional*, defaults to self.transformer.config.sample_size * self.vae_scale_factor):
        The height in pixels of the generated image. If not provided, it is set to 1024.
    width (`int`, *optional*, defaults to self.transformer.config.sample_size * self.vae_scale_factor):
        The width in pixels of the generated image. If not provided it is set to 1024.
    num_inference_steps (`int`, *optional*, defaults to `50`):
        The number of denoising steps. More denoising steps usually lead to a higher quality image at the
        expense of slower inference.
    timesteps (`List[int]`, *optional*):
        Custom timesteps to use for the denoising process with schedulers which support a `timesteps` argument
        in their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is
        passed will be used. Must be in descending order.
    sigmas (`List[float]`, *optional*):
        Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
        their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
        will be used.
    guidance_scale (`float`, *optional*, defaults to `5.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`. Higher guidance scale encourages to generate images that are closely linked to
        the text `prompt`, usually at the expense of lower image quality.
    num_images_per_prompt (`int`, *optional*, defaults to `1`):
        The number of images to generate per prompt.
    generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
        One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
        to make generation deterministic.
    latents (`torch.FloatTensor`, *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 will ge generated by sampling using the supplied random `generator`.
    prompt_embeds (`torch.FloatTensor`, *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. 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.
    original_size (`Tuple[int]`, *optional*, defaults to (1024, 1024)):
        If `original_size` is not the same as `target_size` the image will appear to be down- or upsampled.
        `original_size` defaults to `(height, width)` if not specified. Part of SDXL's micro-conditioning as
        explained in section 2.2 of
        [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
    crops_coords_top_left (`Tuple[int]`, *optional*, defaults to (0, 0)):
        `crops_coords_top_left` can be used to generate an image that appears to be "cropped" from the position
        `crops_coords_top_left` downwards. Favorable, well-centered images are usually achieved by setting
        `crops_coords_top_left` to (0, 0). Part of SDXL's micro-conditioning as explained in section 2.2 of
        [https://huggingface.co/papers/2307.01952](https://huggingface.co/papers/2307.01952).
    output_type (`str`, *optional*, defaults to `"pil"`):
        The output format of the generate image. Choose between
        [PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
    return_dict (`bool`, *optional*, defaults to `True`):
        Whether or not to return a [`~pipelines.pipeline_CogView4.CogView4PipelineOutput`] instead of a plain
        tuple.
    attention_kwargs (`dict`, *optional*):
        A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
        `self.processor` in
        [diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
    callback_on_step_end (`Callable`, *optional*):
        A function that calls at the end of each denoising steps during the inference. The function is called
        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.
    max_sequence_length (`int`, defaults to `224`):
        Maximum sequence length in encoded prompt. Can be set to other values but may lead to poorer results.
Examples:

Returns:
    [`~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput`] or `tuple`:
    [`~pipelines.cogview4.pipeline_CogView4.CogView4PipelineOutput`] if `return_dict` is True, otherwise a
    `tuple`. When returning a tuple, the first element is a list with the generated images.
NFr   r   )r   r>   r?   rS   r(   rE   )r   r   r   r   r   r(   rT   rc   rd   g      ?base_image_seq_len   r         ?r         ?)r#   )totalr`   )rs   encoder_hidden_statestimestepr   target_sizecrop_coordsr   r   )r   r=   r>   r?   latent)r   r   )r   )images)Crf   r   r   tensor_inputsrC   rL   sample_sizerG   r   r   r   r   r   rg   r   r4   ri   re   r   r~   in_channelsr   rB   rT   encodelatent_distsamplescaling_factorr   rj   float32tensorr   
patch_sizenplinspacer5   num_train_timestepsarrayastypeint64r%   getr9   r   maxorderprogress_bar	enumerater   rq   rr   expandr   steplocalsr*   popupdateXLA_AVAILABLExm	mark_stepdecoderN   postprocessmaybe_free_model_hooksr   ),rO   rR   r}   r   r   r   r'   r)   r*   r   r   r   r=   r>   r?   r   r   r   r   r   r   r   rS   r   r   r(   latent_channelsvae_shift_factorr!   r#   transformer_dtypenum_warmup_stepsr   itlatent_model_inputr   noise_pred_condnoise_pred_uncond
noise_predcallback_kwargsr   callback_outputsr   s,                                               r$   __call__ CogView4ControlPipeline.__call__  s   f *-=?U,VWW1E1S1S.V4++22>>AVAVVT))00<<t?T?TT%8&o 	."	
  .!1!% *VS"9"9JJvt$<$<VJ&,,Q/J'' 150B0B,,"7'#9 3 1C 	1
- **11==B**!$99"7((.. + 
 &++BC06BBIIK&)99TXX__=[=[[&&..MM	
 m_M<O<OX^_llK=8K8KTZ[ %.C-DML_L_hn o%,,Z:O-OQRS!((6K)KQO 5 < <ZJ_=_ab c !$9$99eG\G\>\]##..1
   KK--AA3H[\)$ 	
 $$RXX.55bjjA	JP.^^22FFF^dNN!!%%&:C@NN!!%%lD9NN!!%%k48	
 *<NN/r*
&	 ")n ,,22s9~0CnnFZFZ0ZZ\]^%89\!),1>>)*&%*YY/GQ%O%R%RSd%e" 88GMM!$45"&"2"2"4*7%"/ + 5%5 % #3 	# 	# 33(,(8(8&8.D!)&3$/$9)9$) )9 	) 	)% "3T5H5HO^oLo5p!pJ!0J..--j!WRW-XYZ[ (3&(O?-3Xa[* @';D!T^^EZEZ[\E]_n'o$.229gFG$4$8$8-$XM-=-A-ABZ\r-s*I**A9I/IqSTuX\XfXfXlXlNlpqNq '') =LLNk - :p "&h&jj0488??3Q3QQGHHOOG)OTUVWEE$$00K0P 	##%8O%U33Q :9s    F4]9]
])r   r   r   r   r   rN   rG   )NrQ   NN)NTr   NNNNrQ   r   )FF)NN)5__name__
__module____qualname____firstlineno____doc___optional_componentsmodel_cpu_offload_seqr   r
   r   r   r   r   rI   r	   rg   r   r   r   rj   r(   rT   r{   boolr   r   r   r   r   propertyr   r~   r   r   r   r   no_gradr   EXAMPLE_DOC_STRINGr   float	GeneratorFloatTensorr   r   r   r   r   r   r   r  __static_attributes____classcell__)r3   s   @r$   r;   r;      sO   ( <TY Y Y 	Y
 0Y 3Y& )-#')-'+)c49n%) !) &	)
 $)^ <@,0%&049=)-'+#'M5c49n%M5 "%T#Y"78M5 &*	M5
  #M5  -M5 !) 6M5 &M5 $M5 !M5^6 %* R #1f $ $ ( ( # # & & & &   ]]_12 37;?,0 $##%)-(, #%&MQ/359>B3717  59 9B#'3h4sDI~./h4 "%T#Y"78h4 *	h4
 h4 }h4 !h4 DI&h4 e%h4 h4  #h4 E%//43H"HIJh4 %++,h4   1 12h4 !)):): ;h4   c3h0!h4"  %S#X#h4$ %h4& 'h4( #4S>2)h4* '(Cd+T124DF\\]
+h40 -1I1h42 !3h44 
%u,	-5h4 3 h4r&   r;   )r   r   r   )NNNN)4r-   typingr   r   r   r   r   r   r	   numpyr   rj   transformersr
   r   	callbacksr   r   rN   r   r   modelsr   r   pipelines.pipeline_utilsr   
schedulersr   utilsr   r   r   utils.torch_utilsr   pipeline_outputr   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr  rm   r  r   r  r%   rg   r(   r9   r;   r    r&   r$   <module>r%     s     D D D   0 A D ? 9 9 O O - 3 ))MM			H	% ( 	  	
  *.15%)$(@*!#@* U3,-.@* S	"	@*
 T%[!@*FQ	4/ Q	4r&   