Function
load_state_dict_from_safetensors
(file_path, torch_dtype=None)
Source from the content-addressed store, hash-verified
| 70 | |
| 71 | |
| 72 | def load_state_dict_from_safetensors(file_path, torch_dtype=None): |
| 73 | state_dict = {} |
| 74 | with safe_open(file_path, framework="pt", device="cpu") as f: |
| 75 | for k in f.keys(): |
| 76 | state_dict[k] = f.get_tensor(k) |
| 77 | if torch_dtype is not None: |
| 78 | state_dict[k] = state_dict[k].to(torch_dtype) |
| 79 | return state_dict |
| 80 | |
| 81 | |
| 82 | def load_state_dict_from_bin(file_path, torch_dtype=None): |
Tested by
no test coverage detected