Add big endian support
This commit is contained in:
parent
03c9683eb7
commit
fd30850576
3 changed files with 11 additions and 3 deletions
|
@ -28,12 +28,16 @@ else:
|
||||||
# output in the same directory as the model by default
|
# output in the same directory as the model by default
|
||||||
fname_out = dir_model / f'ggml-model-{ftype_str[ftype]}.gguf'
|
fname_out = dir_model / f'ggml-model-{ftype_str[ftype]}.gguf'
|
||||||
|
|
||||||
|
is_big_endian = False
|
||||||
|
if args.bigendian is not None:
|
||||||
|
is_big_endian = True
|
||||||
|
|
||||||
print(f"Loading model: {dir_model.name}")
|
print(f"Loading model: {dir_model.name}")
|
||||||
|
|
||||||
hparams = model.Model.load_hparams(dir_model)
|
hparams = model.Model.load_hparams(dir_model)
|
||||||
|
|
||||||
model_class = model.Model.from_model_architecture(hparams["architectures"][0])
|
model_class = model.Model.from_model_architecture(hparams["architectures"][0])
|
||||||
model_instance = model_class(dir_model, ftype, fname_out)
|
model_instance = model_class(dir_model, ftype, fname_out, is_big_endian)
|
||||||
|
|
||||||
print("Set model parameters")
|
print("Set model parameters")
|
||||||
model_instance.set_gguf_parameters()
|
model_instance.set_gguf_parameters()
|
||||||
|
|
6
model.py
6
model.py
|
@ -30,16 +30,18 @@ class SentencePieceTokenTypes(IntEnum):
|
||||||
|
|
||||||
|
|
||||||
class Model:
|
class Model:
|
||||||
def __init__(self, dir_model: Path, ftype: int, fname_out: Path):
|
def __init__(self, dir_model: Path, ftype: int, fname_out: Path, is_big_endian: bool):
|
||||||
self.dir_model = dir_model
|
self.dir_model = dir_model
|
||||||
self.ftype = ftype
|
self.ftype = ftype
|
||||||
self.fname_out = fname_out
|
self.fname_out = fname_out
|
||||||
|
self.is_big_endian = is_big_endian
|
||||||
|
self.endianess = gguf.GGUFEndian.BIG if is_big_endian else gguf.GGUFEndian.LITTLE
|
||||||
self.is_safetensors = self._is_model_safetensors()
|
self.is_safetensors = self._is_model_safetensors()
|
||||||
self.num_parts = Model.count_model_parts(self.dir_model, ".safetensors" if self.is_safetensors else ".bin")
|
self.num_parts = Model.count_model_parts(self.dir_model, ".safetensors" if self.is_safetensors else ".bin")
|
||||||
self.part_names = self._get_part_names()
|
self.part_names = self._get_part_names()
|
||||||
self.hparams = Model.load_hparams(self.dir_model)
|
self.hparams = Model.load_hparams(self.dir_model)
|
||||||
self.model_arch = self._get_model_architecture()
|
self.model_arch = self._get_model_architecture()
|
||||||
self.gguf_writer = gguf.GGUFWriter(fname_out, gguf.MODEL_ARCH_NAMES[self.model_arch])
|
self.gguf_writer = gguf.GGUFWriter(fname_out, gguf.MODEL_ARCH_NAMES[self.model_arch], endianess=self.endianess)
|
||||||
|
|
||||||
def set_vocab(self):
|
def set_vocab(self):
|
||||||
self._set_vocab_gpt2()
|
self._set_vocab_gpt2()
|
||||||
|
|
2
util.py
2
util.py
|
@ -20,4 +20,6 @@ def parse_args() -> argparse.Namespace:
|
||||||
"ftype", type=int, choices=[0, 1], default=1, nargs='?',
|
"ftype", type=int, choices=[0, 1], default=1, nargs='?',
|
||||||
help="output format - use 0 for float32, 1 for float16",
|
help="output format - use 0 for float32, 1 for float16",
|
||||||
)
|
)
|
||||||
|
parser.add_argument("--bigendian", action="store_true", help="model is executed on big endian machine")
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue