Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

dFactory is an extensible training framework for discrete diffusion language
models. It provides SFT, autoregressive SFT, multi-stage fine-tuning, and
continued-pretraining recipes for the LLaDA2 family, with PyTorch FSDP2 and
VeOmni providing the distributed runtime.
continued-pretraining recipes for the LLaDA2 family, plus SolDiff pretraining
for Qwen3, with PyTorch FSDP2 and VeOmni providing the distributed runtime.

dFactory owns its model, data, recipe, checkpoint, and configuration semantics.
VeOmni is an installed dependency, not a source submodule and not part of the
Expand Down Expand Up @@ -123,6 +123,8 @@ The same launcher directly supports every checked-in training profile:
| EMTF random-T2T | `configs/recipes/emtf_random_t2t/llada2_mini.yaml` |
| AR2BD continued pretraining | `configs/recipes/ar2bd/llada2_mini.yaml` |
| ESTF continued pretraining | `configs/recipes/estf/llada2_mini.yaml` |
| [SolDiff](docs/source/algo/soldiff.rst) 1.7B continued pretraining | `configs/recipes/soldiff/qwen3_1.7b.yaml` |
| [SolDiff](docs/source/algo/soldiff.rst) 8B continued pretraining | `configs/recipes/soldiff/qwen3_8b.yaml` |

To resume, use the same command with
`--set checkpoint.resume_from=/path/to/checkpoints/global_step_N`.
Expand Down
30 changes: 30 additions & 0 deletions configs/model_configs/qwen3_1.7b/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"architectures": [
"Qwen3ForBDLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151643,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 2048,
"initializer_range": 0.02,
"intermediate_size": 6144,
"max_position_embeddings": 32768,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 28,
"num_key_value_heads": 8,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": true,
"torch_dtype": "bfloat16",
"transformers_version": "4.51.0",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}
30 changes: 30 additions & 0 deletions configs/model_configs/qwen3_8b/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"architectures": [
"Qwen3ForBDLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151643,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 12288,
"max_position_embeddings": 32768,
"max_window_layers": 36,
"model_type": "qwen3",
"num_attention_heads": 32,
"num_hidden_layers": 36,
"num_key_value_heads": 8,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.51.0",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936
}
8 changes: 8 additions & 0 deletions configs/p_head_configs/qwen3_1.7b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"activation": "silu",
"head_type": "rmsnorm_gated_mlp",
"hidden_size": 2048,
"initializer_std": 0.02,
"intermediate_size": 1024,
"rms_eps": 1e-06
}
8 changes: 8 additions & 0 deletions configs/p_head_configs/qwen3_8b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"activation": "silu",
"head_type": "rmsnorm_gated_mlp",
"hidden_size": 4096,
"initializer_std": 0.02,
"intermediate_size": 2048,
"rms_eps": 1e-06
}
58 changes: 58 additions & 0 deletions configs/q_configs/qwen3_1.7b_soldiff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"format": "mask_generator_q_linear.init.v1",
"architectures": [
"MaskGeneratorQLinearForOrdering"
],
"model_type": "mask_generator_q_linear",
"base_model_type": "qwen3",
"base_architectures": [
"Qwen3ForBDLM"
],
"base_config": {
"architectures": [
"Qwen3ForBDLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151643,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 2048,
"initializer_range": 0.02,
"intermediate_size": 6144,
"max_position_embeddings": 32768,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 14,
"num_key_value_heads": 8,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": true,
"torch_dtype": "bfloat16",
"transformers_version": "4.51.0",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936,
"pad_token_id": null
},
"encoder_num_layers": 14,
"hidden_size": 2048,
"q_head_type": "linear",
"q_score_bias": false,
"rms_eps": 1e-06,
"attention_block_size": 32,
"attention_mask_type": "doc_causal_block",
"attn_implementation": "flex_attention",
"eos_token_id": 151645,
"eos_token_id_source": "tokenizer.eos_token_id",
"tokenizer_eos_token": "<|im_end|>",
"contains_lm_head": false,
"tie_word_embeddings": false,
"frozen_encoder": false,
"trainable_encoder": true,
"self_contained_package": true
}
58 changes: 58 additions & 0 deletions configs/q_configs/qwen3_8b_soldiff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"format": "mask_generator_q_linear.init.v1",
"architectures": [
"MaskGeneratorQLinearForOrdering"
],
"model_type": "mask_generator_q_linear",
"base_model_type": "qwen3",
"base_architectures": [
"Qwen3ForBDLM"
],
"base_config": {
"architectures": [
"Qwen3ForBDLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"bos_token_id": 151643,
"eos_token_id": 151643,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 4096,
"initializer_range": 0.02,
"intermediate_size": 12288,
"max_position_embeddings": 32768,
"max_window_layers": 36,
"model_type": "qwen3",
"num_attention_heads": 32,
"num_hidden_layers": 12,
"num_key_value_heads": 8,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": false,
"torch_dtype": "bfloat16",
"transformers_version": "4.51.0",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 151936,
"pad_token_id": null
},
"encoder_num_layers": 12,
"hidden_size": 4096,
"q_head_type": "linear",
"q_score_bias": false,
"rms_eps": 1e-06,
"attention_block_size": 32,
"attention_mask_type": "doc_causal_block",
"attn_implementation": "flex_attention",
"eos_token_id": 151645,
"eos_token_id_source": "tokenizer.eos_token_id",
"tokenizer_eos_token": "<|im_end|>",
"contains_lm_head": false,
"tie_word_embeddings": false,
"frozen_encoder": false,
"trainable_encoder": true,
"self_contained_package": true
}
72 changes: 72 additions & 0 deletions configs/recipes/soldiff/qwen3_1.7b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Set model/data paths and choose the step budget for the intended training run.
run:
output_dir: outputs/qwen3-1.7b-soldiff
seed: 42
max_steps: 1000
num_train_epochs: 1

