Megatron parallel state utils
This package contains utilities for managing the state of distributed model parallelism in Megatron and Apex.
In general you should just use the context manager distributed_model_parallel_state
to manage the state of
your test. This context manager will handle the setup and teardown of the distributed model parallel state for you.
Example usage:
from bionemo.testing import megatron_parallel_state_utils
def my_test():
with megatron_parallel_state_utils.distributed_model_parallel_state():
# your test code that requires megatron/apex parallel state to be set up here
clean_parallel_state_context()
Puts you into a clean parallel state, and again tears it down at the end.
Source code in bionemo/testing/megatron_parallel_state_utils.py
105 106 107 108 109 110 111 112 113 114 115 |
|
distributed_model_parallel_state(seed=42, devices=1, tensor_model_parallel_size=1, pipeline_model_parallel_size=1, pipeline_model_parallel_split_rank=0, context_parallel_size=1, interactive=False)
Context manager for handling creating and cleaning up distributed model parallel state for tests. Use like: with distributed_model_parallel_state(): # your test code here
After the block your state is cleaned up.
Source code in bionemo/testing/megatron_parallel_state_utils.py
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 |
|
mock_distributed_parallel_state(world_size=8, rank=0, tensor_model_parallel_size=1, pipeline_model_parallel_size=1, virtual_pipeline_model_parallel_size=None, context_parallel_size=1, expert_model_parallel_size=1, seed=42)
A context manager that facilitates easy mocking of torch.distributed for an arbitrary GPU in a simulated cluster.
Key functions that are mocked
torch.distributed.new_group
whenbackend="gloo"
which doesn't support abackend="fake"
torch.distributed.destroy_process_group
whenbackend="gloo"
since new "gloo" groups are not actually madetorch._C._cuda_setDevice
which changes the current device behind the scenes. We assign devices round-robin to supportworld_size > torch.cuda.device_count()
.
Outside of this mocking, a fake cluster is initialized using backend="fake"
in torch.distributed
. This sets up
enough global state and environment for megatron to think that it is initializing a larger cluster with some
settings where the current context has some user defined rank. You can then test the megatron state on a
hypothetical rank in some large world size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
world_size
|
int
|
The world size (cluster size). Defaults to 8. |
8
|
rank
|
int
|
the GPU number globally in the cluster. Defaults to 0. |
0
|
tensor_model_parallel_size
|
int
|
tensor model parallel setting for megatron. Defaults to 1. |
1
|
pipeline_model_parallel_size
|
int
|
pipeline model parallel setting for megatron. Defaults to 1. |
1
|
virtual_pipeline_model_parallel_size
|
Optional[int]
|
virtual pipeline model parallel size for megatron. Defaults to None. |
None
|
context_parallel_size
|
int
|
context parallel size. Defaults to 1. |
1
|
expert_model_parallel_size
|
int
|
expert model parallel size. Defaults to 1. |
1
|
seed
|
int | None
|
seed for RNG state. Defaults to 42. |
42
|
Source code in bionemo/testing/megatron_parallel_state_utils.py
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|