MojoLlama
Archived Mojo/MAX quantizer and serving research repository (read-only history)
Brought by drakestapleton
| 1 | from std.python import Python |
| 2 | from mojollama.gguf.reader import load_gguf |
| 3 | |
| 4 | fn main() raises: |
| 5 | var model_path_py = Python.evaluate("__import__('os').environ.get('MODEL_PATH', '')") |
| 6 | |
| 7 | if Python.evaluate("len")(model_path_py) == 0: |
| 8 | var glob = Python.evaluate("__import__('glob')") |
| 9 | var files = glob.glob("*.gguf") |
| 10 | if Python.evaluate("len")(files) > 0: |
| 11 | model_path_py = files[0] |
| 12 | else: |
| 13 | print("Usage: MODEL_PATH=<model.gguf> ./build/mojollama") |
| 14 | return |
| 15 | |
| 16 | var model_path = String(model_path_py) |
| 17 | print("Loading GGUF:", model_path) |
| 18 | var metadata = load_gguf(model_path) |
| 19 | |
| 20 | var is_none = Python.evaluate("lambda x: x is None")(metadata) |
| 21 | if is_none: |
| 22 | print("Failed to load model") |
| 23 | return |
| 24 | |
| 25 | var arch = "unknown" |
| 26 | if metadata.__contains__("general.architecture"): |
| 27 | arch = String(metadata["general.architecture"]) |
| 28 | print("Architecture:", arch) |
| 29 | |
| 30 | var tensor_info = metadata["_tensor_info"] |
| 31 | var n_tensors = Int(py=Python.evaluate("len")(tensor_info)) |
| 32 | print("Tensors:", n_tensors) |
| 33 | |
| 34 | if n_tensors > 0: |
| 35 | var t0 = tensor_info[0] |
| 36 | print("First tensor:", String(t0["name"])) |
| 37 | |
| 38 | print("Done") |