-
Notifications
You must be signed in to change notification settings - Fork 27.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Safetensors offload #20321
Safetensors offload #20321
Conversation
The documentation is not available anymore as the PR was closed or merged. |
@@ -28,7 +28,7 @@ | |||
|
|||
import torch | |||
from packaging import version | |||
from torch import Tensor, device, nn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import was dangerous with so many local variables named device
. It was only used in a type annotation.
offload_index = { | ||
p: {"safetensors_file": os.path.join(folder, f), "weight_name": p, "dtype": str_dtype} | ||
for p, f in sharded_metadata["weight_map"].items() | ||
if param_device_map[p] == "disk" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We build the offload_index
here when the checkpoin is safetensors
, this way we can skip loading all the shards and gain time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, very cool addition! Should make a lot of things simpler
* INtegrate safetensos in weight offloading * Use safetensors checkpoint for offload when available * Make naming consistent * Make load faster * Quality * Add default
What does this PR do?
This PRs make offload to disk more efficient for models that have a checkpoint in safetensors format: instead of re-saving everything as Numpy memory-mapped array, it uses directly the fact we can access the tensor in the checkpoint without loading the rest.
Goes with huggingface/accelerate#873