recipe:
name: soldiff
params:
block_size: 32
q_config_path: configs/q_configs/qwen3_1.7b_soldiff.json
p_head_config_path: configs/p_head_configs/qwen3_1.7b.json
loss_backward_divisor: 4096.0
suffix_reconstruction_tau: 8.0
lambda_align: 1.0
lambda_recon: 1.0
diagnostics_every_steps: 100

model:
provider: qwen3
config_path: configs/model_configs/qwen3_1.7b
weights_path: /path/to/main-model
tokenizer_path: configs/tokenizer/qwen3_tokenizer
attention: flex_attention
moe: eager
init_device: meta
mask_token_id: 151669
# Document boundaries use the tokenizer EOS, which differs from the native model config.
eos_token_id: 151645
pad_token_id: 151643

data:
source: jsonl
path: /path/to/token-documents.jsonl
format: token_records
text_key: input_ids
max_seq_len: 4096
packing: false
num_workers: 16

distributed:
mode: fsdp2
dp: 8
dp_replicate: 1
ep: 1
activation_offload: false
gradient_checkpointing: true

optimization:
optimizer: adamw
lr: 2.0e-5
beta1: 0.9
beta2: 0.95
weight_decay: 0.1
scheduler: constant
warmup_ratio: 0.0
decay_ratio: 1.0
min_lr: 2.0e-5
global_batch_size: 1024
micro_batch_size: 4
max_grad_norm: 0.1

checkpoint:
resume_from: null
save_every_steps: 1000
save_every_epochs: 1
save_hf_weights: false

logging:
report_to: [stdout]
log_every_steps: 1
72 changes: 72 additions & 0 deletions configs/recipes/soldiff/qwen3_8b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Set model/data paths and choose the step budget for the intended training run.
run:
output_dir: outputs/qwen3-8b-soldiff
seed: 42
max_steps: 1000
num_train_epochs: 1

recipe:
name: soldiff
params:
block_size: 32
q_config_path: configs/q_configs/qwen3_8b_soldiff.json
p_head_config_path: configs/p_head_configs/qwen3_8b.json
loss_backward_divisor: 4096.0
suffix_reconstruction_tau: 8.0
lambda_align: 1.0
lambda_recon: 1.0
diagnostics_every_steps: 100

model:
provider: qwen3
config_path: configs/model_configs/qwen3_8b
weights_path: /path/to/main-model
tokenizer_path: configs/tokenizer/qwen3_tokenizer
attention: flex_attention
moe: eager
init_device: meta
mask_token_id: 151669
# Document boundaries use the tokenizer EOS, which differs from the native model config.
eos_token_id: 151645
pad_token_id: 151643

data:
source: jsonl
path: /path/to/token-documents.jsonl
format: token_records
text_key: input_ids
max_seq_len: 4096
packing: false
num_workers: 16

distributed:
mode: fsdp2
dp: 8
dp_replicate: 1
ep: 1
activation_offload: false
gradient_checkpointing: true

optimization:
optimizer: adamw
lr: 2.0e-5
beta1: 0.9
beta2: 0.95
weight_decay: 0.1
scheduler: constant
warmup_ratio: 0.0
decay_ratio: 1.0
min_lr: 2.0e-5
global_batch_size: 1024
micro_batch_size: 4
max_grad_norm: 0.1

checkpoint:
resume_from: null
save_every_steps: 1000
save_every_epochs: 1
save_hf_weights: false

logging:
report_to: [stdout]
log_every_steps: 1
29 changes: 29 additions & 0 deletions configs/tokenizer/qwen3_tokenizer/added_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"</think>": 151668,
"</tool_call>": 151658,
"</tool_response>": 151666,
"<MASK>": 151669,
"<think>": 151667,
"<tool_call>": 151657,
"<tool_response>": 151665,
"<|box_end|>": 151649,
"<|box_start|>": 151648,
"<|endoftext|>": 151643,
"<|file_sep|>": 151664,
"<|fim_middle|>": 151660,
"<|fim_pad|>": 151662,
"<|fim_prefix|>": 151659,
"<|fim_suffix|>": 151661,
"<|im_end|>": 151645,
"<|im_start|>": 151644,
"<|image_pad|>": 151655,
"<|object_ref_end|>": 151647,
"<|object_ref_start|>": 151646,
"<|quad_end|>": 151651,
"<|quad_start|>": 151650,
"<|repo_name|>": 151663,
"<|video_pad|>": 151656,
"<|vision_end|>": 151653,
"<|vision_pad|>": 151654,
"<|vision_start|>": 151652
}
Loading