File size: 5,895 Bytes
31dc8dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Configuration Design Guide
**************************

YAML Configuration Structure
============================

Configuration files use hierarchical YAML structure with three main sections:

.. code-block:: yaml

   model:
     # Model-specific settings
   data:
     # Data loading and preprocessing
   train:
     # Training hyperparameters and setup

Model Configuration
===================

Model Section
-------------

**Required fields:**

.. code-block:: yaml

   model:
     config_path: "./configs/model_configs/[model_name]"
     model_path: "./path/to/model"
     tokenizer_path: "./path/to/tokenizer"
     attn_implementation: "sdpa"        # sdpa|eager|flex_attention
     moe_implementation: "fused"        # fused|standard

.. warning::

   **Flash Attention Limitation**: The flash attention backend can only be used with ``full_attention`` or ``causal_attention`` modes. It **cannot** adapt to custom attention types used in LLaDA2.0 models. **Do not use FlashAttention (flash_attn2/flash_attn) for Block Diffusion Mode models**. See :doc:`/algo/block_diffusion` for detailed explanation of block diffusion training.

Data Configuration
==================

Data Section
------------

**Template for conversation data:**

.. code-block:: yaml

   data:
     train_path: "./datasets/train.jsonl"
     data_type: "conversation"          # conversation|plain|instruction
     datasets_type: "mapping"           # mapping|streaming
     dataloader_type: "native"          # native|custom
     max_seq_len: 2048
     text_keys: "messages"              # field name in JSON
     noise_range_low: 0.3               # diffusion noise lower bound
     noise_range_high: 0.8              # diffusion noise upper bound
     num_workers: 16

- Support multiple data formats (JSONL, Parquet)
- Configurable noise ranges for diffusion training
- Flexible text field mapping
- Worker count based on CPU cores

Training Configuration
======================

Training Section
----------------

**Distributed training setup:**

.. code-block:: yaml

   train:
     output_dir: "./outputs/experiment_name"
     
     # Parallel configuration
     data_parallel_mode: "fsdp2"        # fsdp2
     tensor_parallel_size: 1            # model parallel
     ulysses_parallel_size: 1           # sequence parallel
     expert_parallel_size: 1            # MoE parallel
     
     # Batch configuration
     global_batch_size: 16              # total batch across all GPUs
     micro_batch_size: 1                # batch per GPU
     
     # Training schedule
     num_train_epochs: 1
     save_epochs: 1                     # checkpoint frequency
     log_steps: 1                       # logging frequency

**Optimization parameters:**

.. code-block:: yaml

   train:
     optimizer: "adamw"
     beta1: 0.9
     beta2: 0.999
     lr: 1.0e-5                        # learning rate
     lr_warmup_ratio: 0.03             # warmup steps ratio
     lr_decay_style: "cosine"          # cosine|linear|constant
     weight_decay: 0.1
     max_grad_norm: 1.0

**Memory optimization:**

.. code-block:: yaml

   train:
     enable_mixed_precision: true
     enable_gradient_checkpointing: true
     enable_full_shard: true           # FSDP parameter sharding
     enable_fsdp_offload: true         # CPU offloading
     empty_cache_steps: 500            # GPU memory cleanup

Configuration Patterns
======================

Model Scaling
-------------

**Small model template:**

.. code-block:: yaml

   train:
     global_batch_size: 8               # Reduce for smaller models
     micro_batch_size: 1

**Large model template:**

.. code-block:: yaml

   train:
     global_batch_size: 64              # Increase for larger models
     micro_batch_size: 1
     tensor_parallel_size: 2            # Enable model parallelism
     expert_parallel_size: 2            # Distribute experts

Dataset Adaptation
------------------

**For large datasets:**

.. code-block:: yaml

   data:
     datasets_type: "streaming"        # Memory-efficient loading
     num_workers: 32                   # Increase workers

**For small datasets:**

.. code-block:: yaml

   data:
     datasets_type: "mapping"          # Full dataset in memory
     num_workers: 8                    # Reduce overhead

Hardware Adaptation
===================

Single GPU Setup
----------------

.. code-block:: yaml

   train:
     data_parallel_mode: "fsdp2"
     tensor_parallel_size: 1
     expert_parallel_size: 1
     global_batch_size: 4            # Fit single GPU
     micro_batch_size: 1
     enable_fsdp_offload: false      # Disable offloading

Multi-GPU Setup
---------------

.. code-block:: yaml

   train:
     data_parallel_mode: "fsdp2"
     tensor_parallel_size: 1
     expert_parallel_size: 2         # Distribute experts
     global_batch_size: 32           # Scale with GPU count
     micro_batch_size: 1
     enable_fsdp_offload: false      # Faster training

Memory-Constrained Setup
------------------------

.. code-block:: yaml

   train:
     enable_gradient_checkpointing: true
     enable_full_shard: true
     enable_fsdp_offload: true       # Enable CPU offloading
     enable_activation_offload: true # Reduce GPU memory
     micro_batch_size: 1             # Minimal per-GPU batch

Best Practices
==============

**Path Management**
   Use relative paths for configs
      Store absolute paths in environment variables
      Create separate output directories per experiment

**Parameter Tuning**
   Start with conservative batch sizes
      Increase learning rate for larger batches
      Adjust warmup ratio based on dataset size

**Monitoring**
   Enable W&B for experiment tracking
      Set appropriate logging frequency
      Monitor gradient norms and loss curves

**Reproducibility**
   Fix random seeds in training scripts
      Document configuration changes
      Version control configuration files