Skip to main content

Atomic Model Fragmentation (AMF) — Molecular Inference Engine for resource-constrained hardware

Project description

⚛️ AMF — Atomic Model Fragmentation

First Arabic-originated Molecular Inference Engine for LLMs أول مكتبة عربية توفر محرك استدلال جزيئي للنماذج اللغوية الكبيرة

PyPI version Python License: MIT RAM

pip install amf-core

What is AMF?

AMF (Atomic Model Fragmentation) is a Python library that enables running large language models (LLMs) on severely resource-constrained hardware — including machines with less than 1 GB of VRAM and as little as 300 MB of RAM.

Instead of loading an entire model into memory, AMF:

  1. Fragments the model into independent semantic cells
  2. Analyzes each user prompt to determine which cells are needed
  3. Loads only the required cells on demand via memory-mapping
  4. Infers using only the active subset of weights

Validated on Kaggle: Qwen2.5-7B (9 GB model) running with < 500 MB RAM ✅


Installation

pip install amf-core

Optional extras:

pip install amf-core[safetensors]   # Safetensors / HuggingFace support
pip install amf-core[dev]           # Development tools

Requirements: Python ≥ 3.10, numpy, gguf, rich, scikit-learn


Quick Start

1 — Direct Molecular Inference (fastest)

import amf

eng = amf.engine("path/to/model.gguf")
eng.load()

print(eng.predict("Hello"))           # → "resilient"
print(eng.generate("Hello", n=5))    # → "Hello resilient strong bold clear"

eng.close()

2 — Context manager (auto-close)

import amf

with amf.engine("model.gguf") as eng:
    print(eng.predict("The future of AI is"))

3 — Full Fragmentation Pipeline

import amf

model = amf.load_universal("path/to/model.gguf")
cells = amf.fragment(model, strategy="functional", output_dir="./cells")
print(f"Generated {cells.total_cells} cells ({cells.total_bytes / 1e6:.0f} MB)")

for cell in cells.cells:
    print(f"  {cell.cell_id:30s}  DNA: {cell.dna_tag}  ({cell.size_mb:.1f} MB)")

4 — CLI

amf fragment --model qwen2.5:0.5b   # Fragment a model
amf chat                             # Interactive chat
amf info                             # System info

Architecture

AMF operates in 6 distinct phases:

User Prompt
    │
    ▼
┌──────────────────────────────────────────────────────────┐
│  1. Universal Parsing    │  ModelLoader reads GGUF /     │
│                          │  Safetensors → UniversalModel │
├──────────────────────────┼───────────────────────────────┤
│  2. Weight Analysis      │  WeightAnalyzer classifies    │
│                          │  tensors by zone & function   │
├──────────────────────────┼───────────────────────────────┤
│  3. DNA Tagging          │  SortingAlgorithm assigns     │
│                          │  tags: A-L-003-Q              │
│                          │  (Attention-Linguistic-L3-Q)  │
├──────────────────────────┼───────────────────────────────┤
│  4. Intent Analysis      │  IntentAnalyzer determines    │
│                          │  which layer zones are needed │
├──────────────────────────┼───────────────────────────────┤
│  5. Molecular Engine     │  Loads only required cells    │
│                          │  via selective mmap           │
├──────────────────────────┼───────────────────────────────┤
│  6. AMFEngine Inference  │  Forward pass on active       │
│                          │  weight subset (NumPy)        │
└──────────────────────────┴───────────────────────────────┘

Layer Zones

Zone Layers Specialisation
Linguistic 0 – 7 Grammar, syntax, tokens
Semantic 8 – 15 Meaning, context
Reasoning 16–23 Logic, math, code

DNA Tag Format

A  -  L  -  003  -  Q
│     │      │      └─ Component  (Q/K/V/O/Gate/Up/Down/Norm)
│     │      └──────── Layer index (zero-padded)
│     └─────────────── Zone       (L=Linguistic / S=Semantic / R=Reasoning)
└───────────────────── Type       (A=Attention / F=FFN / C=Core)

AMFEngine API

from engine.amf_engine import AMFEngine

eng = AMFEngine("model.gguf", inference_layer=20)
eng.load()

eng.predict("Hello")          # → str
eng.generate("Hello", n=5)   # → str
eng.set_layer(16)             # switch inference layer
eng.list_layers()             # → [0, 1, ..., 23]
eng.info()                    # → dict
eng.close()

Supported quantisation formats

Format Status
F32 ✅ Full
F16 ✅ Full
Q8_0 ✅ Full
Q4_K_M ✅ Approximate
Q4_0 ✅ Approximate

Benchmark

Model Full RAM AMF RAM Reduction
Qwen2.5-0.5B ~400 MB ~80 MB
Qwen2.5-7B (Q4) ~4.5 GB ~500 MB
Qwen2.5-32B (Q4) ~20 GB ~500 MB 40×

CPU-only. No GPU required.


Supported Models

Model Family Format Status
Qwen 2.5 (all sizes) GGUF ✅ Tested
Qwen 3 / 3.5 GGUF ✅ Compatible
LLaMA 3 GGUF ✅ Compatible
Mistral GGUF ✅ Compatible
HuggingFace models Safetensors 🔄 Beta

Contributing

git clone https://github.com/jadcrypto/amf-core.git
cd amf-core
pip install -e .[dev]
pytest tests/

License

MIT — see LICENSE.


Citation

@software{amf_core,
  title  = {AMF: Atomic Model Fragmentation},
  author = {Jad},
  year   = {2026},
  url    = {https://github.com/jadcrypto/amf-core}
}

Built with ❤️ — First molecular inference engine from the Arab world

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

amf_core-0.2.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

amf_core-0.2.0-py3-none-any.whl (52.8 kB view details)

Uploaded Python 3

File details

Details for the file amf_core-0.2.0.tar.gz.

File metadata

  • Download URL: amf_core-0.2.0.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for amf_core-0.2.0.tar.gz
Algorithm Hash digest
SHA256 10a38bb9d4cc2959d0ea395d5514e1b8008d2025c967848982c9e2c9ee350f55
MD5 2a3a62197c3198d7692d9559de3df84c
BLAKE2b-256 c1ab2d988e25ddbc4db1fb41459f2e4072dde57d37902a37cda218880b6c2345

See more details on using hashes here.

File details

Details for the file amf_core-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: amf_core-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 52.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for amf_core-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e45e3866bca461795bf84704ae2654ecf13da053ab5df6e681319ae537f1ed1
MD5 2c92c96705393e17f5e7373afe45dfcc
BLAKE2b-256 fb27ac0aa642a49fd7ed727e158ffd5db1672274fe41387aaac2364d682f2431

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page