Comfy-Org / Comfy-Org/ComfyUI

Modular KSampler Hooks / Overrides

Open
#9,307 0 comments 0 reactions 0 assignees View on GitHub
bug-cop:non-blocking Feature
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

### Feature Idea

Currently, changing a single line in `KSamplerX0Inpaint` requires replacing the entire class. For example, to tweak the x = ... step below, I must duplicate all the surrounding code:

```python
class KSamplerX0Inpaint:
def __init__(self, model, sigmas):
self.inner_model = model
self.sigmas = sigmas

def __call__(self, x, sigma, denoise_mask, model_options={}, seed=None):
if denoise_mask is not None:
if "denoise_mask_function" in model_options:
denoise_mask = model_options["denoise_mask_function"](
sigma, denoise_mask,
extra_options={"model": self.inner_model, "sigmas": self.sigmas}
)
latent_mask = 1. - denoise_mask
x = x * denoise_mask + self.inner_model.inner_model.scale_latent_inpaint(
x=x, sigma=sigma, noise=self.noise, latent_image=self.latent_image
) * latent_mask
out = self.inner_model(x, sigma, model_options=model_options, seed=seed)
if denoise_mask is not None:
out = out * denoise_mask + self.latent_image * latent_mask
return out
```

For example, I would like to change the line to something like:
```
x = x * denoise_mask + self.latent_image * latent_mask
```
i.e. inject the original latent instead of the scaled one.

#### Proposal:
Add a modular API or hook system so steps like scale_latent_inpaint can be overridden or swapped via function args or registered hooks, without rewriting the full sampler.

#### Benefits:
Easier experimentation
Less code duplication
Maintainable community variants

Is there an existing way to do this? If not, I’m happy to help prototype it.

### Existing Solutions

_No response_

### Other

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.