同一バッチ内にながーいプロンプトがあると、生成結果が変わってしまう問題の修正 #1338
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
他の長いプロンプトに合わせてパディングを行うと、生成結果が変わってしまいます。
このPRはパディングではなく、トークン列の複製によってトークン長を合わせています(ComfyUIと同じ方法)。
という感じです。
以下の二つのプロンプトリストで試しました。2つ目のプロンプトを適当に長くしています。
生成コマンドは以下の通りです。
元のコードの結果です。右側は2つ目のプロンプトに合わせてパディングされています。

修正後コードの結果です。右側は(ry

数学的にはトークン列が複製されても結果は変わらないはずですが、--fp16を利用すると精度の問題で少し異なる画像が生成されるようです。
全トークン長の最小公倍数まで複製するため、場合によってはトークン長が大きくなって、計算量が跳ね上がってしまいます。ComfyUIでは複製サイズが大きすぎる場合は結合せずに計算するようです。Cross Attentionをプロンプトごとに計算するのがわかりやすいのですかね。