-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f4e046a
commit 9e4a246
Showing
4 changed files
with
26 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import numpy as np | ||
import safetensors | ||
|
||
def save_external_weights( | ||
mapper, | ||
model, | ||
external_weights=None, | ||
external_weight_file=None, | ||
): | ||
if external_weights is not None: | ||
if external_weights == "safetensors": | ||
mod_params = dict(model.named_parameters()) | ||
for name in mod_params: | ||
mapper["params." + name] = name | ||
if external_weight_file: | ||
safetensors.torch.save_file(mod_params, external_weight_file) | ||
print("Saved params to", external_weight_file) | ||
|
||
|
||
def largest_error(array1, array2): | ||
absolute_diff = np.abs(array1 - array2) | ||
max_error = np.max(absolute_diff) | ||
return max_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters