llama : fix build_ffn without gate #13336
Merged
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.
While porting these
build_*
function toclip.cpp
, I came across the case of FFN not having gate (which is quite common in vision transformers)The current logic in
llm_graph_context::build_ffn
kinda assumes that gate always exist (which make sense, since most - if not all - modern LLM have up/gate/down FFN). If the gate is missing, this causes the logic to calculatecur = up_state * up_state
which results in an incorrect result.I'm not sure if the code is intended to be written this way, but I think we should either:
gate
to the check as proposed in this PRGGML_ASSERT(gate)
to make sure the gate is always therePlease note that when porting to ViT, I only copy the case of
LLM_FFN_PAR
and notLLM_FFN_SEQ