Instructions to use shibatch/tinyllama4gpt2m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinyllama4gpt2m with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinyllama4gpt2m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +25 -21
- hf/config.json +6 -1
- hf/model.safetensors +1 -1
- hf/tokenizer.json +0 -0
README.md
CHANGED
|
@@ -12,13 +12,14 @@ tags:
|
|
| 12 |
|
| 13 |
# TinyModel Mixtral 2M Top-3 MoE (tinyllama4gpt2m) HF Validation Suite
|
| 14 |
|
| 15 |
-
This repository provides an ultra-lightweight
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
|
| 23 |
---
|
| 24 |
|
|
@@ -28,19 +29,21 @@ It remains highly optimized for debugging sparse Mixture-of-Experts (MoE) featur
|
|
| 28 |
Unquantized components formatted for direct instantiation inside the PyTorch `transformers` library ecosystem or compatible proprietary model parsers:
|
| 29 |
|
| 30 |
* **`hf/model.safetensors`**: Raw unquantized matrix parameters containing all 5 expert sub-networks alongside the master router tensor (Gate) and GQA projection layers.
|
| 31 |
-
* **`hf/config.json`**: Architectural specifications built around `MixtralConfig` criteria, explicitly enforcing `num_attention_heads: 4`, `num_key_value_heads: 2`,
|
| 32 |
* **`hf/generation_config.json`**: Standard generation defaults for greedy search boundaries.
|
| 33 |
-
* **`hf/tokenizer.json`**: The core Byte-level BPE tokenizer layout containing vocabulary indices, pre-tokenization rules, and the merges map.
|
| 34 |
* **`hf/tokenizer.model`**: A structural dummy file provided exclusively to maintain complete Llama/Mixtral asset footprint compatibility with legacy reference loaders.
|
| 35 |
* **`hf/tokenizer_config.json`**: Metadata managing tokenization classes to guarantee correct handling of prefix spacing and automatic `<s>` (BOS) injection properly on the execution backend.
|
| 36 |
|
| 37 |
---
|
| 38 |
|
| 39 |
-
##
|
| 40 |
|
| 41 |
This checkpoint is engineered strictly as a deterministic validation test asset for computing platforms and custom inference environments.
|
| 42 |
|
| 43 |
Due to the compact vocabulary layout (4,000 tokens) and highly localized layer structure, it provides an ideal environment to isolate and profile specific compute structures:
|
|
|
|
|
|
|
| 44 |
* **GQA Routing & Index Mapping**: Verifying the group indexing logic where 4 query heads resolve to 2 distinct key/value head pairs, exposing stride offsets and boundary errors in attention loops.
|
| 45 |
* **Dynamic Routing Isolation**: Validating Top-3 gating allocation vectors and tracking row-index distribution matrices inside custom execution topologies.
|
| 46 |
* **Scatter/Gather Verification**: Profiling the memory dispatch loops that split token matrices into independent expert segments and synthesize them back into the main residual stream.
|
|
@@ -48,35 +51,37 @@ Due to the compact vocabulary layout (4,000 tokens) and highly localized layer s
|
|
| 48 |
|
| 49 |
---
|
| 50 |
|
| 51 |
-
##
|
| 52 |
|
| 53 |
### Loading Hugging Face Formats via Python
|
| 54 |
|
| 55 |
-
Because the configuration parameters are seamlessly matched with the standard Transformers schema, you can invoke the classes using automated loaders by pointing directly to the
|
| 56 |
|
| 57 |
```python
|
| 58 |
import torch
|
| 59 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
|
|
|
| 63 |
|
| 64 |
-
print("Loading MoE GQA configuration and tokenizer layers...")
|
| 65 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
| 66 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 67 |
|
| 68 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 69 |
model = model.to(device)
|
| 70 |
model.eval()
|
| 71 |
|
| 72 |
prompt = "Once upon"
|
|
|
|
| 73 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 74 |
|
| 75 |
-
print("Running inference loop (Validating Top-3
|
| 76 |
with torch.no_grad():
|
| 77 |
outputs = model.generate(
|
| 78 |
**inputs,
|
| 79 |
-
max_new_tokens=
|
| 80 |
do_sample=False
|
| 81 |
)
|
| 82 |
|
|
@@ -90,22 +95,21 @@ print("Generated:", generated_text)
|
|
| 90 |
|
| 91 |
---
|
| 92 |
|
| 93 |
-
##
|
| 94 |
|
| 95 |
* **Architecture:** Mixtral (`MixtralForCausalLM`)
|
| 96 |
* **Dataset:** Language Modeling Corpora
|
| 97 |
* **Total Parameters (`num_local_experts` = 5):** 2M class footprint
|
| 98 |
* **Active Parameters (`num_experts_per_tok` = 3):** 1.18M active during dispatch
|
| 99 |
-
* **Vocabulary Size (`vocab_size`):** 4,000 (Byte-level BPE with
|
| 100 |
* **Hidden Size (`hidden_size`):** 96
|
| 101 |
* **Number of Hidden Layers (`num_hidden_layers`):** 2
|
| 102 |
* **Number of Attention Heads (`num_heads` / `num_kv_heads`):** 4 / 2 *(Grouped-Query Attention layout)*
|
| 103 |
* **Individual Expert Internal Dimension (`intermediate_size`):** 192 *(SwiGLU structure)*
|
| 104 |
* **Max Position Embeddings (`max_position_embeddings`):** 1,024
|
|
|
|
| 105 |
* **RMS Norm Epsilon (`rms_norm_eps`):** 1e-5
|
| 106 |
|
| 107 |
-
##
|
| 108 |
|
| 109 |
* **License:** **MIT License**. You are completely free to duplicate, modify, distribute, and utilize these assets across any commercial, personal, or educational environments.
|
| 110 |
-
|
| 111 |
-
```
|
|
|
|
| 12 |
|
| 13 |
# TinyModel Mixtral 2M Top-3 MoE (tinyllama4gpt2m) HF Validation Suite
|
| 14 |
|
| 15 |
+
This repository provides an ultra-lightweight **Llama 4 format model variant** scaled down to a 2M class total parameter footprint, explicitly utilizing a **GPT-style tokenizer**.
|
| 16 |
|
| 17 |
+
### π― Primary Validation Objective: GPT-Style Tokenizer Verification (Core Purpose)
|
| 18 |
+
The foundational purpose of this entire suite is to isolate and verify the exact mathematical and structural behavior of a **GPT-style Byte-level BPE Tokenizer** (configured with `add_prefix_space=True`). Testing tokenizer compliance on large models introduces unnecessary complexity. This 2M parameter configuration allows developers to ensure their text-to-token transformation, token-to-text decoding, and prefix-space fusion rules perfectly match the reference implementation, with immediate visibility into alignment results.
|
| 19 |
|
| 20 |
+
**If your custom inference backend handles prefix spaces, boundary word fusions, or byte-level fallbacks incorrectly, the token IDs emitted here will immediately drift from the PyTorch reference baseline, isolating tokenization anomalies before tensor computations even begin.**
|
| 21 |
|
| 22 |
+
In addition to tokenizer verification, this asset is calibrated to a 1,024 token context window utilizing **Llama 3 RoPE Scaling** (4.0x factor over a 256 base window), providing a comprehensive test bed for both text processing and advanced position embedding calculations.
|
| 23 |
|
| 24 |
---
|
| 25 |
|
|
|
|
| 29 |
Unquantized components formatted for direct instantiation inside the PyTorch `transformers` library ecosystem or compatible proprietary model parsers:
|
| 30 |
|
| 31 |
* **`hf/model.safetensors`**: Raw unquantized matrix parameters containing all 5 expert sub-networks alongside the master router tensor (Gate) and GQA projection layers.
|
| 32 |
+
* **`hf/config.json`**: Architectural specifications built around `MixtralConfig` criteria, explicitly enforcing `num_attention_heads: 4`, `num_key_value_heads: 2`, `max_position_embeddings: 1024`, and the `llama3` type `rope_scaling` parameters.
|
| 33 |
* **`hf/generation_config.json`**: Standard generation defaults for greedy search boundaries.
|
| 34 |
+
* **`hf/tokenizer.json`**: The core Byte-level BPE tokenizer layout (configured with GPT-style `add_prefix_space=True`) containing vocabulary indices, pre-tokenization rules, and the merges map.
|
| 35 |
* **`hf/tokenizer.model`**: A structural dummy file provided exclusively to maintain complete Llama/Mixtral asset footprint compatibility with legacy reference loaders.
|
| 36 |
* **`hf/tokenizer_config.json`**: Metadata managing tokenization classes to guarantee correct handling of prefix spacing and automatic `<s>` (BOS) injection properly on the execution backend.
|
| 37 |
|
| 38 |
---
|
| 39 |
|
| 40 |
+
## π Purpose & Design Philosophy (Verification Targets)
|
| 41 |
|
| 42 |
This checkpoint is engineered strictly as a deterministic validation test asset for computing platforms and custom inference environments.
|
| 43 |
|
| 44 |
Due to the compact vocabulary layout (4,000 tokens) and highly localized layer structure, it provides an ideal environment to isolate and profile specific compute structures:
|
| 45 |
+
* **GPT-Style Tokenization Mechanics**: Validates that the word-boundary space management (`add_prefix_space=True`) and byte-level fallback merging match the GPT-2/Llama ecosystem exactly. This isolates subtokens layout anomalies before text data interacts with embedding layers.
|
| 46 |
+
* **Llama 3 RoPE Scaling Verification**: Validating multi-band frequency adjustments (`factor=4.0`, `low_freq_factor=1.0`, `high_freq_factor=4.0`, `original_max_position_embeddings=256`). This verifies whether the custom inference engine correctly bifurcates dimensions into high, medium, and low frequency bands and scales them accurately across an expanded 1,024-token sequence.
|
| 47 |
* **GQA Routing & Index Mapping**: Verifying the group indexing logic where 4 query heads resolve to 2 distinct key/value head pairs, exposing stride offsets and boundary errors in attention loops.
|
| 48 |
* **Dynamic Routing Isolation**: Validating Top-3 gating allocation vectors and tracking row-index distribution matrices inside custom execution topologies.
|
| 49 |
* **Scatter/Gather Verification**: Profiling the memory dispatch loops that split token matrices into independent expert segments and synthesize them back into the main residual stream.
|
|
|
|
| 51 |
|
| 52 |
---
|
| 53 |
|
| 54 |
+
## π Usage Examples
|
| 55 |
|
| 56 |
### Loading Hugging Face Formats via Python
|
| 57 |
|
| 58 |
+
Because the configuration parameters are seamlessly matched with the standard Transformers schema, you can invoke the classes using automated loaders by pointing directly to the Hugging Face repository and subfolder.
|
| 59 |
|
| 60 |
```python
|
| 61 |
import torch
|
| 62 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 63 |
|
| 64 |
+
# Target repository and subfolder configuration
|
| 65 |
+
repo_id = "shibatch/tinyllama4gpt2m"
|
| 66 |
+
subfolder = "hf"
|
| 67 |
|
| 68 |
+
print("Loading MoE GQA configuration and GPT-style tokenizer layers from Hugging Face...")
|
| 69 |
+
tokenizer = AutoTokenizer.from_pretrained(repo_id, subfolder=subfolder)
|
| 70 |
+
model = AutoModelForCausalLM.from_pretrained(repo_id, subfolder=subfolder)
|
| 71 |
|
| 72 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 73 |
model = model.to(device)
|
| 74 |
model.eval()
|
| 75 |
|
| 76 |
prompt = "Once upon"
|
| 77 |
+
# Tokenize using the loaded GPT-style configuration
|
| 78 |
inputs = tokenizer(prompt, return_tensors="pt").to(device)
|
| 79 |
|
| 80 |
+
print("Running inference loop (Validating GPT-style Tokenizer, Top-3 routing, GQA, and Llama3 RoPE Scaling)...")
|
| 81 |
with torch.no_grad():
|
| 82 |
outputs = model.generate(
|
| 83 |
**inputs,
|
| 84 |
+
max_new_tokens=100,
|
| 85 |
do_sample=False
|
| 86 |
)
|
| 87 |
|
|
|
|
| 95 |
|
| 96 |
---
|
| 97 |
|
| 98 |
+
## π Model Specifications
|
| 99 |
|
| 100 |
* **Architecture:** Mixtral (`MixtralForCausalLM`)
|
| 101 |
* **Dataset:** Language Modeling Corpora
|
| 102 |
* **Total Parameters (`num_local_experts` = 5):** 2M class footprint
|
| 103 |
* **Active Parameters (`num_experts_per_tok` = 3):** 1.18M active during dispatch
|
| 104 |
+
* **Vocabulary Size (`vocab_size`):** 4,000 (Byte-level BPE with strict GPT-style `add_prefix_space=True` configuration)
|
| 105 |
* **Hidden Size (`hidden_size`):** 96
|
| 106 |
* **Number of Hidden Layers (`num_hidden_layers`):** 2
|
| 107 |
* **Number of Attention Heads (`num_heads` / `num_kv_heads`):** 4 / 2 *(Grouped-Query Attention layout)*
|
| 108 |
* **Individual Expert Internal Dimension (`intermediate_size`):** 192 *(SwiGLU structure)*
|
| 109 |
* **Max Position Embeddings (`max_position_embeddings`):** 1,024
|
| 110 |
+
* **RoPE Scaling (`rope_scaling`):** `{"type": "llama3", "factor": 4.0, "low_freq_factor": 1.0, "high_freq_factor": 4.0, "original_max_position_embeddings": 256}`
|
| 111 |
* **RMS Norm Epsilon (`rms_norm_eps`):** 1e-5
|
| 112 |
|
| 113 |
+
## π License
|
| 114 |
|
| 115 |
* **License:** **MIT License**. You are completely free to duplicate, modify, distribute, and utilize these assets across any commercial, personal, or educational environments.
|
|
|
|
|
|
hf/config.json
CHANGED
|
@@ -22,8 +22,13 @@
|
|
| 22 |
"pad_token_id": 2,
|
| 23 |
"rms_norm_eps": 1e-05,
|
| 24 |
"rope_parameters": {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
"rope_theta": 1000000.0,
|
| 26 |
-
"rope_type": "
|
|
|
|
| 27 |
},
|
| 28 |
"router_aux_loss_coef": 0.001,
|
| 29 |
"router_jitter_noise": 0.0,
|
|
|
|
| 22 |
"pad_token_id": 2,
|
| 23 |
"rms_norm_eps": 1e-05,
|
| 24 |
"rope_parameters": {
|
| 25 |
+
"factor": 4.0,
|
| 26 |
+
"high_freq_factor": 4.0,
|
| 27 |
+
"low_freq_factor": 1.0,
|
| 28 |
+
"original_max_position_embeddings": 256,
|
| 29 |
"rope_theta": 1000000.0,
|
| 30 |
+
"rope_type": "llama3",
|
| 31 |
+
"type": "llama3"
|
| 32 |
},
|
| 33 |
"router_aux_loss_coef": 0.001,
|
| 34 |
"router_jitter_noise": 0.0,
|
hf/model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 5516176
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1c9ffa9b6fb878519124dd655bc1dc344516e494d29c462b3d3a52e76eda2bb
|
| 3 |
size 5516176
|
hf/tokenizer.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|