Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the sampling loop of pipelines modular, with designated inputs that can be handled iteratively with functions and a default sampler step function #7808

Open
AmericanPresidentJimmyCarter opened this issue Apr 28, 2024 · 3 comments
Labels
stale Issues that haven't received updates

Comments

@AmericanPresidentJimmyCarter
Copy link
Contributor

AmericanPresidentJimmyCarter commented Apr 28, 2024

Model/Pipeline/Scheduler description

Related to #7761 .

This is an effective replacement for the existing sampling loop function and the many, many kwargs that were made to allow the user to control it or inject callbacks into it.

class SamplingInput:
    def __init__(self, img, text_embedding, unet, timestep=None, **kwargs):
        self.img = img
        self.text_embedding = text_embedding
        self.unet = unet
        self.timestep = timestep

# ... lots of other code ...

        inp = SamplingInput(img, text_embedding, unet)
        with self.progress_bar(total=num_inference_steps) as progress_bar:
            for i, t in enumerate(timesteps):
                inp.timestep = t
                for sampling_function in self.sampling_functions:
                    inp = sampling_function(inp)
                    
        output_img = inp.img

This will give the end user complete control of the sampling loop, allow the repo to add "official inline sampling functions" like report an image to an endpoint so that the user can view intermediate steps, etc.

We can add an argument sampling_functions: list[Callable]=[default_sampling_function] into the __call__ as a new, backwards compatible kwarg.

This requires a rewrite of all of the pipelines, but as it is a backwards compatible change it can be introduced to any of the more popular pipelines first.

@Beinsezii
Copy link
Contributor

Should the default functionality be a single function or a list of smaller functions do you think?

If it was a list such as [f_a, f_b, f_c] you could easily hook into any stage by simply funcs.insert(f_a1, 1) or funcs[1] = f_b_custom, but that makes the MVP more complex.

@AmericanPresidentJimmyCarter
Copy link
Contributor Author

You could always decompose the default function to have multiple other functions that are called inside it, which the user can also import and use in their functions if needed.

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@github-actions github-actions bot added the stale Issues that haven't received updates label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issues that haven't received updates
Projects
None yet
Development

No branches or pull requests

2 participants