| """ |
| GGUF + DAG Pipeline — load GGUF model, run through networkx DAG |
| Author: Ahmad Ali Parr · Trust: Bel Esprit D'Accord Irrevocable Trust |
| """ |
| |
| from llama_cpp import Llama |
| import networkx as nx |
|
|
| model = Llama(model_path="model.gguf", n_ctx=2048, n_threads=8) |
|
|
| |
| dag = nx.DiGraph() |
| dag.add_nodes_from(["parse_binary", "convert_numpy", "convert_torch", "inference"]) |
| dag.add_edges_from([ |
| ("parse_binary", "convert_numpy"), |
| ("convert_numpy", "convert_torch"), |
| ("convert_torch", "inference"), |
| ]) |
|
|
| def parse_binary(path): |
| with open(path, "rb") as f: |
| return f.read() |
|
|
| def convert_numpy(bin_data): |
| import numpy as np |
| return np.frombuffer(bin_data, dtype=np.float32) |
|
|
| def convert_torch(np_arr): |
| import torch |
| return torch.from_numpy(np_arr) |
|
|
| def inference(tensor): |
| return model("Translate this sentence to Korean:") |
|
|
| |
| binary_data = parse_binary("model.gguf") |
| np_arr = convert_numpy(binary_data) |
| torch_tensor = convert_torch(np_arr) |
| output = inference(torch_tensor) |
| print(output) |
|
|