added SAVE_ON_CRASH
Browse files- _safetensors.py +3 -2
- run_test.py +2 -0
_safetensors.py
CHANGED
|
@@ -6,7 +6,7 @@ import torch
|
|
| 6 |
from _bighash import hash
|
| 7 |
|
| 8 |
class WritingSafeTensors:
|
| 9 |
-
def __init__(self, name, file_size=16*1024*1024*1024, deduplicate=False, **metadata):
|
| 10 |
self.name = name.removesuffix('.safetensors')
|
| 11 |
self.metadata = metadata
|
| 12 |
self.file = self.File(self.name + '.safetensors')
|
|
@@ -16,6 +16,7 @@ class WritingSafeTensors:
|
|
| 16 |
if deduplicate:
|
| 17 |
warnings.warn('Safetensors deduplication enabled. The file will not be readable with the official library without https://github.com/huggingface/safetensors/pull/586', stacklevel=2)
|
| 18 |
self.hash_map = {} if deduplicate else None
|
|
|
|
| 19 |
def add(self, name, tensor):
|
| 20 |
if self.hash_map is None:
|
| 21 |
self.file.add(name, tensor, return_hash=False)
|
|
@@ -87,7 +88,7 @@ class WritingSafeTensors:
|
|
| 87 |
return self
|
| 88 |
def __exit__(self, Exc, exc, tb):
|
| 89 |
throw = None
|
| 90 |
-
if Exc is None:
|
| 91 |
try:
|
| 92 |
self.finalize()
|
| 93 |
except:
|
|
|
|
| 6 |
from _bighash import hash
|
| 7 |
|
| 8 |
class WritingSafeTensors:
|
| 9 |
+
def __init__(self, name, file_size=16*1024*1024*1024, deduplicate=False, save_on_crash=False, **metadata):
|
| 10 |
self.name = name.removesuffix('.safetensors')
|
| 11 |
self.metadata = metadata
|
| 12 |
self.file = self.File(self.name + '.safetensors')
|
|
|
|
| 16 |
if deduplicate:
|
| 17 |
warnings.warn('Safetensors deduplication enabled. The file will not be readable with the official library without https://github.com/huggingface/safetensors/pull/586', stacklevel=2)
|
| 18 |
self.hash_map = {} if deduplicate else None
|
| 19 |
+
self.save_on_crash = save_on_crash
|
| 20 |
def add(self, name, tensor):
|
| 21 |
if self.hash_map is None:
|
| 22 |
self.file.add(name, tensor, return_hash=False)
|
|
|
|
| 88 |
return self
|
| 89 |
def __exit__(self, Exc, exc, tb):
|
| 90 |
throw = None
|
| 91 |
+
if Exc is None or self.save_on_crash:
|
| 92 |
try:
|
| 93 |
self.finalize()
|
| 94 |
except:
|
run_test.py
CHANGED
|
@@ -3,6 +3,7 @@ import contextlib, os, sys
|
|
| 3 |
|
| 4 |
STORE_WEIGHTS = False
|
| 5 |
DEDUPLICATE_SAFETENSORS = True
|
|
|
|
| 6 |
FAKE_H100 = False
|
| 7 |
TORCH_DTYPE = 'float64'
|
| 8 |
USE_GPU = False
|
|
@@ -79,6 +80,7 @@ with range_progress_description('constructing pipeline'):
|
|
| 79 |
SafeTensors = WritingSafeTensors(
|
| 80 |
fn,
|
| 81 |
deduplicate = DEDUPLICATE_SAFETENSORS,
|
|
|
|
| 82 |
prompt = prompt,
|
| 83 |
store_weights = STORE_WEIGHTS,
|
| 84 |
use_gpu = USE_GPU,
|
|
|
|
| 3 |
|
| 4 |
STORE_WEIGHTS = False
|
| 5 |
DEDUPLICATE_SAFETENSORS = True
|
| 6 |
+
SAVE_ON_CRASH = False
|
| 7 |
FAKE_H100 = False
|
| 8 |
TORCH_DTYPE = 'float64'
|
| 9 |
USE_GPU = False
|
|
|
|
| 80 |
SafeTensors = WritingSafeTensors(
|
| 81 |
fn,
|
| 82 |
deduplicate = DEDUPLICATE_SAFETENSORS,
|
| 83 |
+
save_on_crash = SAVE_ON_CRASH,
|
| 84 |
prompt = prompt,
|
| 85 |
store_weights = STORE_WEIGHTS,
|
| 86 |
use_gpu = USE_GPU,
|