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

[FR] Attention Interpolation #39

Open
DrJKL opened this issue May 1, 2024 · 4 comments
Open

[FR] Attention Interpolation #39

DrJKL opened this issue May 1, 2024 · 4 comments

Comments

@DrJKL
Copy link
Contributor

DrJKL commented May 1, 2024

Describe what's missing
Basically, this: https://github.com/ljleb/prompt-fusion-extension/wiki/Attention-Interpolation

Additional context
🙏🏻
Not sure if there's a way to accomplish this using the existing interpolation feature.

@asagi4
Copy link
Owner

asagi4 commented May 1, 2024

I think you can sort of do this already if you combine the MUSimpleWildcard / Jinja nodes from my other repo to generate a [SEQ:...] element with changing weights, ie, you can generate a [SEQ:(a:0.1)(b:0.9):0.1:(a:0.2)(b:0.8):0.2:...] etc. The generated prompt will be long but I think it'll do about the same thing as prompt fusion's interpolation. The MUSimpleWilcard node contains functions to generate sequences like that already, though I admit they aren't the easiest to use.

The existing interpolation feature works on the embedding tensors directly so it's unfortunately not useful.

@DrJKL
Copy link
Contributor Author

DrJKL commented May 1, 2024

Hmmm, this does look like it works, but it's not the prettiest.
attention_interpolation_via_seq.json

@DrJKL
Copy link
Contributor Author

DrJKL commented May 2, 2024

Edited to allow for descending weight

<%- macro step_weight(weight, start, dir) -%>
  <= round(start + (dir * weight), 2) =>
<%- endmacro -%>
<%- macro switch_at(weight, startX, endX) -%>
  <= round(abs(weight) / abs(endX - startX), 2) =>
<%- endmacro -%>

<%- set start = min(__weight-start__, __weight-end__) -%>
<%- set end = max(__weight-start__, __weight-end__) -%>
<%- set dir = 1 if __weight-start__ < __weight-end__ else -1 -%>

[SEQ
<%- for weight in steps(0, end - start, __step-size__) -%>
:(__prompt-segment__:
  <=- step_weight(weight, __weight-start__, dir) -=>):
  <=- switch_at(weight, start, end) -=>
<%- endfor -%>
]

@asagi4
Copy link
Owner

asagi4 commented May 2, 2024

You can make that a bit simpler with MUSimpleWildcard with its in-prompt variable / macro support, but that does get a bit complex.

I actually didn't know Jinja can do macros; I should probably refactor the "built-in" functions in MUSimpleWildcard to use them more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants