feat: add Dream-7B model support (Qwen2.5 backbone, GQA)

- New converter: tools/convert-dream.py (Qwen2.5 tensor mapping)
- Multi-model loader: reads diffuse.model_type from GGUF metadata
- GQA support verified (28 query heads, 4 KV heads)
- New remasking strategies: maskgit_plus, topk_margin (from Dream paper)
- Updated CLI, benchmark, and generate.py with new remasking options
- README: supported models table, Dream conversion example
- Zero breaking changes for existing LLaDA GGUF files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
iafiscal1212andClaude Opus 4.6 committed 2026-03-22 13:03:30 +01:00
1 parent 9b76ba9bc3
commit 3f6aa5597a
9 files changed
+376 -18

No files matched your search

+1
View File
@@ -46,6 +46,7 @@ struct diffuse_layer {
// ── Full model struct ──────────────────────────────────────────
struct diffuse_model {
diffuse_hparams hparams;
std::string model_type; // "llada", "dream", etc. (from GGUF metadata)
// Embeddings
struct ggml_tensor * tok_embd; // token embeddings
+19 -4
View File
@@ -58,10 +58,25 @@ diffuse_model * diffuse_model_load_impl(const std::string & path, int n_threads)
hp.rope_theta = get_f32(gctx, "diffuse.rope.freq_base", 500000.0f);
hp.rms_norm_eps = get_f32(gctx, "diffuse.attention.layer_norm_rms_epsilon", 1e-5f);
DIFFUSE_LOG(" arch: LLaDA (Llama backbone)");
DIFFUSE_LOG(" n_vocab=%u, n_embd=%u, n_head=%u, n_layer=%u, n_ff=%u",
hp.n_vocab, hp.n_embd, hp.n_head, hp.n_layer, hp.n_ff);
DIFFUSE_LOG(" mask_token_id=%u, rope_theta=%.0f", hp.mask_token_id, hp.rope_theta);
// Read model type (llada, dream, etc.)
{
int64_t id = gguf_find_key(gctx, "diffuse.model_type");
if (id >= 0) {
model->model_type = gguf_get_val_str(gctx, id);
} else {
model->model_type = "llada"; // default for older GGUF files
}
}
const char * arch_name = "unknown";
if (model->model_type == "llada") arch_name = "LLaDA (Llama backbone)";
else if (model->model_type == "dream") arch_name = "Dream (Qwen2.5 backbone, GQA)";
DIFFUSE_LOG(" arch: %s", arch_name);
DIFFUSE_LOG(" n_vocab=%u, n_embd=%u, n_head=%u/%u(kv), n_layer=%u, n_ff=%u",
hp.n_vocab, hp.n_embd, hp.n_head, hp.n_head_kv, hp.n_layer, hp.n_ff);
DIFFUSE_LOG(" mask_token_id=%u, rope_theta=%.0f, rms_norm_eps=%.1e",
hp.mask_token_id, hp.rope_theta, hp.rms_norm_eps);
// The weight context is the one that gguf_init populated
model->ctx = meta_ctx;
+24 -5
View File
@@ -98,11 +98,15 @@ std::vector<int32_t> diffuse_sample(
const int cache_refresh = params.cache_refresh;
const int cache_keep_active = params.cache_keep_active;
const char * remasking_name =
params.remasking == diffuse_remasking::ENTROPY_EXIT ? "entropy_exit" :
params.remasking == diffuse_remasking::LOW_CONFIDENCE ? "low_confidence" :
params.remasking == diffuse_remasking::MASKGIT_PLUS ? "maskgit_plus" :
params.remasking == diffuse_remasking::TOPK_MARGIN ? "topk_margin" :
"random";
DIFFUSE_LOG("diffusion: %d steps, %d tokens to generate, scheduler=%s, cache=%s, refresh=%d, keep_active=%d",
params.n_steps, n_generate,
params.remasking == diffuse_remasking::ENTROPY_EXIT ? "entropy_exit" :
params.remasking == diffuse_remasking::LOW_CONFIDENCE ? "low_confidence" :
"random",
remasking_name,
use_cache ? "ON" : "OFF",
cache_refresh, cache_keep_active);
@@ -226,15 +230,22 @@ std::vector<int32_t> diffuse_sample(
float ent = compute_entropy(logit_row, n_vocab);
if (params.temperature <= 0.0f) {
// Find top-1 (and top-2 for TOPK_MARGIN)
int best = 0;
float best_val = logit_row[0];
float second_val = -1e30f;
for (int v = 1; v < n_vocab; v++) {
if (logit_row[v] > best_val) {
second_val = best_val;
best_val = logit_row[v];
best = v;
} else if (logit_row[v] > second_val) {
second_val = logit_row[v];
}
}
candidates.push_back({i, best, best_val, ent});
float conf = (params.remasking == diffuse_remasking::TOPK_MARGIN)
? (best_val - second_val) : best_val;
candidates.push_back({i, best, conf, ent});
} else {
float max_logit = *std::max_element(logit_row, logit_row + n_vocab);
std::vector<float> probs(n_vocab);
@@ -272,11 +283,19 @@ std::vector<int32_t> diffuse_sample(
n_unmask = std::max(n_unmask, n_easy);
n_unmask = std::min(n_unmask, (int)candidates.size());
} else if (params.remasking == diffuse_remasking::LOW_CONFIDENCE) {
} else if (params.remasking == diffuse_remasking::LOW_CONFIDENCE ||
params.remasking == diffuse_remasking::MASKGIT_PLUS) {
// Both sort by highest confidence (top-1 logit value)
std::sort(candidates.begin(), candidates.end(),
[](const candidate & a, const candidate & b) {
return a.confidence > b.confidence;
});
} else if (params.remasking == diffuse_remasking::TOPK_MARGIN) {
// Sort by margin between top-1 and top-2 logits (highest margin first)
std::sort(candidates.begin(), candidates.end(),
[](const candidate & a, const candidate & b) {
return a.confidence > b.confidence; // margin stored in confidence field
});
} else {
std::shuffle(candidates.begin(), candidates.end(), rng);
}