Skip to content

Commit 1439fbe

Browse files
committed
Make everything in a single example
1 parent c0971b6 commit 1439fbe

File tree

7 files changed

+936
-1092
lines changed

7 files changed

+936
-1092
lines changed

common/arg.cpp

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,59 +3438,50 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
34383438
}
34393439
).set_examples({LLAMA_EXAMPLE_SERVER}));
34403440

3441-
// shared diffusion parameters
34423441
add_opt(common_arg(
34433442
{ "--diffusion-steps" }, "N",
3444-
string_format("number of diffusion steps (default: %d)", params.diffusion_dream.steps),
3445-
[](common_params & params, int value) {
3446-
params.diffusion_dream.steps = value;
3447-
params.diffusion_llada.steps = value;
3448-
}
3449-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_DREAM, LLAMA_EXAMPLE_DIFFUSION_LLADA }));
3443+
string_format("number of diffusion steps (default: %d)", params.diffusion.steps),
3444+
[](common_params & params, int value) { params.diffusion.steps = value; }
3445+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
34503446
add_opt(common_arg(
34513447
{ "--diffusion-visual" },
34523448
string_format("enable visual diffusion mode (show progressive generation) (default: %s)",
3453-
params.diffusion_dream.visual_mode ? "true" : "false"),
3454-
[](common_params & params) {
3455-
params.diffusion_dream.visual_mode = true;
3456-
params.diffusion_llada.visual_mode = true;
3457-
}
3458-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_DREAM, LLAMA_EXAMPLE_DIFFUSION_LLADA }));
3449+
params.diffusion.visual_mode ? "true" : "false"),
3450+
[](common_params & params) { params.diffusion.visual_mode = true; }
3451+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
34593452

