DeepSpeedRunner¶
danling.runner.deepspeed_runner
¶
DeepSpeedRunner
¶
Bases: TorchRunner
DeepSpeed-powered runner for large-scale model operations.
DeepSpeedRunner integrates Microsoft’s DeepSpeed framework to enable efficient execution of large language models and other compute-intensive neural networks with advanced memory optimization techniques.
Key features:
- ZeRO (Zero Redundancy Optimizer) for memory-efficient distributed operations
- Mixed precision execution with reduced memory footprint
- Progressive layer dropping for computational acceleration
- 3D parallelism (data, model, pipeline) for billion+ parameter models
- Optimized checkpoint management for large models
DeepSpeedRunner is particularly useful for:
- Operating large language models efficiently across multiple GPUs
- Running larger models within limited GPU memory constraints
- Achieving near-linear scaling in multi-node distributed settings
- Evaluating very large models that wouldn’t fit in memory with standard approaches
Configuration
DeepSpeed requires a specific configuration format. You can provide a DeepSpeed
configuration in the deepspeed
key of your runner config, or let DanLing auto-generate
a configuration based on your other settings.
Note
For optimal performance, DeepSpeed requires NVMe offloading and specific GPU configurations. See DeepSpeed documentation for details.
See Also
TorchRunner
: PyTorch DDP runner.- DeepSpeed Documentation: Official DeepSpeed docs.
Source code in danling/runner/deepspeed_runner.py
Python | |
---|---|
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
|
init_distributed
¶
Set up distributed training.
Initialise process group and set up DDP variables.
Source code in danling/runner/deepspeed_runner.py
save_checkpoint
¶
save_checkpoint(name: str = 'latest', epoch: int | None = None, save_best: bool = True) -> None
Save checkpoint to self.checkpoint_dir
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str
|
Name of the checkpoint. Defaults to |
'latest'
|
|
int | None
|
Epoch to save. Defaults to |
None
|
|
bool
|
If |
True
|
If self.config.save_interval
is positive and epochs + 1
is a multiple of save_interval
,
the checkpoint will also be copied to self.checkpoint_dir/epoch-{epochs}
.
Source code in danling/runner/deepspeed_runner.py
load_checkpoint
¶
Load model, optimizer, and scheduler from checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bytes | str | PathLike
|
Checkpoint (or its path) to load. |
required |
|
Additional arguments to pass to |
()
|
|
|
Additional keyword arguments to pass to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
ValueError
|
If |
See Also
from_checkpoint
: Build runner from checkpoint.
load_pretrained
: Load model parameters from pretrained checkpoint.
Source code in danling/runner/deepspeed_runner.py
load_pretrained
¶
Load model from pretrained checkpoint.
This method only loads the model weights.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bytes | str | PathLike
|
Pretrained checkpoint directory. |
required |
|
Additional arguments to pass to |
()
|
|
|
Additional keyword arguments to pass to |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
If |
See Also
load_checkpoint
: Load model, optimizer, and scheduler from
checkpoint.
Source code in danling/runner/deepspeed_runner.py
load_config
¶
load_config(checkpoint: bytes | str | PathLike, overwrite: bool = False, *args, **kwargs) -> None
Load config from checkpoint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
bytes | str | PathLike
|
Checkpoint (or its path) to load. |
required |
|
bool
|
If |
False
|
|
Additional arguments to pass to |
()
|
|
|
Additional keyword arguments to pass to |
{}
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If |