---
name: diffusers_set_scheduler
kind: function
lang: py
domain: ml
version: "1.0.0"
purity: impure
signature: "def diffusers_set_scheduler(pipe: Any, sampler: str) -> Any"
description: "Reemplaza el scheduler de un pipeline diffusers por la clase correspondiente al sampler solicitado. Usa from_config para heredar configuracion base del modelo."
tags: [diffusers, ml, scheduler, sampler, image-generation, pendiente-usar]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [diffusers]
params:
  - name: pipe
    desc: "Pipeline diffusers cargado con atributo pipe.scheduler y pipe.scheduler.config."
  - name: sampler
    desc: "Nombre del sampler: euler, euler_a, dpm++2m, dpm++2m_v2, heun, dpm2, lcm."
output: "El mismo pipe con pipe.scheduler reemplazado. Modificacion in-place, retorna pipe para composicion."
tested: true
tests:
  - "euler cambia scheduler a EulerDiscreteScheduler"
  - "sampler invalido lanza ValueError"
test_file_path: "python/functions/ml/tests/test_diffusers_backend.py"
file_path: "python/functions/ml/diffusers_set_scheduler.py"
---

## Ejemplo

```python
from diffusers_load_pipeline import diffusers_load_pipeline
from diffusers_set_scheduler import diffusers_set_scheduler
from model_ref import ModelRef

model = ModelRef(name="sd-turbo", model_type="sd15", path="/path/to/model")
pipe = diffusers_load_pipeline(model)
pipe = diffusers_set_scheduler(pipe, "euler_a")
# type(pipe.scheduler).__name__ == "EulerAncestralDiscreteScheduler"
```

## Mapping de samplers

| sampler      | clase diffusers                    | kwargs extra                              |
|--------------|------------------------------------|-------------------------------------------|
| euler        | EulerDiscreteScheduler             | —                                         |
| euler_a      | EulerAncestralDiscreteScheduler    | —                                         |
| dpm++2m      | DPMSolverMultistepScheduler        | algorithm_type="dpmsolver++"              |
| dpm++2m_v2   | DPMSolverMultistepScheduler        | algorithm_type="dpmsolver++", solver_order=2 |
| heun         | HeunDiscreteScheduler              | —                                         |
| dpm2         | KDPM2DiscreteScheduler             | —                                         |
| lcm          | LCMScheduler                       | —                                         |

## Notas

Usa `SchedulerCls.from_config(pipe.scheduler.config, **extra_kwargs)` para
heredar `beta_start`, `beta_end`, `clip_sample`, etc. del modelo base.

Import lazy de diffusers — ImportError descriptivo si no instalado.
