dodle commited on
Commit
bd9a8ac
·
verified ·
1 Parent(s): b93ff7c

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. README.md +5 -1
  2. me.py +54 -2
README.md CHANGED
@@ -19,7 +19,9 @@ cd core/model
19
  python3 me.py
20
  ```
21
 
22
- This creates `noe-model.dodl` in the current directory. `create_model_file(path)` is also available when creating a model from Python; it writes the binary DODL format and returns the model object.
 
 
23
 
24
  The path may be a string or another path-like value. Its parent directory must already exist. The file is binary; open it with `"rb"` when reading.
25
 
@@ -100,6 +102,8 @@ The file starts with the `DODL` magic signature and a versioned header. It store
100
  - `create_model_file(path)` creates a fresh model and writes it to `path`.
101
  - `serialize_model(model)` converts a model to DODL bytes.
102
  - `deserialize_model(data)` converts DODL bytes back to a model.
 
 
103
  - `merge_models(model_a, model_b, alpha=0.5)` blends compatible models' network parameters.
104
  - `AIEngine(model=None)` runs and updates a model; without an argument it creates a fresh one.
105
  - `AIEngine.step(input_value)` observes input, chooses and executes an action, evaluates it, learns, updates state, and returns the cycle result.
 
19
  python3 me.py
20
  ```
21
 
22
+ This creates `noe-model.dodl` and `noe-model.gguf` in the current directory. The DODL file stores the complete model, including its state, memory, rules, behavior, and network. The GGUF file contains the network's four float32 tensors and architecture dimensions; it uses the custom `noesis` architecture and requires a compatible runtime to execute.
23
+
24
+ `create_model_file(path)` is also available when creating a model from Python; it writes the binary DODL format and returns the model object. Pass that model to `create_gguf_model_file(path, model)` to write the matching GGUF file.
25
 
26
  The path may be a string or another path-like value. Its parent directory must already exist. The file is binary; open it with `"rb"` when reading.
27
 
 
102
  - `create_model_file(path)` creates a fresh model and writes it to `path`.
103
  - `serialize_model(model)` converts a model to DODL bytes.
104
  - `deserialize_model(data)` converts DODL bytes back to a model.
105
+ - `serialize_gguf_model(model)` converts the network tensors to GGUF v3 bytes.
106
+ - `create_gguf_model_file(path, model)` writes those GGUF bytes to `path`.
107
  - `merge_models(model_a, model_b, alpha=0.5)` blends compatible models' network parameters.
108
  - `AIEngine(model=None)` runs and updates a model; without an argument it creates a fresh one.
109
  - `AIEngine.step(input_value)` observes input, chooses and executes an action, evaluates it, learns, updates state, and returns the cycle result.
me.py CHANGED
@@ -608,6 +608,50 @@ def serialize_model(model):
608
  return header + metadata_bytes + network_bytes
609
 
610
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
611
  def create_model_file(path):
612
  model = create_model()
613
  with open(path, "wb") as model_file:
@@ -615,6 +659,11 @@ def create_model_file(path):
615
  return model
616
 
617
 
 
 
 
 
 
618
  def deserialize_model(buffer):
619
  buffer = bytes(buffer)
620
  if len(buffer) < HEADER_SIZE or buffer[:4] != MAGIC:
@@ -954,5 +1003,8 @@ class AIEngine:
954
 
955
  if __name__ == "__main__":
956
  output_path = "noe-model.dodl"
957
- create_model_file(output_path)
958
- print(f"Model file created: {output_path}")
 
 
 
 
608
  return header + metadata_bytes + network_bytes
609
 
610
 
611
+ def _gguf_string(value):
612
+ encoded = value.encode("utf-8")
613
+ return struct.pack("<Q", len(encoded)) + encoded
614
+
615
+
616
+ def serialize_gguf_model(model):
617
+ network = model["network"]
618
+ tensors = (
619
+ ("network.weights1", (network["inputSize"], network["hiddenSize"]), network["weights1"]),
620
+ ("network.bias1", (network["hiddenSize"],), network["bias1"]),
621
+ ("network.weights2", (network["hiddenSize"], network["outputSize"]), network["weights2"]),
622
+ ("network.bias2", (network["outputSize"],), network["bias2"]),
623
+ )
624
+ metadata = (
625
+ ("general.architecture", 8, "noesis"),
626
+ ("general.name", 8, "Noesis Tiny Network"),
627
+ ("general.alignment", 4, 32),
628
+ ("noesis.input_size", 4, network["inputSize"]),
629
+ ("noesis.hidden_size", 4, network["hiddenSize"]),
630
+ ("noesis.output_size", 4, network["outputSize"]),
631
+ )
632
+ metadata_bytes = bytearray(struct.pack("<Q", len(metadata)))
633
+ for key, value_type, value in metadata:
634
+ metadata_bytes.extend(_gguf_string(key))
635
+ metadata_bytes.extend(struct.pack("<I", value_type))
636
+ metadata_bytes.extend(_gguf_string(value) if value_type == 8 else struct.pack("<I", value))
637
+
638
+ tensor_data = bytearray()
639
+ tensor_descriptors = bytearray(struct.pack("<Q", len(tensors)))
640
+ for name, dimensions, values in tensors:
641
+ tensor_data.extend(b"\0" * ((-len(tensor_data)) % 32))
642
+ offset = len(tensor_data)
643
+ tensor_data.extend(_float_array_bytes(values))
644
+ tensor_descriptors.extend(_gguf_string(name))
645
+ tensor_descriptors.extend(struct.pack("<I", len(dimensions)))
646
+ tensor_descriptors.extend(struct.pack(f"<{len(dimensions)}Q", *dimensions))
647
+ tensor_descriptors.extend(struct.pack("<IQ", 0, offset))
648
+
649
+ header = b"GGUF" + struct.pack("<IQQ", 3, len(tensors), len(metadata))
650
+ content = header + metadata_bytes + tensor_descriptors
651
+ content += b"\0" * ((-len(content)) % 32)
652
+ return content + tensor_data
653
+
654
+
655
  def create_model_file(path):
656
  model = create_model()
657
  with open(path, "wb") as model_file:
 
659
  return model
660
 
661
 
662
+ def create_gguf_model_file(path, model):
663
+ with open(path, "wb") as model_file:
664
+ model_file.write(serialize_gguf_model(model))
665
+
666
+
667
  def deserialize_model(buffer):
668
  buffer = bytes(buffer)
669
  if len(buffer) < HEADER_SIZE or buffer[:4] != MAGIC:
 
1003
 
1004
  if __name__ == "__main__":
1005
  output_path = "noe-model.dodl"
1006
+ model = create_model_file(output_path)
1007
+ print(f"Model file created: {output_path}")
1008
+ gguf_output_path = "noe-model.gguf"
1009
+ create_gguf_model_file(gguf_output_path, model)
1010
+ print(f"GGUF model file created: {gguf_output_path}")