3460-
// DREAM-specific diffusion parameters
34613453
add_opt(common_arg(
3462-
{ "--diffusion-eps" }, "F",
3463-
string_format("epsilon for timesteps (default: %.6f)", (double) params.diffusion_dream.eps),
3464-
[](common_params & params, const std::string & value) { params.diffusion_dream.eps = std::stof(value); }
3465-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_DREAM }));
3454+
{ "--diffusion--dream-eps" }, "F",
3455+
string_format("epsilon for timesteps (default: %.6f)", (double) params.diffusion.eps),
3456+
[](common_params & params, const std::string & value) { params.diffusion.eps = std::stof(value); }
3457+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
34663458
add_opt(common_arg(
3467-
{ "--diffusion-algorithm" }, "N",
3459+
{ "--diffusion-dream-algorithm" }, "N",
34683460
string_format("diffusion algorithm: 0=ORIGIN, 1=MASKGIT_PLUS, 2=TOPK_MARGIN, 3=ENTROPY (default: %d)",
3469-
params.diffusion_dream.algorithm),
3470-
[](common_params & params, int value) { params.diffusion_dream.algorithm = value; }
3471-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_DREAM }));
3472-
add_opt(common_arg(
3473-
{ "--diffusion-alg-temp" }, "F",
3474-
string_format("algorithm temperature (default: %.3f)", (double) params.diffusion_dream.alg_temp),
3475-
[](common_params & params, const std::string & value) { params.diffusion_dream.alg_temp = std::stof(value); }
3476-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_DREAM }));
3477-
3478-
// LLADA-specific diffusion parameters
3479-
add_opt(common_arg(
3480-
{ "--diffusion-block-length" }, "N",
3481-
string_format("block length for generation (default: %d)", params.diffusion_llada.block_length),
3482-
[](common_params & params, int value) { params.diffusion_llada.block_length = value; }
3483-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_LLADA }));
3484-
add_opt(common_arg(
3485-
{ "--diffusion-cfg-scale" }, "F",
3486-
string_format("classifier-free guidance scale (default: %.3f)", (double) params.diffusion_llada.cfg_scale),
3487-
[](common_params & params, const std::string & value) { params.diffusion_llada.cfg_scale = std::stof(value); }
3488-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_LLADA }));
3489-
add_opt(common_arg(
3490-
{ "--diffusion-algorithm" }, "N",
3491-
string_format("remasking algorithm: 0=LOW_CONFIDENCE, 1=RANDOM (default: %d)", params.diffusion_llada.remasking),
3492-
[](common_params & params, int value) { params.diffusion_llada.remasking = value; }
3493-
).set_examples({ LLAMA_EXAMPLE_DIFFUSION_LLADA }));
3461+
params.diffusion.algorithm),
3462+
[](common_params & params, int value) { params.diffusion.algorithm = value; }
3463+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
3464+
add_opt(common_arg(
3465+
{ "--diffusion-dream-alg-temp" }, "F",
3466+
string_format("dream algorithm temperature (default: %.3f)", (double) params.diffusion.alg_temp),
3467+
[](common_params & params, const std::string & value) { params.diffusion.alg_temp = std::stof(value); }
3468+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
3469+
3470+
add_opt(common_arg(
3471+
{ "--diffusion-llada-block-length" }, "N",
3472+
string_format("llada block length for generation (default: %d)", params.diffusion.block_length),
3473+
[](common_params & params, int value) { params.diffusion.block_length = value; }
3474+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
3475+
add_opt(common_arg(
3476+
{ "--diffusion-llada-cfg-scale" }, "F",
3477+
string_format("llada classifier-free guidance scale (default: %.3f)", (double) params.diffusion.cfg_scale),
3478+
[](common_params & params, const std::string & value) { params.diffusion.cfg_scale = std::stof(value); }
3479+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
3480+
add_opt(common_arg(
3481+
{ "--diffusion-llada-algorithm" }, "N",
3482+
string_format("llada remasking algorithm: 0=LOW_CONFIDENCE, 1=RANDOM (default: %d)", params.diffusion.remasking),
3483+
[](common_params & params, int value) { params.diffusion.remasking = value; }
3484+
).set_examples({ LLAMA_EXAMPLE_DIFFUSION }));
34943485

34953486
return ctx_arg;
34963487
}

common/common.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ enum llama_example {
8181
LLAMA_EXAMPLE_LOOKUP,
8282
LLAMA_EXAMPLE_PARALLEL,
8383
LLAMA_EXAMPLE_TTS,
84-
LLAMA_EXAMPLE_DIFFUSION_DREAM,
85-
LLAMA_EXAMPLE_DIFFUSION_LLADA,
84+
LLAMA_EXAMPLE_DIFFUSION,
8685

8786
LLAMA_EXAMPLE_COUNT,
8887
};
@@ -220,20 +219,20 @@ struct common_params_vocoder {
220219
bool use_guide_tokens = false; // enable guide tokens to improve TTS accuracy // NOLINT
221220
};
222221

223-
struct common_params_diffusion_dream {
224-
int32_t steps = 64; // number of diffusion steps
225-
float eps = 1e-3f; // epsilon for timesteps
226-
int32_t algorithm = 0; // diffusion algorithm (0=ORIGIN, 1=MASKGIT_PLUS, 2=TOPK_MARGIN, 3=ENTROPY)
227-
float alg_temp = 0.0f; // algorithm temperature
228-
bool visual_mode = false; // show progressive diffusion on screen
229-
};
222+
struct common_params_diffusion {
223+
// Common parameters
224+
int32_t steps = 128; // number of diffusion steps
225+
bool visual_mode = false; // show progressive diffusion on screen
230226

231-
struct common_params_diffusion_llada {
232-
int32_t steps = 64; // number of diffusion steps
227+
// Dream-specific parameters
228+
float eps = 1e-3f; // epsilon for timesteps
229+
int32_t algorithm = 3; // diffusion algorithm (0=ORIGIN, 1=MASKGIT_PLUS, 2=TOPK_MARGIN, 3=ENTROPY)
230+
float alg_temp = 0.0f; // algorithm temperature
231+
232+
// LLaDA-specific parameters
233233
int32_t block_length = 32; // block length for generation
234234
float cfg_scale = 0.2f; // classifier-free guidance scale
235-
int32_t remasking = 0; // remasking algorithm: 0=LOW_CONFIDENCE, 1=RANDOM
236-
bool visual_mode = false; // show progressive diffusion on screen
235+
int32_t remasking = 1; // remasking algorithm: 0=LOW_CONFIDENCE, 1=RANDOM
237236
};
238237

239238
enum common_reasoning_format {
@@ -287,8 +286,7 @@ struct common_params {
287286
struct common_params_sampling sampling;
288287
struct common_params_speculative speculative;
289288
struct common_params_vocoder vocoder;
290-
struct common_params_diffusion_dream diffusion_dream;
291-
struct common_params_diffusion_llada diffusion_llada;
289+
struct common_params_diffusion diffusion;
292290

293291
struct common_params_model model;
294292

examples/diffusion/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
set(TARGET llama-diffusion-dream-cli)
2-
add_executable(${TARGET} diffusion-dream-cli.cpp)
3-
install(TARGETS ${TARGET} RUNTIME)
4-
target_link_libraries(${TARGET} PRIVATE llama common ${CMAKE_THREAD_LIBS_INIT})
5-
target_compile_features(${TARGET} PRIVATE cxx_std_17)
6-
7-
set(TARGET llama-diffusion-llada-cli)
8-
add_executable(${TARGET} diffusion-llada-cli.cpp)
1+
set(TARGET llama-diffusion-cli)
2+
add_executable(${TARGET} diffusion-cli.cpp)
93
install(TARGETS ${TARGET} RUNTIME)
104
target_link_libraries(${TARGET} PRIVATE llama common ${CMAKE_THREAD_LIBS_INIT})
115
target_compile_features(${TARGET} PRIVATE cxx_std_17)

examples/diffusion/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22

33
This directory contains implementations for diffusion-based text generation using two different model architectures: **Dream** and **LLaDA-8B**. Both models use iterative denoising processes to generate text, but employ different sampling strategies and algorithms.
44

5-
## Supported Models
5+
## Supported Architechtures
66

7-
### 1. Dream Model (`llama-diffusion-dream-cli`)
7+
### 1. Dream
88

9+
Example models:
910
- https://huggingface.co/Dream-org/Dream-v0-Base-7B
10-
- Original PR - https://github.com/ggml-org/llama.cpp/pull/14644
11+
- PR - https://github.com/ggml-org/llama.cpp/pull/14644
1112

12-
The Dream model supports four different sampling algorithms controlled by the `--diffusion-algorithm` parameter:
13+
The Dream model supports four different sampling algorithms controlled by the `--diffusion-dream-algorithm` parameter:
1314

1415
1. **ORIGIN (0)** - Original diffusion algorithm
1516
- Uses probability transfer based on timestep ratios
16-
- Default algorithm with standard confidence-based token selection
1717

1818
2. **MASKGIT_PLUS (1)** - Enhanced MaskGIT sampling
1919
- Improved version of the MaskGIT algorithm
2020

2121
3. **TOPK_MARGIN (2)** - Top-K margin-based sampling
2222
- Confidence calculated as the margin between top-1 and top-2 probabilities
2323

24-
4. **ENTROPY (3)** - Entropy-based sampling (recommended)
24+
4. **ENTROPY (3)** - Entropy-based sampling (default, recommended)
2525
- Uses entropy calculation for confidence estimation
2626

27-
### 2. LLaDA-8B Model (`llama-diffusion-llada-cli`)
27+
### 2. LLaDA
2828

29+
Example models:
2930
- https://huggingface.co/GSAI-ML/LLaDA-8B-Instruct
31+
- PR: https://github.com/ggml-org/llama.cpp/pull/14771
3032

3133
### LLaDA Model Remasking Strategies
3234

33-
The LLaDA model uses two remasking approaches controlled by the `--diffusion-algorithm` parameter:
35+
The LLaDA model uses two remasking approaches controlled by the `--diffusion-llada-algorithm` parameter:
3436

3537
1. **REMASKING_LOW_CONFIDENCE (0)** - Default strategy
3638
- Remasks tokens with lowest confidence scores

0 commit comments

Comments
 (0)