Closed wbclark closed 10 months ago
see #48, I implemented it in a way that should be usable by any script no matter whether they run before or after neutral prompt.
Sorry, I could have explained my use-case better. My goal isn't to export the quantity φ
or control it from another extension, although that is a welcome feature for sure (adetailer integration comes to mind).
I want to export the quantity which captures how much the cfg-rescaled guidance differs from the guidance before rescaling and use this quantity within other extensions to dynamically schedule other types of guidance. One application is research into the effects of generalized adaptive guidance mechanisms.
A better implementation might look like a guidance stats module in neutral prompt that makes torch.std(cond)
and torch.std(cfg_cond)
observable. Would you consider something like this?
Sure, we can do this. I suggest we replace the torch.std calls with a custom function that takes as input the two conds and the current sampling step number so external code has a way to know where we are, and then implement it as torch.std / torch.std by default if no special function is defined for that step.
Would this solution cover your use case?
Is there a reason you want neutral prompt to do this btw? It may be better to implement this in another new extension. If this is not possible or may lead to issues for some reason, we can implement it here.
I'm closing this for now, but please leave a comment if there is still an unmet need that requires a change in the repo and we can find a way to make this work.
This allows other extensions and scripts to get and use the CFG rescale factor: from lib_neutral_prompt.cfg_denoiser_hijack import CFGRescaleFactorSingleton current_rescale_factor = CFGRescaleFactorSingleton.get_cfg_rescale_factor()
My particular use case involves setting self-attention guidance scale per denoising step from the cfg_rescale_factor