Skip to content

UPSTREAM PR #18528: llama-graph: fix UB warning from cross-attn mask loop indices - #778

Open
loci-dev wants to merge 1 commit into
mainfrom
upstream-PR18528-branch_nabbi-aggressive-loop-optimizations
Open

UPSTREAM PR #18528: llama-graph: fix UB warning from cross-attn mask loop indices#778
loci-dev wants to merge 1 commit into
mainfrom
upstream-PR18528-branch_nabbi-aggressive-loop-optimizations

Conversation

@loci-dev

@loci-dev loci-dev commented Jan 1, 2026

Copy link
Copy Markdown

Mirrored from ggml-org/llama.cpp#18528

I observed this behavior when building ollama on Gentoo.
Confirmed llm_graph_input_attn_cross::set_input functions are aligned between these two projects so submitting the PR here.

GCC emits the following warning when building with optimizations:

llama-graph.cpp:473:9: warning: iteration 2147483645 invokes undefined
behavior [-Waggressive-loop-optimizations]

The warning is caused by using int loop induction variables against int64_t bounds (n_tokens, n_enc), which allows signed overflow in the induction variable and enables undefined behavior.

This change widens the loop counters to int64_t to match the bounds and removes an unreachable loop of the form:

for (i = n_tokens; i < n_tokens; ++i)

which could never execute.

Thank you

@loci-review

loci-review Bot commented Jan 1, 2026

Copy link
Copy Markdown

Explore the complete analysis inside the Version Insights

I've successfully generated a comprehensive summary report for your project. The report analyzes the performance comparison between two versions of the llama.cpp project (Pull Request #778) and highlights:

Key Highlights:

  1. Most Significant Change: The _M_const_cast function shows a dramatic +284% throughput increase but also a +217% response time increase

  2. Performance Pattern: Mixed results with throughput generally improving but response times increasing for several functions

  3. Areas Affected: Primarily STL container operations including:

    • Tree operations
    • Iterator operations
    • Hash table operations
    • Vector operations
  4. Critical Functions: The report identifies the top 10 functions by both response time and throughput changes, helping you focus on the most impactful areas

The report includes detailed metrics, recommendations for investigation, and highlights both improvements and potential concerns that should be reviewed as part of PR #778.

@loci-dev
loci-dev force-pushed the main branch 2 times, most recently from ca06125 to 76fc6ba Compare January 2, 2026 00:37
@loci-dev
loci-dev force-pushed the upstream-PR18528-branch_nabbi-aggressive-loop-optimizations branch from b68e1d7 to cdd47ab Compare January 2, 2026 02:15
@loci-review

loci-review Bot commented Jan 2, 2026

Copy link
Copy Markdown

Explore the complete analysis inside the Version Insights

I've successfully retrieved the summary report for your project. The report shows a performance analysis comparing the base version to the new version for the llama.cpp repository (Pull Request #778).

Key Highlights:

⚠️ Performance Regressions Detected - The analysis reveals significant performance degradations across multiple functions:

  • STL Iterator Operations show the most severe regressions (44-68% increase in response time)
  • Graph Input Functions in llama-graph.cpp show moderate regressions (2.67-9.92%)
  • Logging Functions show a 16.60% performance decrease

The report recommends investigating these regressions, particularly the STL operations and graph input logic, and suggests considering a review of the changes before merging PR #778.

Would you like me to provide more detailed information about any specific function or aspect of this performance report?

@loci-dev
loci-dev force-pushed the main branch 21 times, most recently from bfd3c27 to 58eff53 Compare January 5, 2026 18:14
Normalize loop index types across batch, graph, and KV code paths to
match the width of their bounds (e.g. n_tokens, n_rs,
n_seq_id, n_expert_used).

This also removes an unreachable loop with identical start/end
conditions
GCC emited the following warning when building with optimizations:

  llama-graph.cpp:473:9: warning: iteration 2147483645 invokes undefined
  behavior [-Waggressive-loop-optimizations]

Signed-off-by: Nic Boet <nic@boet.cc>
@loci-dev
loci-dev force-pushed the upstream-PR18528-branch_nabbi-aggressive-loop-optimizations branch from cdd47ab to 4f310f4 Compare January 5, 2026 18:45
@loci-dev
loci-dev force-pushed the main branch 30 times, most recently from e48f18a to 82cdf69 Compare January 11, 2026 16:09
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.

2 participants