Skip to content

feat: add text context CLI parameter#2

Open
happyyzy wants to merge 1 commit into
agent/sdcpp-ggml-q4-fixfrom
agent/sdcpp-text-ctx-cli
Open

feat: add text context CLI parameter#2
happyyzy wants to merge 1 commit into
agent/sdcpp-ggml-q4-fixfrom
agent/sdcpp-text-ctx-cli

Conversation

@happyyzy

Copy link
Copy Markdown
Owner

Summary

Adds a --text-ctx CLI option and passes it through the stable-diffusion.cpp API/runtime configuration.

This is needed by the 1024-resolution Flux/Z-Image reproduction commands that use a shorter text context.

Notes

This PR is stacked on #1 and does not change ggml itself.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 532d513866

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/stable-diffusion.cpp
Comment on lines +3757 to +3760
truncate_text_context_tensor(&condition->c_crossattn, text_ctx, name);
for (size_t i = 0; i < condition->extra_c_crossattns.size(); ++i) {
std::string extra_name = std::string(name) + ".extra_c_crossattns[" + std::to_string(i) + "]";
truncate_text_context_tensor(&condition->extra_c_crossattns[i], text_ctx, extra_name.c_str());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Truncate paired attention masks with context

This helper only shortens c_crossattn and extra_c_crossattns, but some models carry per-token data alongside the context. In particular, Chroma's T5CLIPEmbedder stores the DiT text mask in c_vector (conditioner.hpp:1370), and Flux pads that y tensor into txt_img_mask (flux.hpp:1004) for attention. With --text-ctx smaller than the original Chroma context and chroma_use_dit_mask enabled, the context length is reduced while the mask keeps the old length, so attention receives mismatched/incorrect masking. Please truncate the paired mask tensor when the text context is truncated, or reject this option for masked models.

Useful? React with 👍 / 👎.

params.prompt = prompt.c_str();
params.negative_prompt = negative_prompt.c_str();
params.clip_skip = clip_skip;
params.text_ctx = text_ctx;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Propagate text_ctx through video generation

This copies the new field only into sd_img_gen_params_t. The same SDGenerationParams is used by the video CLI path (examples/cli/main.cpp:768 calls to_sd_vid_gen_params_t()), but sd_vid_gen_params_t and GenerationRequest(sd_vid_gen_params_t*) never carry text_ctx, so --text-ctx N in video generation is accepted and printed in the generation params but leaves request.text_ctx at 0 and never truncates in prepare_image_generation_embeds. Please add the field to the video params path or reject it for video mode.

Useful? React with 👍 / 👎.

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

Successfully merging this pull request may close these issues.

1 participant