Buckets:
| # Plantillas de docstring y parámetros automáticas | |
| Cada [ModularPipelineBlocks](/docs/diffusers/v0.43.0/es/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks) tiene una propiedad `doc` que se genera automáticamente a partir de su `description`, `inputs`, `intermediate_outputs`, `expected_components` y `expected_configs`. El sistema de docstrings automáticos mantiene las docstrings sincronizadas con la interfaz real del bloque. Las plantillas de parámetros proporcionan descripciones estandarizadas para parámetros que aparecen en muchos pipelines. | |
| ## Auto docstring | |
| Los bloques de pipeline modulares son componibles: puedes anidarlos, encadenarlos en secuencias y reorganizarlos libremente. Sus docstrings siguen el mismo patrón. Cuando un [SequentialPipelineBlocks](/docs/diffusers/v0.43.0/es/api/modular_diffusers/pipeline_blocks#diffusers.SequentialPipelineBlocks) agrega las entradas y salidas de sus subbloques, la documentación debe actualizarse automáticamente sin reescrituras manuales. | |
| El marcador `# auto_docstring` genera docstrings a partir de las propiedades del bloque. Añádelo sobre la definición de una clase para marcarla para la generación automática de docstrings. | |
| ```py | |
| # auto_docstring | |
| class FluxTextEncoderStep(SequentialPipelineBlocks): | |
| ... | |
| ``` | |
| Ejecuta el siguiente comando para generar e insertar las docstrings. | |
| ```bash | |
| python utils/modular_auto_docstring.py --fix_and_overwrite | |
| ``` | |
| La utilidad lee la propiedad `doc` del bloque y la inserta como docstring de la clase. | |
| ```py | |
| # auto_docstring | |
| class FluxTextEncoderStep(SequentialPipelineBlocks): | |
| """ | |
| Text input processing step that standardizes text embeddings for the pipeline. | |
| Inputs: | |
| prompt_embeds (`torch.Tensor`) *required*: | |
| text embeddings used to guide the image generation. | |
| ... | |
| Outputs: | |
| prompt_embeds (`torch.Tensor`): | |
| text embeddings used to guide the image generation. | |
| ... | |
| """ | |
| ``` | |
| También puede verificar sin sobrescribir, o apuntar a un archivo o directorio específico. | |
| ```bash | |
| # Check that all marked classes have up-to-date docstrings | |
| python utils/modular_auto_docstring.py | |
| # Check a specific file or directory | |
| python utils/modular_auto_docstring.py src/diffusers/modular_pipelines/flux/ | |
| ``` | |
| Si alguna clase marcada carece de docstring, la comprobación falla y enumera las clases que necesitan actualizarse. | |
| ``` | |
| Found the following # auto_docstring markers that need docstrings: | |
| - src/diffusers/modular_pipelines/flux/encoders.py: FluxTextEncoderStep at line 42 | |
| Run `python utils/modular_auto_docstring.py --fix_and_overwrite` to fix them. | |
| ``` | |
| ## Plantillas de parámetros | |
| `InputParam` y `OutputParam` definen las entradas y salidas de un bloque. Créalos directamente o usa `.template()` para definiciones estandarizadas de parámetros comunes como `prompt`, `num_inference_steps` o `latents`. | |
| ### InputParam | |
| `InputParam` describe una sola entrada de un bloque. | |
| | Campo | Tipo | Descripción | | |
| |---|---|---| | |
| | `name` | `str` | Nombre del parámetro | | |
| | `type_hint` | `Any` | Anotación de tipo (p. ej., `str`, `torch.Tensor`) | | |
| | `default` | `Any` | Valor predeterminado (si no se establece, el parámetro no tiene valor predeterminado) | | |
| | `required` | `bool` | Si el parámetro es obligatorio | | |
| | `description` | `str` | Descripción legible por humanos | | |
| | `kwargs_type` | `str` | Nombre del grupo para parámetros relacionados (p. ej., `"denoiser_input_fields"`) | | |
| | `metadata` | `dict` | Información adicional arbitraria | | |
| #### Creación de InputParam directamente | |
| ```py | |
| from diffusers.modular_pipelines import InputParam | |
| InputParam( | |
| name="guidance_scale", | |
| type_hint=float, | |
| default=7.5, | |
| description="Scale for classifier-free guidance.", | |
| ) | |
| ``` | |
| #### Usando una plantilla | |
| ```py | |
| InputParam.template("prompt") | |
| # Equivalent to: | |
| # InputParam(name="prompt", type_hint=str, required=True, | |
| # description="The prompt or prompts to guide image generation.") | |
| ``` | |
| Las plantillas establecen automáticamente `name`, `type_hint`, `default`, `required` y `description`. Sobrescribe cualquier campo o añade contexto con el parámetro `note`. | |
| ```py | |
| # Override the default value | |
| InputParam.template("num_inference_steps", default=28) | |
| # Add a note to the description | |
| InputParam.template("prompt_embeds", note="batch-expanded") | |
| # description becomes: "text embeddings used to guide the image generation. ... (batch-expanded)" | |
| ``` | |
| ### OutputParam | |
| `OutputParam` describe una sola salida de un bloque. | |
| | Campo | Tipo | Descripción | | |
| |---|---|---| | |
| | `name` | `str` | Nombre del parámetro | | |
| | `type_hint` | `Any` | Anotación de tipo | | |
| | `description` | `str` | Descripción legible por humanos | | |
| | `kwargs_type` | `str` | Nombre del grupo para parámetros relacionados | | |
| | `metadata` | `dict` | Información adicional arbitraria | | |
| #### Creación de OutputParam directamente | |
| ```py | |
| from diffusers.modular_pipelines import OutputParam | |
| OutputParam(name="image_latents", type_hint=torch.Tensor, description="Encoded image latents.") | |
| ``` | |
| #### Usando una plantilla | |
| ```py | |
| OutputParam.template("latents") | |
| # Add a note to the description | |
| OutputParam.template("prompt_embeds", note="batch-expanded") | |
| ``` | |
| ## Plantillas disponibles | |
| `INPUT_PARAM_TEMPLATES` y `OUTPUT_PARAM_TEMPLATES` se definen en [modular_pipeline_utils.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/modular_pipeline_utils.py). Incluyen parámetros comunes como `prompt`, `image`, `num_inference_steps`, `latents`, `prompt_embeds`, entre otros. Consulte el código fuente para obtener la lista completa de nombres de plantillas disponibles. | |
Xet Storage Details
- Size:
- 5.7 kB
- Xet hash:
- b69a3c9487edc093c0c26f585559c1578ea7cc6260a52c977e1de2586afede5d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.