-
Notifications
You must be signed in to change notification settings - Fork 13.8k
model : add LLADA 2.0 diffusion support #17454
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
Draft
wsbagnsv1
wants to merge
49
commits into
ggml-org:master
Choose a base branch
from
wsbagnsv1:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+472
−53
Draft
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
ce46999
Implement LLaDA2MoeModel conversion in convert_hf_to_gguf.py
wsbagnsv1 9716bd4
Add LLADA2 architecture to constants
wsbagnsv1 a9e81a6
Implement LLaDA2.0 support to diffusion-cli.cpp
wsbagnsv1 bfc0b31
Add llada2.cpp to CMakeLists.txt
wsbagnsv1 85f5285
Add LLADA2 architecture support
wsbagnsv1 d5a4779
Add LLM_ARCH_LLADA2 to architecture list
wsbagnsv1 3db37fd
Add llada2.0 to llama-model.cpp
wsbagnsv1 b763f9b
Create llada2.cpp
wsbagnsv1 07180eb
Add llm_build_llada2 struct to models.h
wsbagnsv1 b9a938f
Merge branch 'ggml-org:master' into master
wsbagnsv1 d059973
Merge branch 'ggml-org:master' into master
wsbagnsv1 e071460
Add proper fall-through for llada2.0
wsbagnsv1 985ff29
Cleanup 1
wsbagnsv1 d383917
Cleanup 2
wsbagnsv1 0309fa2
Add EOS, Threshold and batch strategy
wsbagnsv1 885ae30
Add parameters to conversion script
wsbagnsv1 603c86b
Cleanup3
wsbagnsv1 2c2a930
Remove LLaDA2.0 specific code and make it model independent
wsbagnsv1 4e5abd2
small fix
wsbagnsv1 758c2f3
small fix part 2
wsbagnsv1 76e1642
small fix 1
wsbagnsv1 66610b7
Merge branch 'master' into master
wsbagnsv1 fa087c8
Enable hybrid diffusion
wsbagnsv1 e763d37
Add HYBRID_DIFFUSION constant to diffusion class
wsbagnsv1 e81ad4d
Remove LLM_ARCH_LLADA2 from architecture switch
wsbagnsv1 ebe9210
Implement hybrid diffusion optimization
wsbagnsv1 eace3fb
Make model use kv cache
wsbagnsv1 c488c41
Add Hybrid diffusion mechanism
wsbagnsv1 e84a77a
Clear white space
wsbagnsv1 77d833b
revert ubatch
wsbagnsv1 dcc5f1f
Change log level from INFO to DEBUG
wsbagnsv1 a48f4ea
Improve confidence handling
wsbagnsv1 876fa91
Refactor confidence calculation and transfer logic for clarity and ef…
wsbagnsv1 1c8e5c8
Implement EOS token assertion for early stop
wsbagnsv1 d20055f
Merge branch 'ggml-org:master' into master
wsbagnsv1 680812d
Update src/models/llada2.cpp
wsbagnsv1 8e37279
Update src/models/llada2.cpp
wsbagnsv1 0eaaac8
Update convert_hf_to_gguf.py
wsbagnsv1 80cb625
Update gguf-py/gguf/constants.py
wsbagnsv1 97dcb64
Update convert_hf_to_gguf.py
wsbagnsv1 baae37e
Update convert_hf_to_gguf.py
wsbagnsv1 d7f7d1c
Update src/llama-arch.cpp
wsbagnsv1 a8ba60b
Update gguf-py/gguf/constants.py
wsbagnsv1 679de2d
Refactor EOS and threshold parameters to use CLI
wsbagnsv1 11bd5a3
Add threshold and early stop flags to common.h
wsbagnsv1 8cf1588
Add diffusion options for threshold and early stopping
wsbagnsv1 191f1e0
Add options for hybrid diffusion
wsbagnsv1 de6416e
Add hybrid diffusion optimization flag
wsbagnsv1 6896bc3
Remove truncate_batch and simplify hybrid diffusion
wsbagnsv1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| #include "models.h" | ||
|
|
||
| llm_build_llada2::llm_build_llada2(const llama_model & model, const llm_graph_params & params) : | ||
| llm_graph_context(params) { | ||
| const int64_t n_embd_head = hparams.n_embd_head_v; | ||
| const int64_t n_embd_gqa = hparams.n_embd_v_gqa(); | ||
|
|
||
| GGML_ASSERT(n_embd_head == hparams.n_embd_head_k); | ||
|
|
||
| ggml_tensor * cur; | ||
| ggml_tensor * inpL; | ||
|
|
||
| inpL = build_inp_embd(model.tok_embd); | ||
|
|
||
| // inp_pos - contains the positions | ||
| ggml_tensor * inp_pos = build_inp_pos(); | ||
|
|
||
| auto * inp_attn = build_attn_inp_kv(); | ||
|
|
||
| ggml_tensor * inp_out_ids = build_inp_out_ids(); | ||
|
|
||
| for (int il = 0; il < n_layer; ++il) { | ||
| ggml_tensor * inpSA = inpL; | ||
|
|
||
| // norm | ||
| cur = build_norm(inpL, model.layers[il].attn_norm, NULL, LLM_NORM_RMS, il); | ||
| cb(cur, "attn_norm", il); | ||
|
|
||
| // self_attention | ||
| { | ||
| cur = build_lora_mm(model.layers[il].wqkv, cur); | ||
| cb(cur, "wqkv", il); | ||
|
|
||
| ggml_tensor * Qcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head, n_tokens, n_embd_head * sizeof(float), | ||
| cur->nb[1], 0 * sizeof(float) * (n_embd)); | ||
| ggml_tensor * Kcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head_kv, n_tokens, n_embd_head * sizeof(float), | ||
| cur->nb[1], 1 * sizeof(float) * (n_embd)); | ||
| ggml_tensor * Vcur = ggml_view_3d(ctx0, cur, n_embd_head, n_head_kv, n_tokens, n_embd_head * sizeof(float), | ||
| cur->nb[1], 1 * sizeof(float) * (n_embd + n_embd_gqa)); | ||
|
|
||
| Qcur = build_norm(Qcur, model.layers[il].attn_q_norm, NULL, LLM_NORM_RMS, il); | ||
| cb(Qcur, "Qcur_normed", il); | ||
|
|
||
| Qcur = ggml_rope_ext(ctx0, Qcur, inp_pos, nullptr, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale, | ||
| ext_factor, attn_factor, beta_fast, beta_slow); | ||
|
|
||
| Kcur = build_norm(Kcur, model.layers[il].attn_k_norm, NULL, LLM_NORM_RMS, il); | ||
| cb(Kcur, "Kcur_normed", il); | ||
|
|
||
| Kcur = ggml_rope_ext(ctx0, Kcur, inp_pos, nullptr, n_rot, rope_type, n_ctx_orig, freq_base, freq_scale, | ||
| ext_factor, attn_factor, beta_fast, beta_slow); | ||
|
|
||
| cb(Qcur, "Qcur", il); | ||
| cb(Kcur, "Kcur", il); | ||
| cb(Vcur, "Vcur", il); | ||
|
|
||
| cur = build_attn(inp_attn, | ||
| model.layers[il].wo, model.layers[il].bo, | ||
| Qcur, Kcur, Vcur, nullptr, nullptr, nullptr, 1.0f / sqrtf(float(n_embd_head)), il); | ||
| } | ||
|
|
||
| if (il == n_layer - 1 && inp_out_ids) { | ||
| cur = ggml_get_rows(ctx0, cur, inp_out_ids); | ||
| inpSA = ggml_get_rows(ctx0, inpSA, inp_out_ids); | ||
| } | ||
|
|
||
| ggml_tensor * sa_out = ggml_add(ctx0, cur, inpSA); | ||
| cb(sa_out, "sa_out", il); | ||
|
|
||
| // MoE branch | ||
| cur = build_norm(sa_out, model.layers[il].ffn_norm, NULL, LLM_NORM_RMS, il); | ||
| cb(cur, "ffn_norm", il); | ||
|
|
||
| if (static_cast<uint32_t>(il) < hparams.n_layer_dense_lead) { | ||
| cur = build_ffn(cur, | ||
| model.layers[il].ffn_up, NULL, NULL, | ||
| model.layers[il].ffn_gate, NULL, NULL, | ||
| model.layers[il].ffn_down, NULL, NULL, | ||
| NULL, LLM_FFN_SILU, LLM_FFN_PAR, il); | ||
| cb(cur, "ffn_out", il); | ||
| } else { | ||
| ggml_tensor * moe_out = build_moe_ffn(cur, | ||
| model.layers[il].ffn_gate_inp, | ||
| model.layers[il].ffn_up_exps, | ||
| model.layers[il].ffn_gate_exps, | ||
| model.layers[il].ffn_down_exps, | ||
| model.layers[il].ffn_exp_probs_b, | ||
| n_expert, n_expert_used, | ||
| LLM_FFN_SILU, hparams.expert_weights_norm, | ||
| true, hparams.expert_weights_scale, | ||
| (llama_expert_gating_func_type) hparams.expert_gating_func, | ||
| il); | ||
| cb(moe_out, "ffn_moe_out", il); | ||
|
|
||
| { | ||
| ggml_tensor * ffn_shexp = | ||
| build_ffn(cur, | ||
| model.layers[il].ffn_up_shexp, NULL, NULL, | ||
| model.layers[il].ffn_gate_shexp, NULL, NULL, | ||
| model.layers[il].ffn_down_shexp, NULL, NULL, | ||
| NULL, LLM_FFN_SILU, LLM_FFN_PAR, il); | ||
| cb(ffn_shexp, "ffn_shexp", il); | ||
|
|
||
| cur = ggml_add(ctx0, moe_out, ffn_shexp); | ||
| cb(cur, "ffn_out", il); | ||
| } | ||
| } | ||
|
|
||
| cur = ggml_add(ctx0, cur, sa_out); | ||
|
|
||
| cur = build_cvec(cur, il); | ||
| cb(cur, "l_out", il); | ||
|
|
||
| // input for next layer | ||
| inpL = cur; | ||
| } | ||
|
|
||
| cur = inpL; | ||
|
|
||
| cur = build_norm(cur, model.output_norm, NULL, LLM_NORM_RMS, -1); | ||
|
|
||
| cb(cur, "result_norm", -1); | ||
| res->t_embd = cur; | ||
|
|
||
| // lm_head | ||
| cur = build_lora_mm(model.output, cur); | ||
|
|
||
| cb(cur, "result_output", -1); | ||
| res->t_logits = cur; | ||
|
|
||
| ggml_build_forward_expand(gf, cur); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Uh oh!
There was an error while loading. Please reload this page.