gguf : do not store defaults in class vars

Making an assignment in a class outside of a method does not set the
default value, it actually sets the attribute on the class itself.
Instances of the class inherit these, but it's incorrect to expose these
fields here.
This commit is contained in:
Cebtenzzre 2023-10-01 17:49:22 -04:00 committed by cebtenzzre
parent 207b51900e
commit 6df988d5f1

View file

@ -638,15 +638,7 @@ class GGUFValueType(IntEnum):
class GGUFWriter: class GGUFWriter:
fout: BufferedWriter fout: BufferedWriter
arch: str temp_file: tempfile.SpooledTemporaryFile[bytes] | None
offset_tensor = 0
data_alignment = GGUF_DEFAULT_ALIGNMENT
kv_data = b""
kv_data_count = 0
ti_data = b""
ti_data_count = 0
use_temp_file: bool
temp_file: tempfile.SpooledTemporaryFile[bytes] | None = None
tensors: list[tuple[np.ndarray[Any, Any], int]] tensors: list[tuple[np.ndarray[Any, Any], int]]
@property @property
@ -673,12 +665,20 @@ class GGUFWriter:
GGUFValueType.FLOAT64: f"{self.pack_prefix}d", GGUFValueType.FLOAT64: f"{self.pack_prefix}d",
GGUFValueType.BOOL: "?" , GGUFValueType.BOOL: "?" ,
} }
self.add_architecture() self.offset_tensor = 0
self.data_alignment = GGUF_DEFAULT_ALIGNMENT
self.kv_data = b""
self.kv_data_count = 0
self.ti_data = b""
self.ti_data_count = 0
self.use_temp_file = use_temp_file self.use_temp_file = use_temp_file
self.temp_file = None
self.tensors = [] self.tensors = []
endianess_str = "Big Endian" if self.endianess == GGUFEndian.BIG else "Little Endian" endianess_str = "Big Endian" if self.endianess == GGUFEndian.BIG else "Little Endian"
print(f"This gguf file is for {endianess_str} only") print(f"This gguf file is for {endianess_str} only")
self.add_architecture()
def write_header_to_file(self): def write_header_to_file(self):
self.fout.write(struct.pack("<I", GGUF_MAGIC)) self.fout.write(struct.pack("<I", GGUF_MAGIC))
self.fout.write(struct.pack(f"{self.pack_prefix}I", GGUF_VERSION)) self.fout.write(struct.pack(f"{self.pack_prefix}I", GGUF_VERSION))
@ -983,11 +983,8 @@ class GGUFWriter:
class SpecialVocab: class SpecialVocab:
load_merges: bool = False merges: list[str]
merges: list[str] = [] special_token_ids: dict[str, int]
special_token_types: tuple[str, ...] = ('bos', 'eos', 'unk', 'sep', 'pad')
special_token_ids: dict[str, int] = {}
n_vocab: int | None = None
def __init__( def __init__(
self, path: str | os.PathLike[str], load_merges: bool = False, self, path: str | os.PathLike[str], load_merges: bool = False,
@ -997,8 +994,11 @@ class SpecialVocab:
self.special_token_ids = {} self.special_token_ids = {}
self.n_vocab = n_vocab self.n_vocab = n_vocab
self.load_merges = load_merges self.load_merges = load_merges
self.merges = []
if special_token_types is not None: if special_token_types is not None:
self.special_token_types = special_token_types self.special_token_types = special_token_types
else:
self.special_token_types = ('bos', 'eos', 'unk', 'sep', 'pad')
self._load(Path(path)) self._load(Path(path))
def _load(self, path: Path) -> None: def _load(self, path: Path) -> None: