compressed_tensors.offload.dispatch
Functions:
-
dispatch_model–Dispatch a model for autoregressive generation. This means that modules are
-
dispatch_with_map–Dispatch a model according to the provided device map
-
get_device_map–Get the device map of a CT-offloaded model
-
get_device_memory–Get the total memory of all available accelerator devices. Returns accelerator
-
offload_model–.. deprecated::
-
remove_dispatch–Remove any existing dispatches from module
-
set_onload_device–Modify the dispatch of a model to onload to the provided
onload_device. All
dispatch_model
dispatch_model(model: ModelType, device_memory: dict[device, int] | None = None, extra_memory: int | None = None, no_split_modules: Container[str] | None = None) -> ModelType
Dispatch a model for autoregressive generation. This means that modules are dispatched evenly across available devices and kept onloaded if possible. If onloading the entire model is not possible, some modules may be offloaded. Any existing offloads will be removed.
Disclaimers:
* Optimal runtime assumes that modules are called in order of model.modules()
Parameters:
-
model(ModelType) –model to dispatch
-
device_memory(dict[device, int] | None, default:None) –optional dictionary mapping torch device to available memory. If none is provided, all available devices will be used
-
extra_memory(int | None, default:None) –the amount of memory to be reserved for activations
-
no_split_modules(Container[str] | None, default:None) –names of module classes which should not be split across multiple devices
Returns:
-
ModelType–dispatched model
Source code in src/compressed_tensors/offload/dispatch.py
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 | |
dispatch_with_map
dispatch_with_map(model: Module, device_map: DeviceMap, offload_dir: Optional[str] = None, show_progress: bool = True)
Dispatch a model according to the provided device map
Parameters:
-
model(Module) –model to dispatch
-
device_map(DeviceMap) –device map specifying the onload and offload of each module
-
offload_dir(Optional[str], default:None) –optional directory for disk offloading
-
show_progress(bool, default:True) –show tqdm progress
Source code in src/compressed_tensors/offload/dispatch.py
get_device_map
Get the device map of a CT-offloaded model
Parameters:
-
default_device(device, default:device('cpu')) –the default onload/offload device when module has no parameters
Returns:
-
DeviceMap–device map specifying the onload and offload device of all modules
Source code in src/compressed_tensors/offload/dispatch.py
get_device_memory
Get the total memory of all available accelerator devices. Returns accelerator device memory when available, otherwise falls back to CPU with system RAM.
Returns:
-
dict[device, int]–mapping from torch device to total memory
Source code in src/compressed_tensors/offload/dispatch.py
offload_model
offload_model(model: ModelType, onload_device: device | str, offload_device: Any = None) -> ModelType
.. deprecated::
Use :func:set_onload_device instead.
Source code in src/compressed_tensors/offload/dispatch.py
remove_dispatch
Remove any existing dispatches from module
Parameters:
-
onload_tensors(bool, default:False) –Whether to move tensors to the onloaded device, or keep them on the offload device. Defaults to False.
Returns:
-
Module–module with offloading functionality removed
Source code in src/compressed_tensors/offload/dispatch.py
set_onload_device
Modify the dispatch of a model to onload to the provided onload_device. All
modules will be offloaded, with offload device set with the following priority:
- Offloaded modules retain their existing offloads
- Modules with existing parameters will be offloaded to the parameter device
- Modules without parameters will adopt of the offloading of any offloaded children
- Modules without parameters or children will be offloaded to cpu
Parameters:
-
model–model to dispatch
-
onload_device(device | str) –device to move weights to during forward pass