Repository navigation
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| and state_dict is None | ||
| and checkpoint_files is not None | ||
| and checkpoint_files[0].endswith(".safetensors") | ||
| and (load_config.hf_quantizer is None or load_config.hf_quantizer.pre_quantized) |
There was a problem hiding this comment.
not sure about this @ArthurZucker, is it possible to apply quantisation directly on device?
There was a problem hiding this comment.
its own device allocations
the device allocation of the checkpoint shard? The engine of the process?
There was a problem hiding this comment.
yeah, quite te contrary most ops are gpu compatible -> faster on device.
There was a problem hiding this comment.
ok good to know, because the prefetch engine loads directly on device. for now i've disabled it when quantisation is involved, but we need to think of how to make it compatible in that case!
ArthurZucker
left a comment
There was a problem hiding this comment.
Ty! I don't understand anything from the code / comments, happy to talk about it more.
Users need to know why they'd opt in on this (our out if we default_
| """The single CUDA device every entry of `device_map` resolves to, or `None`. | ||
|
|
||
| One shard handle loads onto one device, so the prefetch path is used only when the whole model lands on | ||
| the same CUDA device (also the case for every rank of a tensor-parallel load). |
There was a problem hiding this comment.
comment is a bit obfuscated.
One shard of what? the checkpoint shard? a Rank?
Whole model on the same CUDA device as what? the shard?
Is this for a single device?
| class PrefetchedShard: | ||
| """One open shard whose background load starts the first time a tensor of it is materialised. | ||
|
|
||
| `copy_full` makes even whole-tensor reads compact copies. The engine allocates a shard in ranges that |
There was a problem hiding this comment.
copy_fullmakes even whole-tensor reads compact copies.
Sorry not enough context to understand 🍭
| hold many neighbouring tensors and frees a range only when its last view is gone; on a rank that keeps | ||
| just a slice of most tensors (tensor parallelism), a zero-copy view of a small replicated tensor would | ||
| pin its whole range, so nothing is kept as a view there. |
There was a problem hiding this comment.
I don't understand much.
Pin where? cpu pinned memory?
| and state_dict is None | ||
| and checkpoint_files is not None | ||
| and checkpoint_files[0].endswith(".safetensors") | ||
| and (load_config.hf_quantizer is None or load_config.hf_quantizer.pre_quantized) |
There was a problem hiding this comment.
its own device allocations
the device allocation of the checkpoint shard? The engine of the process?
| and state_dict is None | ||
| and checkpoint_files is not None | ||
| and checkpoint_files[0].endswith(".safetensors") | ||
| and (load_config.hf_quantizer is None or load_config.hf_quantizer.pre_quantized) |
There was a problem hiding this comment.
yeah, quite te contrary most ops are gpu compatible -> faster on device.
| and is_prefetch_available() | ||
| ): | ||
| prefetch_device = prefetch_target_device(load_config.device_map) | ||
| if prefetch_device is not None: | ||
| logger.info(f"Loading safetensors shards with the CUDA prefetch engine on {prefetch_device}") | ||
| if load_config.prefetch and prefetch_device is None: | ||
| logger.warning( | ||
| "prefetch=True was requested but this checkpoint cannot be loaded with safetensors' CUDA " | ||
| "prefetch engine (it needs safetensors >= 0.9.0rc1 on Linux, safetensors files and a single " | ||
| "CUDA device); loading with the default loader." | ||
| ) |
There was a problem hiding this comment.
everything needs to be in the integration / safetensors with a single validate_prefetch called here as a 1 liner
133d6ce to
bc2c1c0
Compare
Signed-off-by: Luc Georges <[email protected]>
Signed-off-by: Luc Georges <[email protected]>
Signed-off-by: Luc Georges <[email protected]>
Signed-off-by: Luc Georges <[email protected]>
4aaa8fb to
f4950da
Compare
ArthurZucker
left a comment
There was a problem hiding this comment.
starting to look good!
| else: | ||
| _add_unmatched_checkpoint_key(renamed_key, model, loading_info) | ||
|
|
||
| prefetches = [] |
There was a problem hiding this comment.
if no prefetch keep the spawn meterialize in the loop?
| ] | ||
|
|
||
|
|
||
| class FilePrefetch: |
There was a problem hiding this comment.
typing + hard follow where the intervals are from, offuscated a bit here!
| tensor = tensor.to(device=device, dtype=dtype) | ||
| return tensor | ||
| @dataclass | ||
| class TensorLoad: |
There was a problem hiding this comment.
any thing we can do in the constructor?
| shape = list(tensor.shape) if isinstance(tensor, torch.Tensor) else tensor.get_shape() | ||
| if renamed_key not in shard_ops: # e.g. built once for all the experts of a stacked param | ||
| shard_ops[renamed_key] = DtensorShardOperation(empty_param) | ||
| intervals = shard_ops[renamed_key].intervals(shape, tensor_idx) |
There was a problem hiding this comment.
intervals are created here yes!
Signed-off-by: Luc Georges <[email protected]>
CI recapDashboard: View test results in Grafana |
|
Re-ran with safetensors 0.9.0rc1. The global tensor cache is gone but two memory issues are still there (and they matter more now that prefetch is on by default):
|
|
🫠 |
|
@qgallouedec both memory issues are fixed by safetensors/safetensors#902: prefetch now allocates through torch's caching allocator. Qwen3-32B, 1×H200,
GLM-5.2-FP8, 8×H200, |
|
Nice! confirmed on my side! Also:
|
| # skipped with prefetch: weights land in GPU memory safetensors allocates itself, outside torch's caching | ||
| # allocator, so warming the allocator up would only double memory use |
There was a problem hiding this comment.
with safetensors/safetensors#902, the weights now go through torch's allocator
| # skipped with prefetch: weights land in GPU memory safetensors allocates itself, outside torch's caching | |
| # allocator, so warming the allocator up would only double memory use | |
| # skipped with prefetch: safetensors allocates the weights itself, so the warmed-up block would sit unused | |
| # next to them and double peak memory |
GLM 5.2 fp8 on tp=8 on a b200: 1535s -> ~160s
needs safetensors/safetensors#864 to be merged