Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/examples/magika/convert.py # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / examples / magika / convert.py` 32 lines ยท 938 bytes Raw Blame History 1 import sys 2 from tensorflow import keras 3 import gguf 4 5 def convert(model_name): 6 model = keras.models.load_model(model_name, compile=False) 7 gguf_model_name = model_name + ".gguf" 8 gguf_writer = gguf.GGUFWriter(gguf_model_name, "magika") 9 10 for layer in model.layers: 11 # export layers with weights 12 if layer.weights: 13 for weight in layer.weights: 14 print(f" [{weight.name}] {weight.shape} {weight.dtype}") 15 weight_data = weight.numpy() 16 gguf_writer.add_tensor(weight.name, weight_data.T) 17 18 19 gguf_writer.write_header_to_file() 20 gguf_writer.write_kv_data_to_file() 21 gguf_writer.write_tensors_to_file() 22 gguf_writer.close() 23 print("Model converted and saved to '{}'".format(gguf_model_name)) 24 25 26 if __name__ == '__main__': 27 if len(sys.argv) > 1: 28 model_file = sys.argv[1] 29 else: 30 model_file = "model.h5" 31 32 convert(model_file)