sipie800 / ComfyUI-PuLID-Flux-Enhanced

Apache License 2.0
67 stars 8 forks source link

Add an unpatcher to revert the monkeypatch, mid-run? #23

Open cchance27 opened 2 weeks ago

cchance27 commented 2 weeks ago

For people using the nodes for part of the workflow would be good if you added an UnApply Pulid Flux ...

Basically just revert the application, drop the pulid_ca, etc, and set forward back to forward_orig's target.

if not hasattr(flux_model, "pulid_ca"):
            # Add perceiver attention, variables and current node data (weight, embedding, sigma_start, sigma_end)
            # The pulid_data is stored in Dict by unique node index,
            # so we can chain multiple ApplyPulidFlux nodes!
            flux_model.pulid_ca = pulid_flux.pulid_ca
            flux_model.pulid_double_interval = pulid_flux.double_interval
            flux_model.pulid_single_interval = pulid_flux.single_interval
            flux_model.pulid_data = {}
            # Replace model forward_orig with our own
            new_method = forward_orig.__get__(flux_model, flux_model.__class__)
            setattr(flux_model, 'forward_orig', new_method)