Upload folder using huggingface_hub
Browse files- README.md +49 -0
- __init__.py +39 -0
- chat_template.jinja +4 -0
- config.json +44 -0
- config.py +94 -0
- generation_config.json +10 -0
- manifests/dataset_lineage.jsonl +96 -0
- manifests/training_metrics.jsonl +0 -0
- modeling.py +666 -0
- multimodal.py +383 -0
- tokenizer.json +0 -0
- tokenizer_config.json +28 -0
- training_state.json +9 -0
- training_state.pt +3 -0
README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
- ko
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
tags:
|
| 7 |
+
- jerboa
|
| 8 |
+
- pytorch
|
| 9 |
+
- causal-lm
|
| 10 |
+
- edge-ai
|
| 11 |
+
- apple-silicon
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# Jerboa
|
| 16 |
+
|
| 17 |
+
**Lightweight Language & Multimodal Model** (in active development)
|
| 18 |
+
|
| 19 |
+
Jerboa is an ultra-lightweight language and multimodal model (~138M–146M parameters) optimized for Apple Silicon (MPS / Metal) and edge deployments.
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
## Model Specifications
|
| 24 |
+
|
| 25 |
+
| Attribute | Specification |
|
| 26 |
+
| :--- | :--- |
|
| 27 |
+
| **Language Backbone** | `JerboaForCausalLM` (~138.4M base / ~145.9M with MTP) |
|
| 28 |
+
| **Multimodal Model** | `JerboaVLForConditionalGeneration` (~145.2M) |
|
| 29 |
+
| **Layers & Hidden Dim** | 16 Layers, $d_{model}=768$, $d_{ffn}=2048$ (SwiGLU) |
|
| 30 |
+
| **Attention** | GQA (12 Query : 4 KV heads), QK-Norm, Interleaved SWA |
|
| 31 |
+
| **Context Length** | 4,096 tokens (extensible to 16K via YaRN) |
|
| 32 |
+
| **Hardware Target** | Apple Silicon (MPS / Metal) & Edge Devices |
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
+
|
| 36 |
+
## Quickstart
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 40 |
+
|
| 41 |
+
model_id = "ztor2/jerboa-base"
|
| 42 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 43 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
| 44 |
+
|
| 45 |
+
prompt = "Hello, what are you?"
|
| 46 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 47 |
+
outputs = model.generate(**inputs, max_new_tokens=128)
|
| 48 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 49 |
+
```
|
__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jerboa Model Package."""
|
| 2 |
+
|
| 3 |
+
from .config import JerboaConfig
|
| 4 |
+
from .modeling import (
|
| 5 |
+
JerboaAttention,
|
| 6 |
+
JerboaDecoderLayer,
|
| 7 |
+
JerboaForCausalLM,
|
| 8 |
+
JerboaMLP,
|
| 9 |
+
JerboaModel,
|
| 10 |
+
JerboaPreTrainedModel,
|
| 11 |
+
JerboaRMSNorm,
|
| 12 |
+
)
|
| 13 |
+
from .multimodal import (
|
| 14 |
+
AudioProjector,
|
| 15 |
+
EmbeddingGemmaVisionEncoder,
|
| 16 |
+
JerboaVLForConditionalGeneration,
|
| 17 |
+
LightweightAudioEncoder,
|
| 18 |
+
LightweightVisionEncoder,
|
| 19 |
+
VisionProjector,
|
| 20 |
+
)
|
| 21 |
+
from .tokenizer import build_bpe_tokenizer, get_default_tokenizer
|
| 22 |
+
|
| 23 |
+
__all__ = [
|
| 24 |
+
"JerboaConfig",
|
| 25 |
+
"JerboaPreTrainedModel",
|
| 26 |
+
"JerboaModel",
|
| 27 |
+
"JerboaForCausalLM",
|
| 28 |
+
"JerboaRMSNorm",
|
| 29 |
+
"JerboaAttention",
|
| 30 |
+
"JerboaMLP",
|
| 31 |
+
"JerboaDecoderLayer",
|
| 32 |
+
"JerboaVLForConditionalGeneration",
|
| 33 |
+
"LightweightVisionEncoder",
|
| 34 |
+
"LightweightAudioEncoder",
|
| 35 |
+
"VisionProjector",
|
| 36 |
+
"AudioProjector",
|
| 37 |
+
"build_bpe_tokenizer",
|
| 38 |
+
"get_default_tokenizer",
|
| 39 |
+
]
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% for message in messages %}{{'<|im_start|>' + message['role'] + '
|
| 2 |
+
' + message['content'] + '<|im_end|>' + '
|
| 3 |
+
'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
|
| 4 |
+
' }}{% endif %}
|
config.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"JerboaForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_dropout": 0.0,
|
| 6 |
+
"audio_hidden_size": 512,
|
| 7 |
+
"audio_token_id": 32001,
|
| 8 |
+
"bos_token_id": 1,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"enable_mtp": true,
|
| 11 |
+
"eos_token_id": 2,
|
| 12 |
+
"global_layer_interval": 4,
|
| 13 |
+
"hidden_act": "silu",
|
| 14 |
+
"hidden_size": 768,
|
| 15 |
+
"image_token_id": 32000,
|
| 16 |
+
"initializer_range": 0.02,
|
| 17 |
+
"intermediate_size": 2048,
|
| 18 |
+
"max_position_embeddings": 4096,
|
| 19 |
+
"model_type": "jerboa",
|
| 20 |
+
"mtp_loss_factor": 0.3,
|
| 21 |
+
"num_attention_heads": 12,
|
| 22 |
+
"num_hidden_layers": 16,
|
| 23 |
+
"num_key_value_heads": 4,
|
| 24 |
+
"pad_token_id": 0,
|
| 25 |
+
"qk_norm": true,
|
| 26 |
+
"rms_norm_eps": 1e-06,
|
| 27 |
+
"rope_parameters": {
|
| 28 |
+
"rope_theta": 100000.0,
|
| 29 |
+
"rope_type": "default"
|
| 30 |
+
},
|
| 31 |
+
"rope_theta": 100000.0,
|
| 32 |
+
"sliding_window": 2048,
|
| 33 |
+
"tie_word_embeddings": true,
|
| 34 |
+
"transformers_version": "5.17.0",
|
| 35 |
+
"use_cache": true,
|
| 36 |
+
"use_mtp": false,
|
| 37 |
+
"vision_hidden_size": 768,
|
| 38 |
+
"vision_spatial_merge_size": 2,
|
| 39 |
+
"vocab_size": 49155,
|
| 40 |
+
"auto_map": {
|
| 41 |
+
"AutoConfig": "config.JerboaConfig",
|
| 42 |
+
"AutoModelForCausalLM": "modeling.JerboaForCausalLM"
|
| 43 |
+
}
|
| 44 |
+
}
|
config.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jerboa Model Configuration compatible with Hugging Face PretrainedConfig."""
|
| 2 |
+
|
| 3 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class JerboaConfig(PretrainedConfig):
|
| 7 |
+
"""Configuration class to store the configuration of a `JerboaModel`.
|
| 8 |
+
|
| 9 |
+
Default parameters target approximately ~125M-140M parameters:
|
| 10 |
+
- 16 layers, 768 hidden size, 2048 intermediate size (SwiGLU)
|
| 11 |
+
- 12 query heads, 4 KV heads (GQA 3:1)
|
| 12 |
+
- Tied word embeddings (vocab_size=32768) saving ~25M params for deeper layers
|
| 13 |
+
- QK-Norm enabled for numerical stability
|
| 14 |
+
- RoPE base 100,000 for long-context scalability
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
model_type = "jerboa"
|
| 18 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 19 |
+
auto_map = {
|
| 20 |
+
"AutoConfig": "config.JerboaConfig",
|
| 21 |
+
"AutoModelForCausalLM": "modeling.JerboaForCausalLM",
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
def __init__(
|
| 25 |
+
self,
|
| 26 |
+
vocab_size: int = 32768,
|
| 27 |
+
hidden_size: int = 768,
|
| 28 |
+
intermediate_size: int = 2048,
|
| 29 |
+
num_hidden_layers: int = 16,
|
| 30 |
+
num_attention_heads: int = 12,
|
| 31 |
+
num_key_value_heads: int = 4,
|
| 32 |
+
hidden_act: str = "silu",
|
| 33 |
+
max_position_embeddings: int = 4096,
|
| 34 |
+
initializer_range: float = 0.02,
|
| 35 |
+
rms_norm_eps: float = 1e-6,
|
| 36 |
+
use_cache: bool = True,
|
| 37 |
+
pad_token_id: int = 0,
|
| 38 |
+
bos_token_id: int = 1,
|
| 39 |
+
eos_token_id: int = 2,
|
| 40 |
+
tie_word_embeddings: bool = True,
|
| 41 |
+
rope_theta: float = 100000.0,
|
| 42 |
+
rope_scaling: dict | None = None,
|
| 43 |
+
qk_norm: bool = True,
|
| 44 |
+
attention_dropout: float = 0.0,
|
| 45 |
+
# Modern Attention & Long-context (Interleaved SWA)
|
| 46 |
+
sliding_window: int | None = 2048,
|
| 47 |
+
global_layer_interval: int = 4,
|
| 48 |
+
# Multi-Token Prediction (MTP)
|
| 49 |
+
enable_mtp: bool = True,
|
| 50 |
+
use_mtp: bool = False,
|
| 51 |
+
mtp_loss_factor: float = 0.3,
|
| 52 |
+
# Multimodal parameters
|
| 53 |
+
vision_hidden_size: int = 768,
|
| 54 |
+
audio_hidden_size: int = 512,
|
| 55 |
+
image_token_id: int = 32000,
|
| 56 |
+
audio_token_id: int = 32001,
|
| 57 |
+
vision_spatial_merge_size: int = 2,
|
| 58 |
+
**kwargs,
|
| 59 |
+
):
|
| 60 |
+
self.vocab_size = vocab_size
|
| 61 |
+
self.hidden_size = hidden_size
|
| 62 |
+
self.intermediate_size = intermediate_size
|
| 63 |
+
self.num_hidden_layers = num_hidden_layers
|
| 64 |
+
self.num_attention_heads = num_attention_heads
|
| 65 |
+
self.num_key_value_heads = num_key_value_heads
|
| 66 |
+
self.hidden_act = hidden_act
|
| 67 |
+
self.max_position_embeddings = max_position_embeddings
|
| 68 |
+
self.initializer_range = initializer_range
|
| 69 |
+
self.rms_norm_eps = rms_norm_eps
|
| 70 |
+
self.use_cache = use_cache
|
| 71 |
+
self.rope_theta = rope_theta
|
| 72 |
+
self.rope_scaling = rope_scaling
|
| 73 |
+
self.qk_norm = qk_norm
|
| 74 |
+
self.attention_dropout = attention_dropout
|
| 75 |
+
self.sliding_window = sliding_window
|
| 76 |
+
self.global_layer_interval = global_layer_interval
|
| 77 |
+
self.enable_mtp = enable_mtp
|
| 78 |
+
self.use_mtp = use_mtp
|
| 79 |
+
self.mtp_loss_factor = mtp_loss_factor
|
| 80 |
+
|
| 81 |
+
# Multimodal
|
| 82 |
+
self.vision_hidden_size = vision_hidden_size
|
| 83 |
+
self.audio_hidden_size = audio_hidden_size
|
| 84 |
+
self.image_token_id = image_token_id
|
| 85 |
+
self.audio_token_id = audio_token_id
|
| 86 |
+
self.vision_spatial_merge_size = vision_spatial_merge_size
|
| 87 |
+
|
| 88 |
+
super().__init__(
|
| 89 |
+
pad_token_id=pad_token_id,
|
| 90 |
+
bos_token_id=bos_token_id,
|
| 91 |
+
eos_token_id=eos_token_id,
|
| 92 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 93 |
+
**kwargs,
|
| 94 |
+
)
|
generation_config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"output_attentions": false,
|
| 6 |
+
"output_hidden_states": false,
|
| 7 |
+
"pad_token_id": 0,
|
| 8 |
+
"transformers_version": "5.17.0",
|
| 9 |
+
"use_cache": true
|
| 10 |
+
}
|
manifests/dataset_lineage.jsonl
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"timestamp": "2026-09-29 16:12:55", "chunk_id": "chunk_0001", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "0..200", "doc_count": 200, "tokens_in_chunk": 167570, "cumulative_tokens": 167570, "sha256_hash": "887e25b343c312348f72ded89e1313514e0104ed87fb56c401eb39fb80ca19ff", "initial_loss": 11.0104, "final_loss": 10.9208, "checkpoint_saved": "checkpoints/rolling_pretrain/ckpt_chunk_0001", "status": "raw_data_deleted"}
|
| 2 |
+
{"timestamp": "2026-09-29 16:13:04", "chunk_id": "chunk_0002", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "200..400", "doc_count": 200, "tokens_in_chunk": 199939, "cumulative_tokens": 367509, "sha256_hash": "374067d275138c89bca9361d91732f5045400c57134223704c93a7563d78bdcc", "initial_loss": 10.8919, "final_loss": 10.3713, "checkpoint_saved": "checkpoints/rolling_pretrain/ckpt_chunk_0002", "status": "raw_data_deleted"}
|
| 3 |
+
{"timestamp": "2026-09-29 16:46:09", "chunk_id": "chunk_0001", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "0..200", "doc_count": 200, "tokens_in_chunk": 167570, "cumulative_tokens": 167570, "sha256_hash": "887e25b343c312348f72ded89e1313514e0104ed87fb56c401eb39fb80ca19ff", "initial_loss": 10.9333, "final_loss": 11.0142, "checkpoint_saved": "checkpoints/pretrain/ckpt_chunk_0001", "status": "raw_data_deleted"}
|
| 4 |
+
{"timestamp": "2026-09-29 16:46:18", "chunk_id": "chunk_0002", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "200..400", "doc_count": 200, "tokens_in_chunk": 199939, "cumulative_tokens": 367509, "sha256_hash": "374067d275138c89bca9361d91732f5045400c57134223704c93a7563d78bdcc", "initial_loss": 10.7623, "final_loss": 10.4939, "checkpoint_saved": "checkpoints/pretrain/ckpt_chunk_0002", "status": "raw_data_deleted"}
|
| 5 |
+
{"timestamp": "2026-10-06 15:15:44", "chunk_id": "chunk_0003", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "400..1400", "doc_count": 1000, "tokens_in_chunk": 1126934, "cumulative_tokens": 1494443, "sha256_hash": "0fab70f0915f06910d8e0c5576c2317fa8c87a46eaf4feabca22ba7664c5770f", "initial_loss": 13.3211, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0003", "status": "raw_data_deleted"}
|
| 6 |
+
{"timestamp": "2026-10-06 15:22:00", "chunk_id": "chunk_0004", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "1400..2400", "doc_count": 1000, "tokens_in_chunk": 1054088, "cumulative_tokens": 2548531, "sha256_hash": "4befe2580fc2f82f73dbdd7334f2b48b4ae94ea6552f4f9e1bc1aa35213719d2", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0004", "status": "raw_data_deleted"}
|
| 7 |
+
{"timestamp": "2026-10-06 15:28:10", "chunk_id": "chunk_0005", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "2400..3400", "doc_count": 1000, "tokens_in_chunk": 1022347, "cumulative_tokens": 3570878, "sha256_hash": "3e04676d8b8e7de382ddca4a29679826e10f0d0ba250cfa2718b38d695a11e54", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0005", "status": "raw_data_deleted"}
|
| 8 |
+
{"timestamp": "2026-10-06 15:34:20", "chunk_id": "chunk_0006", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "3400..4400", "doc_count": 1000, "tokens_in_chunk": 1024445, "cumulative_tokens": 4595323, "sha256_hash": "66ff3873c957ca046e2ffa5aa4b9862f55ce357cd692174b1ce9b6eac53d1262", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0006", "status": "raw_data_deleted"}
|
| 9 |
+
{"timestamp": "2026-10-06 15:40:52", "chunk_id": "chunk_0007", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "4400..5400", "doc_count": 1000, "tokens_in_chunk": 1086263, "cumulative_tokens": 5681586, "sha256_hash": "7ad7132e071d88c6419248a1dc0de7a6f7a70f3c6f211184c02683fa60d1081b", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0007", "status": "raw_data_deleted"}
|
| 10 |
+
{"timestamp": "2026-10-06 15:47:05", "chunk_id": "chunk_0008", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "5400..6400", "doc_count": 1000, "tokens_in_chunk": 1050915, "cumulative_tokens": 6732501, "sha256_hash": "19a43914642a902540de7ebf6cd21b62792cc5ff4f785ed671629ba3735e3391", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0008", "status": "raw_data_deleted"}
|
| 11 |
+
{"timestamp": "2026-10-06 15:52:51", "chunk_id": "chunk_0009", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "6400..7400", "doc_count": 1000, "tokens_in_chunk": 972371, "cumulative_tokens": 7704872, "sha256_hash": "fc5825ff2954d58b8a695e47eac22c2e35a6d838a04a3217388193e304b76de1", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0009", "status": "raw_data_deleted"}
|
| 12 |
+
{"timestamp": "2026-10-06 15:58:16", "chunk_id": "chunk_0010", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "7400..8400", "doc_count": 1000, "tokens_in_chunk": 911010, "cumulative_tokens": 8615882, "sha256_hash": "62331ec7421fcc19a3c468ce6a8ef98a0feaa3f274822ad4f014206b8853a905", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0010", "status": "raw_data_deleted"}
|
| 13 |
+
{"timestamp": "2026-10-06 16:04:36", "chunk_id": "chunk_0011", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "8400..9400", "doc_count": 1000, "tokens_in_chunk": 1059427, "cumulative_tokens": 9675309, "sha256_hash": "2d696334a07f1ca65b78f266a38036a613aa738d6e8f5e85e02dac1ae8f8404e", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0011", "status": "raw_data_deleted"}
|
| 14 |
+
{"timestamp": "2026-10-06 16:10:32", "chunk_id": "chunk_0012", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "9400..10400", "doc_count": 1000, "tokens_in_chunk": 997741, "cumulative_tokens": 10673050, "sha256_hash": "49a85c9c79526a04310ff09dafb09b387c6ef93d4e73a908945db5070ef3eb90", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0012", "status": "raw_data_deleted"}
|
| 15 |
+
{"timestamp": "2026-10-06 16:16:32", "chunk_id": "chunk_0013", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "10400..11400", "doc_count": 1000, "tokens_in_chunk": 1014924, "cumulative_tokens": 11687974, "sha256_hash": "fe6f234f93fdacebe0b809043ca8fe3d0b5a5fa6ced30d16d7d4313fdadbfb66", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0013", "status": "raw_data_deleted"}
|
| 16 |
+
{"timestamp": "2026-10-06 16:22:11", "chunk_id": "chunk_0014", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "11400..12400", "doc_count": 1000, "tokens_in_chunk": 944037, "cumulative_tokens": 12632011, "sha256_hash": "be438c8a0953ed659c1525cf07441ea2c72a150fa9d81c7c884f75a17fbec127", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0014", "status": "raw_data_deleted"}
|
| 17 |
+
{"timestamp": "2026-10-06 16:28:07", "chunk_id": "chunk_0015", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "12400..13400", "doc_count": 1000, "tokens_in_chunk": 997013, "cumulative_tokens": 13629024, "sha256_hash": "011ce9d1be1fd99845015980875b69fc73736e59f95d784d2fd684b0a7acaf0d", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0015", "status": "raw_data_deleted"}
|
| 18 |
+
{"timestamp": "2026-10-06 16:34:14", "chunk_id": "chunk_0016", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "13400..14400", "doc_count": 1000, "tokens_in_chunk": 1031501, "cumulative_tokens": 14660525, "sha256_hash": "f3f2f1f1ba89436a1bf6a68761f30e0c40a1db7981ec7c032142dea5251ec788", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0016", "status": "raw_data_deleted"}
|
| 19 |
+
{"timestamp": "2026-10-06 16:40:26", "chunk_id": "chunk_0017", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "14400..15400", "doc_count": 1000, "tokens_in_chunk": 1049092, "cumulative_tokens": 15709617, "sha256_hash": "a6b985914979c7de7325a665d9b31d484d7fa7cce72788a502714c54db8c2db4", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0017", "status": "raw_data_deleted"}
|
| 20 |
+
{"timestamp": "2026-10-06 16:46:45", "chunk_id": "chunk_0018", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "15400..16400", "doc_count": 1000, "tokens_in_chunk": 1053687, "cumulative_tokens": 16763304, "sha256_hash": "64579eece7cf93c4e7ba3572a084078e3250d5864b3fcd3fb86fec581aba2b01", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0018", "status": "raw_data_deleted"}
|
| 21 |
+
{"timestamp": "2026-10-06 16:53:08", "chunk_id": "chunk_0019", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "16400..17400", "doc_count": 1000, "tokens_in_chunk": 1058317, "cumulative_tokens": 17821621, "sha256_hash": "1ecdeda60884b4f32b637af6b6fbdfb3510ed7f1fc8926ef4abf383161ae7522", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0019", "status": "raw_data_deleted"}
|
| 22 |
+
{"timestamp": "2026-10-06 16:59:06", "chunk_id": "chunk_0020", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "17400..18400", "doc_count": 1000, "tokens_in_chunk": 997538, "cumulative_tokens": 18819159, "sha256_hash": "d62586a379dc7d1a8523cff4a0517ca2d7c201dd95e39a266a11a01a9366c75e", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0020", "status": "raw_data_deleted"}
|
| 23 |
+
{"timestamp": "2026-10-06 17:05:43", "chunk_id": "chunk_0021", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "18400..19400", "doc_count": 1000, "tokens_in_chunk": 1148681, "cumulative_tokens": 19967840, "sha256_hash": "77697657d12c88c25659f7ad4fd20af275471472f75a7efd60134d20a79710f9", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0021", "status": "raw_data_deleted"}
|
| 24 |
+
{"timestamp": "2026-10-06 17:13:06", "chunk_id": "chunk_0022", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "19400..20400", "doc_count": 1000, "tokens_in_chunk": 1262863, "cumulative_tokens": 21230703, "sha256_hash": "2382f58597ef8c3232231aa4593c78f74c0f2d459e1052fa9ff32a3aaed1ef5e", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0022", "status": "raw_data_deleted"}
|
| 25 |
+
{"timestamp": "2026-10-06 17:20:56", "chunk_id": "chunk_0023", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "20400..21400", "doc_count": 1000, "tokens_in_chunk": 1316911, "cumulative_tokens": 22547614, "sha256_hash": "14ba1d9d3e90ba189053fb0a11f15041781b97c55f6876ff0a401988c5b02675", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0023", "status": "raw_data_deleted"}
|
| 26 |
+
{"timestamp": "2026-10-06 17:28:14", "chunk_id": "chunk_0024", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "21400..22400", "doc_count": 1000, "tokens_in_chunk": 1244162, "cumulative_tokens": 23791776, "sha256_hash": "9cae98ffd4d9c7688bf4a5a881d313c0b2bb0bebdc5b7789a5832686a0433790", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0024", "status": "raw_data_deleted"}
|
| 27 |
+
{"timestamp": "2026-10-06 17:35:36", "chunk_id": "chunk_0025", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "22400..23400", "doc_count": 1000, "tokens_in_chunk": 1262756, "cumulative_tokens": 25054532, "sha256_hash": "f1b5336f92844848bed80556c82f0641415be0546c233422c097b92469bd4dfd", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0025", "status": "raw_data_deleted"}
|
| 28 |
+
{"timestamp": "2026-10-06 17:42:16", "chunk_id": "chunk_0026", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "23400..24400", "doc_count": 1000, "tokens_in_chunk": 1115759, "cumulative_tokens": 26170291, "sha256_hash": "74867933ccf2f2df5fc0cdff77a22ad3dbd194cc91761c426b4183584feb003c", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0026", "status": "raw_data_deleted"}
|
| 29 |
+
{"timestamp": "2026-10-06 17:49:06", "chunk_id": "chunk_0027", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "24400..25400", "doc_count": 1000, "tokens_in_chunk": 1136011, "cumulative_tokens": 27306302, "sha256_hash": "0bb59e019aff19a9b3230f510f764122a010573fc08cc7d432141a7ca5e85045", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0027", "status": "raw_data_deleted"}
|
| 30 |
+
{"timestamp": "2026-10-06 17:55:24", "chunk_id": "chunk_0028", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "25400..26400", "doc_count": 1000, "tokens_in_chunk": 1029926, "cumulative_tokens": 28336228, "sha256_hash": "90d0cca3d904809cfedeabe2a6d997e591fe43e6522240ad3098160043d5c088", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0028", "status": "raw_data_deleted"}
|
| 31 |
+
{"timestamp": "2026-10-06 18:02:16", "chunk_id": "chunk_0029", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "26400..27400", "doc_count": 1000, "tokens_in_chunk": 1084174, "cumulative_tokens": 29420402, "sha256_hash": "b1e8f150bc04abbbb8c714d9d25eeda0503e50e09d4a3443c1b02dcb23a5dc9a", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0029", "status": "raw_data_deleted"}
|
| 32 |
+
{"timestamp": "2026-10-06 18:09:08", "chunk_id": "chunk_0030", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "27400..28400", "doc_count": 1000, "tokens_in_chunk": 1105436, "cumulative_tokens": 30525838, "sha256_hash": "70df01b9b8c5a5145565ea52d5be86f469abfbc2d9d578612afa8ed027a1a5cc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0030", "status": "raw_data_deleted"}
|
| 33 |
+
{"timestamp": "2026-10-06 18:15:18", "chunk_id": "chunk_0031", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "28400..29400", "doc_count": 1000, "tokens_in_chunk": 995973, "cumulative_tokens": 31521811, "sha256_hash": "66299851cfe85e4a58836bfa980400e84aff57bef83fd408cad36c04212efeca", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0031", "status": "raw_data_deleted"}
|
| 34 |
+
{"timestamp": "2026-10-06 18:21:17", "chunk_id": "chunk_0032", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "29400..30400", "doc_count": 1000, "tokens_in_chunk": 982099, "cumulative_tokens": 32503910, "sha256_hash": "9b6d6c51935f5081a8474c0ce5a92deee734d0b43796d5412e9a2b4263cc8c2a", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0032", "status": "raw_data_deleted"}
|
| 35 |
+
{"timestamp": "2026-10-06 18:27:18", "chunk_id": "chunk_0033", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "30400..31400", "doc_count": 1000, "tokens_in_chunk": 974921, "cumulative_tokens": 33478831, "sha256_hash": "dc0a07919e30f0c9ef1ba82509463f702151708ca8faa55ec43513dbde6c94a6", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0033", "status": "raw_data_deleted"}
|
| 36 |
+
{"timestamp": "2026-10-06 18:32:51", "chunk_id": "chunk_0034", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "31400..32400", "doc_count": 1000, "tokens_in_chunk": 909729, "cumulative_tokens": 34388560, "sha256_hash": "173c47a050171d256cfe97d04652b53650d7abd7369a8606917642c0915456be", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0034", "status": "raw_data_deleted"}
|
| 37 |
+
{"timestamp": "2026-10-06 18:58:17", "chunk_id": "chunk_0035", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "33400..34400", "doc_count": 1000, "tokens_in_chunk": 958920, "cumulative_tokens": 37209686, "sha256_hash": "b11b796ed7cce697645dfcea889276a9ec2ca70ddea6be89d4edd8c782ccf3bd", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0035", "status": "raw_data_deleted"}
|
| 38 |
+
{"timestamp": "2026-10-06 19:04:42", "chunk_id": "chunk_0036", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "34400..35400", "doc_count": 1000, "tokens_in_chunk": 1007293, "cumulative_tokens": 38216979, "sha256_hash": "98cb02c99def9acb6043284a3f6914d0d3e7dda057d6f470cd31e2e8fa882cb7", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0036", "status": "raw_data_deleted"}
|
| 39 |
+
{"timestamp": "2026-10-06 19:10:45", "chunk_id": "chunk_0037", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "35400..36400", "doc_count": 1000, "tokens_in_chunk": 1027818, "cumulative_tokens": 39244797, "sha256_hash": "5ec156b7efd06e777f8f22853d115ab3278d1fedea96c0bdb835f58ad93df96a", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0037", "status": "raw_data_deleted"}
|
| 40 |
+
{"timestamp": "2026-10-06 19:16:26", "chunk_id": "chunk_0038", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "36400..37400", "doc_count": 1000, "tokens_in_chunk": 975633, "cumulative_tokens": 40220430, "sha256_hash": "da99d0915d3429c92f1398f8ed0ee392fb7f18bc9082626746b43bc3e7074fba", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0038", "status": "raw_data_deleted"}
|
| 41 |
+
{"timestamp": "2026-10-06 19:22:12", "chunk_id": "chunk_0039", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "37400..38400", "doc_count": 1000, "tokens_in_chunk": 984634, "cumulative_tokens": 41205064, "sha256_hash": "e6d06a906a90e55d8adf70d0be36ee67015d852e8e0405fe1a3127efff1d0949", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0039", "status": "raw_data_deleted"}
|
| 42 |
+
{"timestamp": "2026-10-06 19:27:53", "chunk_id": "chunk_0040", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "38400..39400", "doc_count": 1000, "tokens_in_chunk": 971397, "cumulative_tokens": 42176461, "sha256_hash": "2a51c429570cd1908277f63b171d180d9d5a0b63ccbf0f4807db3f1741ab8799", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0040", "status": "raw_data_deleted"}
|
| 43 |
+
{"timestamp": "2026-10-06 19:33:59", "chunk_id": "chunk_0041", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "39400..40400", "doc_count": 1000, "tokens_in_chunk": 1047340, "cumulative_tokens": 43223801, "sha256_hash": "1381dbee455402acda11a498ea81cf0089e5a6a31ed406e96175d05471fb433c", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0041", "status": "raw_data_deleted"}
|
| 44 |
+
{"timestamp": "2026-10-06 19:39:42", "chunk_id": "chunk_0042", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "40400..41400", "doc_count": 1000, "tokens_in_chunk": 974727, "cumulative_tokens": 44198528, "sha256_hash": "1292d42fc6bc03afffa6e5a8653c803f4642128e4017d376817a2dea8424c1bc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0042", "status": "raw_data_deleted"}
|
| 45 |
+
{"timestamp": "2026-10-06 19:46:18", "chunk_id": "chunk_0043", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "41400..42400", "doc_count": 1000, "tokens_in_chunk": 1134049, "cumulative_tokens": 45332577, "sha256_hash": "3121a994a4d080c05e8a63d5941cab251809a8ea79644bd51d2d402e82dadd38", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0043", "status": "raw_data_deleted"}
|
| 46 |
+
{"timestamp": "2026-10-06 19:52:41", "chunk_id": "chunk_0044", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "42400..43400", "doc_count": 1000, "tokens_in_chunk": 1119746, "cumulative_tokens": 46452323, "sha256_hash": "4172f217422683e59c436de1d1644ecac8aada5846b2b90e4bff5fdbd9d60a36", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0044", "status": "raw_data_deleted"}
|
| 47 |
+
{"timestamp": "2026-10-06 19:59:05", "chunk_id": "chunk_0045", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "43400..44400", "doc_count": 1000, "tokens_in_chunk": 1116176, "cumulative_tokens": 47568499, "sha256_hash": "97ef81501e8e151ff186019719a9fd446bdbd4c0e47dfe94e712f32690b83531", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0045", "status": "raw_data_deleted"}
|
| 48 |
+
{"timestamp": "2026-10-06 20:05:44", "chunk_id": "chunk_0046", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "44400..45400", "doc_count": 1000, "tokens_in_chunk": 1167264, "cumulative_tokens": 48735763, "sha256_hash": "9ad7a2fee1ffb3e12e301a781d2a809b18658a915ec866e8ffe08ebf1f374558", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0046", "status": "raw_data_deleted"}
|
| 49 |
+
{"timestamp": "2026-10-06 20:12:11", "chunk_id": "chunk_0047", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "45400..46400", "doc_count": 1000, "tokens_in_chunk": 1128102, "cumulative_tokens": 49863865, "sha256_hash": "7db71da791356c855b9289c908dbdcecb22bb03342345de121fbeb37a016602b", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0047", "status": "raw_data_deleted"}
|
| 50 |
+
{"timestamp": "2026-10-06 20:18:49", "chunk_id": "chunk_0048", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "46400..47400", "doc_count": 1000, "tokens_in_chunk": 1159605, "cumulative_tokens": 51023470, "sha256_hash": "2c6ec460b2a8b7854d181676799e129fc7afec16647d8c7c35db99be10c95013", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0048", "status": "raw_data_deleted"}
|
| 51 |
+
{"timestamp": "2026-10-06 20:24:43", "chunk_id": "chunk_0049", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "47400..48400", "doc_count": 1000, "tokens_in_chunk": 1002571, "cumulative_tokens": 52026041, "sha256_hash": "be808e4aa5543124ced75459bad1e37fc7f6e6bc160de005244c91846e7eff35", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0049", "status": "raw_data_deleted"}
|
| 52 |
+
{"timestamp": "2026-10-06 20:31:15", "chunk_id": "chunk_0050", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "48400..49400", "doc_count": 1000, "tokens_in_chunk": 1090227, "cumulative_tokens": 53116268, "sha256_hash": "b1d799ce0b1ed3e98e64cfa04576456d13e915b777eb371cb13ae33bea7c11db", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0050", "status": "raw_data_deleted"}
|
| 53 |
+
{"timestamp": "2026-10-06 20:37:52", "chunk_id": "chunk_0051", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "49400..50400", "doc_count": 1000, "tokens_in_chunk": 1112665, "cumulative_tokens": 54228933, "sha256_hash": "ec747a24bb66084539efb4791ade8a96c984a08b70cb1c098abd99c31ac1c35f", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0051", "status": "raw_data_deleted"}
|
| 54 |
+
{"timestamp": "2026-10-06 20:43:58", "chunk_id": "chunk_0052", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "50400..51400", "doc_count": 1000, "tokens_in_chunk": 1025152, "cumulative_tokens": 55254085, "sha256_hash": "242799781f37e796550cf1358a27783bbf6e01f93f205de927084ae6df0b2afe", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0052", "status": "raw_data_deleted"}
|
| 55 |
+
{"timestamp": "2026-10-06 20:50:13", "chunk_id": "chunk_0053", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "51400..52400", "doc_count": 1000, "tokens_in_chunk": 1047872, "cumulative_tokens": 56301957, "sha256_hash": "16a38e7744504dc8891a8ea38b80ed6f4a92b8f6fe70e5c4f01a3e515f4a17cc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0053", "status": "raw_data_deleted"}
|
| 56 |
+
{"timestamp": "2026-10-06 20:56:47", "chunk_id": "chunk_0054", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "52400..53400", "doc_count": 1000, "tokens_in_chunk": 1113570, "cumulative_tokens": 57415527, "sha256_hash": "200b42638ac97c9aa5e5bf81b7983a8faec4b774faca5409def569d134f9b0b2", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0054", "status": "raw_data_deleted"}
|
| 57 |
+
{"timestamp": "2026-10-06 21:02:54", "chunk_id": "chunk_0055", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "53400..54400", "doc_count": 1000, "tokens_in_chunk": 1037555, "cumulative_tokens": 58453082, "sha256_hash": "1854a9db6ea9c212f2e60133a277f348928d3936aa403781f32f405cc7137fcc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0055", "status": "raw_data_deleted"}
|
| 58 |
+
{"timestamp": "2026-10-06 21:08:51", "chunk_id": "chunk_0056", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "54400..55400", "doc_count": 1000, "tokens_in_chunk": 1003529, "cumulative_tokens": 59456611, "sha256_hash": "8d28216c2e054ff4b5697575a37f2cf2e5006a925f7dc5cc9627875ef97e0da8", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0056", "status": "raw_data_deleted"}
|
| 59 |
+
{"timestamp": "2026-10-06 21:14:44", "chunk_id": "chunk_0057", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "55400..56400", "doc_count": 1000, "tokens_in_chunk": 991459, "cumulative_tokens": 60448070, "sha256_hash": "e9fa98a89896c89412090709234e029c72ea912aca3fd99b6d4690f6fb284240", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0057", "status": "raw_data_deleted"}
|
| 60 |
+
{"timestamp": "2026-10-06 21:20:54", "chunk_id": "chunk_0058", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "56400..57400", "doc_count": 1000, "tokens_in_chunk": 1046464, "cumulative_tokens": 61494534, "sha256_hash": "e4b13b9dd3f11e58b0be97308d2e34b197201daf52d5498f8074c63f45b98f4c", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0058", "status": "raw_data_deleted"}
|
| 61 |
+
{"timestamp": "2026-10-06 21:27:08", "chunk_id": "chunk_0059", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "57400..58400", "doc_count": 1000, "tokens_in_chunk": 1056768, "cumulative_tokens": 62551302, "sha256_hash": "6b5353caeca500e32bb100cd0f685e59d0389a42c9b7e028e90b3c6349e28cfe", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0059", "status": "raw_data_deleted"}
|
| 62 |
+
{"timestamp": "2026-10-06 21:33:14", "chunk_id": "chunk_0060", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "58400..59400", "doc_count": 1000, "tokens_in_chunk": 1031420, "cumulative_tokens": 63582722, "sha256_hash": "9cd2db3cdb652e9a0a295e277be3d0fcb054a0ad1199df197a4c3b2c6a7ac35a", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0060", "status": "raw_data_deleted"}
|
| 63 |
+
{"timestamp": "2026-10-06 21:39:24", "chunk_id": "chunk_0061", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "59400..60400", "doc_count": 1000, "tokens_in_chunk": 1047537, "cumulative_tokens": 64630259, "sha256_hash": "84dd6a37b29ef1d21f6cd392ceb6fdaf8fe6dfb58bb4baa67705b9b5b5734ab6", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0061", "status": "raw_data_deleted"}
|
| 64 |
+
{"timestamp": "2026-10-06 21:45:33", "chunk_id": "chunk_0062", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "60400..61400", "doc_count": 1000, "tokens_in_chunk": 1044685, "cumulative_tokens": 65674944, "sha256_hash": "c6391c173e3ed26d0c3d8027d3df275f5053974da963fd3e422813814e036595", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0062", "status": "raw_data_deleted"}
|
| 65 |
+
{"timestamp": "2026-10-06 21:51:25", "chunk_id": "chunk_0063", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "61400..62400", "doc_count": 1000, "tokens_in_chunk": 993614, "cumulative_tokens": 66668558, "sha256_hash": "c263f553053a0753717447f8888cfe93425c2f771fb8d0d86bac69a4d1984753", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0063", "status": "raw_data_deleted"}
|
| 66 |
+
{"timestamp": "2026-10-06 21:57:27", "chunk_id": "chunk_0064", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "62400..63400", "doc_count": 1000, "tokens_in_chunk": 1013906, "cumulative_tokens": 67682464, "sha256_hash": "233fe4a4769fc4f04e3d4dbe17f36aa3f034ba69de663d275140dca7ee099cdb", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0064", "status": "raw_data_deleted"}
|
| 67 |
+
{"timestamp": "2026-10-06 22:03:18", "chunk_id": "chunk_0065", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "63400..64400", "doc_count": 1000, "tokens_in_chunk": 992485, "cumulative_tokens": 68674949, "sha256_hash": "ad4983bf937eba8a4fd865cd891bb5dbad9e80d69de2a57243cf27b2cf34fdbd", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0065", "status": "raw_data_deleted"}
|
| 68 |
+
{"timestamp": "2026-10-06 22:09:56", "chunk_id": "chunk_0066", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "64400..65400", "doc_count": 1000, "tokens_in_chunk": 1123063, "cumulative_tokens": 69798012, "sha256_hash": "56eaa9c4b41b154a6b98a04cfaaad84f473f5526ab734e3069a936d975b32564", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0066", "status": "raw_data_deleted"}
|
| 69 |
+
{"timestamp": "2026-10-06 22:15:48", "chunk_id": "chunk_0067", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "65400..66400", "doc_count": 1000, "tokens_in_chunk": 1007894, "cumulative_tokens": 70805906, "sha256_hash": "55b6ec227a985b8c7a39278407aa50dbcd4c7d0fe8283eee647c3c6d55417d14", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0067", "status": "raw_data_deleted"}
|
| 70 |
+
{"timestamp": "2026-10-06 22:22:40", "chunk_id": "chunk_0068", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "66400..67400", "doc_count": 1000, "tokens_in_chunk": 1183833, "cumulative_tokens": 71989739, "sha256_hash": "20e78cc7ad1b8660aefc08e31e4fe2f72a68fe744bb1e8d43b30e397b045df3d", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0068", "status": "raw_data_deleted"}
|
| 71 |
+
{"timestamp": "2026-10-06 22:29:11", "chunk_id": "chunk_0069", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "67400..68400", "doc_count": 1000, "tokens_in_chunk": 1127259, "cumulative_tokens": 73116998, "sha256_hash": "6dd704218b321d9c509832765337bc313e5fc73e665a46303b764644b3190f39", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0069", "status": "raw_data_deleted"}
|
| 72 |
+
{"timestamp": "2026-10-06 22:35:33", "chunk_id": "chunk_0070", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "68400..69400", "doc_count": 1000, "tokens_in_chunk": 1105349, "cumulative_tokens": 74222347, "sha256_hash": "16b4141c2a0dfdb0fac247e0c3f10129d1e421d72aeb43ba8a1fcef1b0e6d4eb", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0070", "status": "raw_data_deleted"}
|
| 73 |
+
{"timestamp": "2026-10-06 22:41:44", "chunk_id": "chunk_0071", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "69400..70400", "doc_count": 1000, "tokens_in_chunk": 1071660, "cumulative_tokens": 75294007, "sha256_hash": "3cf9f7578d31cba6f704c32fa116f9997053c375d21d663a9f920c6a666e8bfc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0071", "status": "raw_data_deleted"}
|
| 74 |
+
{"timestamp": "2026-10-06 22:48:32", "chunk_id": "chunk_0072", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "70400..71400", "doc_count": 1000, "tokens_in_chunk": 1177436, "cumulative_tokens": 76471443, "sha256_hash": "393a4380147ed38462641a0913da90e508c5cf43736d82bc81982bbc0b5bf75d", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0072", "status": "raw_data_deleted"}
|
| 75 |
+
{"timestamp": "2026-10-06 22:55:02", "chunk_id": "chunk_0073", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "71400..72400", "doc_count": 1000, "tokens_in_chunk": 1088214, "cumulative_tokens": 77559657, "sha256_hash": "60f961279c7476d40b05ec39c2939e57c13af0b195b61438cec5a21262b1965f", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0073", "status": "raw_data_deleted"}
|
| 76 |
+
{"timestamp": "2026-10-06 23:00:59", "chunk_id": "chunk_0074", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "72400..73400", "doc_count": 1000, "tokens_in_chunk": 989042, "cumulative_tokens": 78548699, "sha256_hash": "448cda8425ace3ae2cc82e303091b14da42dd8cdac4c0f00767d7ef448bf8bd4", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0074", "status": "raw_data_deleted"}
|
| 77 |
+
{"timestamp": "2026-10-06 23:07:02", "chunk_id": "chunk_0075", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "73400..74400", "doc_count": 1000, "tokens_in_chunk": 1004218, "cumulative_tokens": 79552917, "sha256_hash": "c07b9a07a4dea309108febe25322076e8bf45ca74b1e9f543c0f8905e8bbbf2b", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0075", "status": "raw_data_deleted"}
|
| 78 |
+
{"timestamp": "2026-10-06 23:13:40", "chunk_id": "chunk_0076", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "74400..75400", "doc_count": 1000, "tokens_in_chunk": 1112644, "cumulative_tokens": 80665561, "sha256_hash": "aa165d5b5e834698e7e94d56fe367a1f7dce10265029afa1fb3e7bbf2823360b", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0076", "status": "raw_data_deleted"}
|
| 79 |
+
{"timestamp": "2026-10-06 23:20:33", "chunk_id": "chunk_0077", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "75400..76400", "doc_count": 1000, "tokens_in_chunk": 1154215, "cumulative_tokens": 81819776, "sha256_hash": "0855742539248429ac2011f607510e75f5f44a5701e46cf145431a97a5e4c635", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0077", "status": "raw_data_deleted"}
|
| 80 |
+
{"timestamp": "2026-10-06 23:26:38", "chunk_id": "chunk_0078", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "76400..77400", "doc_count": 1000, "tokens_in_chunk": 1012692, "cumulative_tokens": 82832468, "sha256_hash": "5b8b3fb8b2de0c1072dec46f03fd661a444e5d0b58d2b388ee0acc971ddcca9d", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0078", "status": "raw_data_deleted"}
|
| 81 |
+
{"timestamp": "2026-10-06 23:33:10", "chunk_id": "chunk_0079", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "77400..78400", "doc_count": 1000, "tokens_in_chunk": 982556, "cumulative_tokens": 83815024, "sha256_hash": "03ada6b5beed608b35f3b49d9a969c4c36f765e10bd3f7538e6295b6d719298e", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0079", "status": "raw_data_deleted"}
|
| 82 |
+
{"timestamp": "2026-10-06 23:40:40", "chunk_id": "chunk_0080", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "78400..79400", "doc_count": 1000, "tokens_in_chunk": 1029424, "cumulative_tokens": 84844448, "sha256_hash": "e8dc7578aaa4c40ed93836fcbdf33cbb4aecb4c15059302aaa0e902f80655527", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0080", "status": "raw_data_deleted"}
|
| 83 |
+
{"timestamp": "2026-10-06 23:47:48", "chunk_id": "chunk_0081", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "79400..80400", "doc_count": 1000, "tokens_in_chunk": 980911, "cumulative_tokens": 85825359, "sha256_hash": "5c8d6c24dd9b198af3b9be71050e8e177c6fd96ffc0c5808201bcf15eece853a", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0081", "status": "raw_data_deleted"}
|
| 84 |
+
{"timestamp": "2026-10-06 23:54:48", "chunk_id": "chunk_0082", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "80400..81400", "doc_count": 1000, "tokens_in_chunk": 958216, "cumulative_tokens": 86783575, "sha256_hash": "38b43a449c2c089ffe32100e5dcd3a4ab0ab4aa96db42cd6561142b16d130331", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0082", "status": "raw_data_deleted"}
|
| 85 |
+
{"timestamp": "2026-10-07 00:02:10", "chunk_id": "chunk_0083", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "81400..82400", "doc_count": 1000, "tokens_in_chunk": 955279, "cumulative_tokens": 87738854, "sha256_hash": "9f07bff2fd69e33a7d8488879b748b676f646a48e6ea30e1435d667dd321e096", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0083", "status": "raw_data_deleted"}
|
| 86 |
+
{"timestamp": "2026-10-07 00:11:02", "chunk_id": "chunk_0084", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "82400..83400", "doc_count": 1000, "tokens_in_chunk": 969208, "cumulative_tokens": 88708062, "sha256_hash": "8770788909d623ce3e7fd3775902c378a1fe219eba1d1f4623bbac4f13b60560", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0084", "status": "raw_data_deleted"}
|
| 87 |
+
{"timestamp": "2026-10-07 00:18:59", "chunk_id": "chunk_0085", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "83400..84400", "doc_count": 1000, "tokens_in_chunk": 876690, "cumulative_tokens": 89584752, "sha256_hash": "cb8e6b36afff00d9e8d225d1be14d0d60b5804165ea73bfb0f53fe73034f827c", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0085", "status": "raw_data_deleted"}
|
| 88 |
+
{"timestamp": "2026-10-07 00:27:50", "chunk_id": "chunk_0086", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "84400..85400", "doc_count": 1000, "tokens_in_chunk": 983898, "cumulative_tokens": 90568650, "sha256_hash": "a51d19c9db25f86082a9a64b215b7446caf73e6e7688af851e97802435e18f67", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0086", "status": "raw_data_deleted"}
|
| 89 |
+
{"timestamp": "2026-10-07 00:37:37", "chunk_id": "chunk_0087", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "85400..86400", "doc_count": 1000, "tokens_in_chunk": 1087484, "cumulative_tokens": 91656134, "sha256_hash": "4bf7916a7498be5d3d444915f86e5e0c78d240e70874d7f0c797fb9d68de8ff4", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0087", "status": "raw_data_deleted"}
|
| 90 |
+
{"timestamp": "2026-10-07 00:46:13", "chunk_id": "chunk_0088", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "86400..87400", "doc_count": 1000, "tokens_in_chunk": 955431, "cumulative_tokens": 92611565, "sha256_hash": "009ee5eeca4cc2a63c0fb9e2790df3eab95946ecce8b99a684b8821227afb8bc", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0088", "status": "raw_data_deleted"}
|
| 91 |
+
{"timestamp": "2026-10-07 00:55:25", "chunk_id": "chunk_0089", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "87400..88400", "doc_count": 1000, "tokens_in_chunk": 1007934, "cumulative_tokens": 93619499, "sha256_hash": "f395ea22b1c1365029f5c3e6348c84809b49f99a7ae32321bf3d4e05a9945efe", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0089", "status": "raw_data_deleted"}
|
| 92 |
+
{"timestamp": "2026-10-07 01:04:06", "chunk_id": "chunk_0090", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "88400..89400", "doc_count": 1000, "tokens_in_chunk": 960619, "cumulative_tokens": 94580118, "sha256_hash": "f10eccfa49d740a1f17f12ac6ef8a1d7c2e1d9bb607ffbdef9f6312c2edd1687", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0090", "status": "raw_data_deleted"}
|
| 93 |
+
{"timestamp": "2026-10-07 01:12:49", "chunk_id": "chunk_0091", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "89400..90400", "doc_count": 1000, "tokens_in_chunk": 990657, "cumulative_tokens": 95570775, "sha256_hash": "5fc000c45c068001e0312316818ff61559a88bcdaf8fd509c25fce089a675545", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0091", "status": "raw_data_deleted"}
|
| 94 |
+
{"timestamp": "2026-10-07 01:22:24", "chunk_id": "chunk_0092", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "90400..91400", "doc_count": 1000, "tokens_in_chunk": 1096573, "cumulative_tokens": 96667348, "sha256_hash": "2f59440c7087ec0784e1965b1d4c28e254a310ecbad3258eee3308f41b3e6a34", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0092", "status": "raw_data_deleted"}
|
| 95 |
+
{"timestamp": "2026-10-07 14:26:45", "chunk_id": "chunk_0093", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "92400..93400", "doc_count": 1000, "tokens_in_chunk": 1095811, "cumulative_tokens": 110742696, "sha256_hash": "68669ae84ff97da1711272600720ad11a20be1fb091010347183849cb08a6393", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0093", "status": "raw_data_deleted"}
|
| 96 |
+
{"timestamp": "2026-10-07 14:33:02", "chunk_id": "chunk_0094", "source": "HuggingFaceFW/fineweb-edu:sample-10BT", "document_range": "93400..94400", "doc_count": 1000, "tokens_in_chunk": 1007216, "cumulative_tokens": 111749912, "sha256_hash": "e8495772cc37f9a2379c025e971ff8d8451bd6cd4630a09e6a50cd208561e58d", "initial_loss": NaN, "final_loss": NaN, "checkpoint_saved": "checkpoints/pretrain/steps/chunk_0094", "status": "raw_data_deleted"}
|
manifests/training_metrics.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling.py
ADDED
|
@@ -0,0 +1,666 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jerboa Language Model Architecture.
|
| 2 |
+
|
| 3 |
+
Incorporating modern LLM design principles:
|
| 4 |
+
- Pre-RMSNorm
|
| 5 |
+
- QK-Norm (stabilizes attention entropy and training)
|
| 6 |
+
- Rotary Position Embeddings (RoPE)
|
| 7 |
+
- Grouped-Query Attention (GQA) for efficient KV caching
|
| 8 |
+
- SwiGLU Feed-Forward Networks
|
| 9 |
+
- Tied Input-Output Embeddings for parameter efficiency in ~100M-150M regime
|
| 10 |
+
- Native PyTorch SDPA (Scaled Dot-Product Attention) for Apple Silicon MPS speed
|
| 11 |
+
- Full Hugging Face PreTrainedModel & GenerationMixin compatibility
|
| 12 |
+
- Modern DynamicCache support
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import math
|
| 16 |
+
from typing import Any, List, Optional, Tuple, Union
|
| 17 |
+
|
| 18 |
+
import torch
|
| 19 |
+
import torch.nn as nn
|
| 20 |
+
import torch.nn.functional as F
|
| 21 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 22 |
+
from transformers.generation.utils import GenerationMixin
|
| 23 |
+
from transformers.modeling_outputs import (
|
| 24 |
+
BaseModelOutputWithPast,
|
| 25 |
+
CausalLMOutputWithPast,
|
| 26 |
+
)
|
| 27 |
+
from transformers.modeling_utils import PreTrainedModel
|
| 28 |
+
from transformers.utils import logging
|
| 29 |
+
|
| 30 |
+
try:
|
| 31 |
+
from .config import JerboaConfig
|
| 32 |
+
except (ImportError, ValueError):
|
| 33 |
+
from config import JerboaConfig
|
| 34 |
+
|
| 35 |
+
logger = logging.get_logger(__name__)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class JerboaRMSNorm(nn.Module):
|
| 39 |
+
"""Root Mean Square Layer Normalization."""
|
| 40 |
+
|
| 41 |
+
def __init__(self, hidden_size: int, eps: float = 1e-6):
|
| 42 |
+
super().__init__()
|
| 43 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 44 |
+
self.variance_epsilon = eps
|
| 45 |
+
|
| 46 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 47 |
+
input_dtype = hidden_states.dtype
|
| 48 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 49 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 50 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 51 |
+
return (self.weight * hidden_states).to(input_dtype)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class JerboaRotaryEmbedding(nn.Module):
|
| 55 |
+
"""Rotary Position Embedding (RoPE) supporting YaRN, dynamic NTK, and meta-device."""
|
| 56 |
+
|
| 57 |
+
def __init__(
|
| 58 |
+
self,
|
| 59 |
+
dim: int,
|
| 60 |
+
max_position_embeddings: int = 4096,
|
| 61 |
+
base: float = 100000.0,
|
| 62 |
+
config: Optional[Any] = None,
|
| 63 |
+
):
|
| 64 |
+
super().__init__()
|
| 65 |
+
self.dim = dim
|
| 66 |
+
self.max_position_embeddings = max_position_embeddings
|
| 67 |
+
self.base = base
|
| 68 |
+
self.config = config
|
| 69 |
+
self.attention_factor = 1.0
|
| 70 |
+
|
| 71 |
+
if config is not None and getattr(config, "rope_scaling", None) is not None:
|
| 72 |
+
scaling_type = config.rope_scaling.get("type", "default")
|
| 73 |
+
try:
|
| 74 |
+
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
|
| 75 |
+
|
| 76 |
+
if scaling_type in ROPE_INIT_FUNCTIONS:
|
| 77 |
+
inv_freq, attention_factor = ROPE_INIT_FUNCTIONS[scaling_type](
|
| 78 |
+
config, device="cpu", seq_len=max_position_embeddings
|
| 79 |
+
)
|
| 80 |
+
self.attention_factor = float(attention_factor) if attention_factor is not None else 1.0
|
| 81 |
+
else:
|
| 82 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
|
| 83 |
+
except Exception:
|
| 84 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
|
| 85 |
+
else:
|
| 86 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
|
| 87 |
+
|
| 88 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 89 |
+
self.max_seq_len_cached = -1
|
| 90 |
+
self.cos_cached = None
|
| 91 |
+
self.sin_cached = None
|
| 92 |
+
|
| 93 |
+
def _set_cos_sin_cache(self, seq_len: int, device: torch.device, dtype: torch.dtype):
|
| 94 |
+
self.max_seq_len_cached = seq_len
|
| 95 |
+
if self.inv_freq.device.type == "meta":
|
| 96 |
+
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, device=device).float() / self.dim))
|
| 97 |
+
else:
|
| 98 |
+
inv_freq = self.inv_freq.to(device)
|
| 99 |
+
t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.float32)
|
| 100 |
+
freqs = torch.outer(t, inv_freq)
|
| 101 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 102 |
+
self.cos_cached = (emb.cos() * self.attention_factor).to(dtype=dtype, device=device)
|
| 103 |
+
self.sin_cached = (emb.sin() * self.attention_factor).to(dtype=dtype, device=device)
|
| 104 |
+
|
| 105 |
+
def forward(self, x: torch.Tensor, seq_len: int) -> Tuple[torch.Tensor, torch.Tensor]:
|
| 106 |
+
if self.cos_cached is None or seq_len > self.max_seq_len_cached or self.cos_cached.device != x.device:
|
| 107 |
+
self._set_cos_sin_cache(
|
| 108 |
+
seq_len=max(seq_len, self.max_position_embeddings),
|
| 109 |
+
device=x.device,
|
| 110 |
+
dtype=x.dtype,
|
| 111 |
+
)
|
| 112 |
+
return (
|
| 113 |
+
self.cos_cached[:seq_len],
|
| 114 |
+
self.sin_cached[:seq_len],
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def rotate_half(x: torch.Tensor) -> torch.Tensor:
|
| 119 |
+
"""Rotates half the hidden dims of the input."""
|
| 120 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 121 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 122 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def apply_rotary_pos_emb(q: torch.Tensor, k: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor, position_ids: torch.Tensor):
|
| 126 |
+
cos = cos[position_ids].unsqueeze(1) # [batch_size, 1, seq_len, dim]
|
| 127 |
+
sin = sin[position_ids].unsqueeze(1) # [batch_size, 1, seq_len, dim]
|
| 128 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 129 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 130 |
+
return q_embed, k_embed
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 134 |
+
"""Repeat KV heads for Grouped Query Attention (GQA)."""
|
| 135 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 136 |
+
if n_rep == 1:
|
| 137 |
+
return hidden_states
|
| 138 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(
|
| 139 |
+
batch, num_key_value_heads, n_rep, slen, head_dim
|
| 140 |
+
)
|
| 141 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
class JerboaAttention(nn.Module):
|
| 145 |
+
"""Grouped-Query Attention with QK-Norm."""
|
| 146 |
+
|
| 147 |
+
def __init__(self, config: JerboaConfig, layer_idx: Optional[int] = None):
|
| 148 |
+
super().__init__()
|
| 149 |
+
self.config = config
|
| 150 |
+
self.layer_idx = layer_idx
|
| 151 |
+
self.hidden_size = config.hidden_size
|
| 152 |
+
self.num_heads = config.num_attention_heads
|
| 153 |
+
self.head_dim = config.hidden_size // config.num_attention_heads
|
| 154 |
+
self.num_key_value_heads = config.num_key_value_heads
|
| 155 |
+
self.num_key_value_groups = self.num_heads // self.num_key_value_heads
|
| 156 |
+
|
| 157 |
+
self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=False)
|
| 158 |
+
self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
|
| 159 |
+
self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=False)
|
| 160 |
+
self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
|
| 161 |
+
|
| 162 |
+
# QK-Norm
|
| 163 |
+
if config.qk_norm:
|
| 164 |
+
self.q_norm = JerboaRMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 165 |
+
self.k_norm = JerboaRMSNorm(self.head_dim, eps=config.rms_norm_eps)
|
| 166 |
+
else:
|
| 167 |
+
self.q_norm = None
|
| 168 |
+
self.k_norm = None
|
| 169 |
+
|
| 170 |
+
# Interleaved Sliding Window Attention (SWA)
|
| 171 |
+
self.sliding_window = getattr(config, "sliding_window", None)
|
| 172 |
+
self.global_layer_interval = getattr(config, "global_layer_interval", 4)
|
| 173 |
+
if self.sliding_window is not None and self.global_layer_interval is not None and layer_idx is not None:
|
| 174 |
+
self.is_sliding = (layer_idx + 1) % self.global_layer_interval != 0
|
| 175 |
+
else:
|
| 176 |
+
self.is_sliding = False
|
| 177 |
+
|
| 178 |
+
def forward(
|
| 179 |
+
self,
|
| 180 |
+
hidden_states: torch.Tensor,
|
| 181 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 182 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 183 |
+
past_key_value: Optional[Union[Cache, Tuple[torch.Tensor, torch.Tensor]]] = None,
|
| 184 |
+
use_cache: bool = False,
|
| 185 |
+
position_ids: Optional[torch.Tensor] = None,
|
| 186 |
+
) -> Tuple[torch.Tensor, Optional[Union[Cache, Tuple[torch.Tensor, torch.Tensor]]]]:
|
| 187 |
+
bsz, q_len, _ = hidden_states.size()
|
| 188 |
+
|
| 189 |
+
query_states = self.q_proj(hidden_states)
|
| 190 |
+
key_states = self.k_proj(hidden_states)
|
| 191 |
+
value_states = self.v_proj(hidden_states)
|
| 192 |
+
|
| 193 |
+
query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
|
| 194 |
+
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 195 |
+
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 196 |
+
|
| 197 |
+
# Apply QK-Norm before RoPE
|
| 198 |
+
if self.q_norm is not None:
|
| 199 |
+
query_states = self.q_norm(query_states)
|
| 200 |
+
if self.k_norm is not None:
|
| 201 |
+
key_states = self.k_norm(key_states)
|
| 202 |
+
|
| 203 |
+
cos, sin = position_embeddings
|
| 204 |
+
if isinstance(past_key_value, Cache):
|
| 205 |
+
past_len = past_key_value.get_seq_length(self.layer_idx)
|
| 206 |
+
elif past_key_value is not None:
|
| 207 |
+
past_len = past_key_value[0].shape[-2]
|
| 208 |
+
else:
|
| 209 |
+
past_len = 0
|
| 210 |
+
|
| 211 |
+
if position_ids is None:
|
| 212 |
+
position_ids = torch.arange(past_len, past_len + q_len, dtype=torch.long, device=hidden_states.device).unsqueeze(0)
|
| 213 |
+
|
| 214 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
|
| 215 |
+
|
| 216 |
+
if past_key_value is not None:
|
| 217 |
+
if isinstance(past_key_value, Cache):
|
| 218 |
+
key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx)
|
| 219 |
+
else:
|
| 220 |
+
key_states = torch.cat([past_key_value[0], key_states], dim=2)
|
| 221 |
+
value_states = torch.cat([past_key_value[1], value_states], dim=2)
|
| 222 |
+
past_key_value = (key_states, value_states)
|
| 223 |
+
elif use_cache:
|
| 224 |
+
past_key_value = (key_states, value_states)
|
| 225 |
+
|
| 226 |
+
# Repeat KV for GQA
|
| 227 |
+
key_states = repeat_kv(key_states, self.num_key_value_groups)
|
| 228 |
+
value_states = repeat_kv(value_states, self.num_key_value_groups)
|
| 229 |
+
|
| 230 |
+
# PyTorch SDPA (Metal hardware-accelerated on MPS)
|
| 231 |
+
kv_len = key_states.shape[-2]
|
| 232 |
+
attn_mask = None
|
| 233 |
+
is_causal = False
|
| 234 |
+
|
| 235 |
+
if attention_mask is not None:
|
| 236 |
+
if attention_mask.dim() == 4:
|
| 237 |
+
attn_mask = attention_mask
|
| 238 |
+
elif attention_mask.dim() == 2:
|
| 239 |
+
# If padding mask is provided and contains padded positions (zeros)
|
| 240 |
+
if not (attention_mask == 1).all():
|
| 241 |
+
mask_2d = attention_mask[:, None, None, :].to(dtype=query_states.dtype)
|
| 242 |
+
attn_mask = (1.0 - mask_2d) * torch.finfo(query_states.dtype).min
|
| 243 |
+
|
| 244 |
+
if attn_mask is None and q_len > 1 and q_len == kv_len:
|
| 245 |
+
is_causal = True
|
| 246 |
+
|
| 247 |
+
# Apply Interleaved Sliding Window Attention (SWA) mask
|
| 248 |
+
if self.is_sliding and self.sliding_window is not None:
|
| 249 |
+
q_pos = torch.arange(past_len, past_len + q_len, device=query_states.device).unsqueeze(1)
|
| 250 |
+
k_pos = torch.arange(0, kv_len, device=key_states.device).unsqueeze(0)
|
| 251 |
+
valid_mask = (k_pos <= q_pos) & (q_pos - k_pos < self.sliding_window)
|
| 252 |
+
swa_mask = torch.zeros((q_len, kv_len), dtype=query_states.dtype, device=query_states.device)
|
| 253 |
+
swa_mask = swa_mask.masked_fill(~valid_mask, torch.finfo(query_states.dtype).min)
|
| 254 |
+
swa_mask = swa_mask.unsqueeze(0).unsqueeze(0)
|
| 255 |
+
if attn_mask is not None:
|
| 256 |
+
attn_mask = attn_mask + swa_mask
|
| 257 |
+
else:
|
| 258 |
+
attn_mask = swa_mask
|
| 259 |
+
is_causal = False
|
| 260 |
+
|
| 261 |
+
attn_output = F.scaled_dot_product_attention(
|
| 262 |
+
query_states,
|
| 263 |
+
key_states,
|
| 264 |
+
value_states,
|
| 265 |
+
attn_mask=attn_mask,
|
| 266 |
+
dropout_p=self.config.attention_dropout if self.training else 0.0,
|
| 267 |
+
is_causal=is_causal,
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
attn_output = attn_output.transpose(1, 2).contiguous().view(bsz, q_len, -1)
|
| 271 |
+
attn_output = self.o_proj(attn_output)
|
| 272 |
+
|
| 273 |
+
return attn_output, past_key_value
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
class JerboaMLP(nn.Module):
|
| 277 |
+
"""SwiGLU Feed-Forward Network."""
|
| 278 |
+
|
| 279 |
+
def __init__(self, config: JerboaConfig):
|
| 280 |
+
super().__init__()
|
| 281 |
+
self.gate_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
|
| 282 |
+
self.up_proj = nn.Linear(config.hidden_size, config.intermediate_size, bias=False)
|
| 283 |
+
self.down_proj = nn.Linear(config.intermediate_size, config.hidden_size, bias=False)
|
| 284 |
+
self.act_fn = F.silu
|
| 285 |
+
|
| 286 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 287 |
+
return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
class JerboaDecoderLayer(nn.Module):
|
| 291 |
+
"""Single Transformer Decoder Block."""
|
| 292 |
+
|
| 293 |
+
def __init__(self, config: JerboaConfig, layer_idx: Optional[int] = None):
|
| 294 |
+
super().__init__()
|
| 295 |
+
self.input_layernorm = JerboaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 296 |
+
self.self_attn = JerboaAttention(config, layer_idx=layer_idx)
|
| 297 |
+
self.post_attention_layernorm = JerboaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 298 |
+
self.mlp = JerboaMLP(config)
|
| 299 |
+
|
| 300 |
+
def forward(
|
| 301 |
+
self,
|
| 302 |
+
hidden_states: torch.Tensor,
|
| 303 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 304 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 305 |
+
past_key_value: Optional[Union[Cache, Tuple[torch.Tensor, torch.Tensor]]] = None,
|
| 306 |
+
use_cache: bool = False,
|
| 307 |
+
position_ids: Optional[torch.Tensor] = None,
|
| 308 |
+
) -> Tuple[torch.Tensor, Optional[Union[Cache, Tuple[torch.Tensor, torch.Tensor]]]]:
|
| 309 |
+
residual = hidden_states
|
| 310 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 311 |
+
hidden_states, present_key_value = self.self_attn(
|
| 312 |
+
hidden_states=hidden_states,
|
| 313 |
+
position_embeddings=position_embeddings,
|
| 314 |
+
attention_mask=attention_mask,
|
| 315 |
+
past_key_value=past_key_value,
|
| 316 |
+
use_cache=use_cache,
|
| 317 |
+
position_ids=position_ids,
|
| 318 |
+
)
|
| 319 |
+
hidden_states = residual + hidden_states
|
| 320 |
+
|
| 321 |
+
residual = hidden_states
|
| 322 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 323 |
+
hidden_states = self.mlp(hidden_states)
|
| 324 |
+
hidden_states = residual + hidden_states
|
| 325 |
+
|
| 326 |
+
return hidden_states, present_key_value
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class JerboaPreTrainedModel(PreTrainedModel):
|
| 330 |
+
"""Base class for Jerboa models."""
|
| 331 |
+
|
| 332 |
+
config_class = JerboaConfig
|
| 333 |
+
base_model_prefix = "model"
|
| 334 |
+
supports_gradient_checkpointing = True
|
| 335 |
+
_no_split_modules = ["JerboaDecoderLayer"]
|
| 336 |
+
|
| 337 |
+
def __init__(self, config: JerboaConfig, *inputs, **kwargs):
|
| 338 |
+
super().__init__(config, *inputs, **kwargs)
|
| 339 |
+
|
| 340 |
+
def _init_weights(self, module):
|
| 341 |
+
std = self.config.initializer_range
|
| 342 |
+
if isinstance(module, nn.Linear):
|
| 343 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 344 |
+
if module.bias is not None:
|
| 345 |
+
module.bias.data.zero_()
|
| 346 |
+
elif isinstance(module, nn.Embedding):
|
| 347 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 348 |
+
if module.padding_idx is not None:
|
| 349 |
+
module.weight.data[module.padding_idx].zero_()
|
| 350 |
+
|
| 351 |
+
|
| 352 |
+
class JerboaModel(JerboaPreTrainedModel):
|
| 353 |
+
"""The bare Jerboa Model transformer outputting raw hidden-states."""
|
| 354 |
+
|
| 355 |
+
def __init__(self, config: JerboaConfig):
|
| 356 |
+
super().__init__(config)
|
| 357 |
+
self.padding_idx = config.pad_token_id
|
| 358 |
+
self.vocab_size = config.vocab_size
|
| 359 |
+
|
| 360 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 361 |
+
self.layers = nn.ModuleList(
|
| 362 |
+
[JerboaDecoderLayer(config, layer_idx=i) for i in range(config.num_hidden_layers)]
|
| 363 |
+
)
|
| 364 |
+
self.norm = JerboaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 365 |
+
self.rotary_emb = JerboaRotaryEmbedding(
|
| 366 |
+
dim=config.hidden_size // config.num_attention_heads,
|
| 367 |
+
max_position_embeddings=config.max_position_embeddings,
|
| 368 |
+
base=config.rope_theta,
|
| 369 |
+
config=config,
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
self.gradient_checkpointing = False
|
| 373 |
+
self.post_init()
|
| 374 |
+
|
| 375 |
+
def get_input_embeddings(self):
|
| 376 |
+
return self.embed_tokens
|
| 377 |
+
|
| 378 |
+
def set_input_embeddings(self, value):
|
| 379 |
+
self.embed_tokens = value
|
| 380 |
+
|
| 381 |
+
def forward(
|
| 382 |
+
self,
|
| 383 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 384 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 385 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 386 |
+
past_key_values: Optional[Union[Cache, List[Tuple[torch.Tensor, torch.Tensor]]]] = None,
|
| 387 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 388 |
+
use_cache: Optional[bool] = None,
|
| 389 |
+
output_hidden_states: Optional[bool] = None,
|
| 390 |
+
return_dict: Optional[bool] = None,
|
| 391 |
+
) -> Union[Tuple, BaseModelOutputWithPast]:
|
| 392 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 393 |
+
return_dict = return_dict if return_dict is not None else getattr(self.config, "return_dict", True)
|
| 394 |
+
|
| 395 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 396 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
| 397 |
+
elif input_ids is not None:
|
| 398 |
+
batch_size, seq_length = input_ids.shape
|
| 399 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 400 |
+
elif inputs_embeds is not None:
|
| 401 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
| 402 |
+
else:
|
| 403 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
| 404 |
+
|
| 405 |
+
if use_cache and past_key_values is None:
|
| 406 |
+
past_key_values = DynamicCache()
|
| 407 |
+
|
| 408 |
+
if past_key_values is not None:
|
| 409 |
+
if isinstance(past_key_values, Cache):
|
| 410 |
+
past_key_values_length = past_key_values.get_seq_length()
|
| 411 |
+
elif len(past_key_values) > 0 and past_key_values[0] is not None:
|
| 412 |
+
past_key_values_length = past_key_values[0][0].shape[-2]
|
| 413 |
+
else:
|
| 414 |
+
past_key_values_length = 0
|
| 415 |
+
else:
|
| 416 |
+
past_key_values_length = 0
|
| 417 |
+
|
| 418 |
+
if position_ids is None:
|
| 419 |
+
position_ids = torch.arange(
|
| 420 |
+
past_key_values_length, seq_length + past_key_values_length, dtype=torch.long, device=inputs_embeds.device
|
| 421 |
+
).unsqueeze(0)
|
| 422 |
+
elif position_ids.shape[-1] != seq_length:
|
| 423 |
+
position_ids = position_ids[:, -seq_length:]
|
| 424 |
+
|
| 425 |
+
hidden_states = inputs_embeds
|
| 426 |
+
position_embeddings = self.rotary_emb(hidden_states, seq_len=seq_length + past_key_values_length)
|
| 427 |
+
|
| 428 |
+
all_hidden_states = () if output_hidden_states else None
|
| 429 |
+
|
| 430 |
+
for idx, decoder_layer in enumerate(self.layers):
|
| 431 |
+
if output_hidden_states:
|
| 432 |
+
all_hidden_states += (hidden_states,)
|
| 433 |
+
|
| 434 |
+
past_kv = past_key_values if isinstance(past_key_values, Cache) else (
|
| 435 |
+
past_key_values[idx] if past_key_values is not None else None
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
if self.gradient_checkpointing and self.training:
|
| 439 |
+
def create_custom_forward(module):
|
| 440 |
+
def custom_forward(*inputs):
|
| 441 |
+
return module(*inputs)
|
| 442 |
+
return custom_forward
|
| 443 |
+
|
| 444 |
+
layer_outputs = torch.utils.checkpoint.checkpoint(
|
| 445 |
+
create_custom_forward(decoder_layer),
|
| 446 |
+
hidden_states,
|
| 447 |
+
position_embeddings,
|
| 448 |
+
attention_mask,
|
| 449 |
+
past_kv,
|
| 450 |
+
use_cache,
|
| 451 |
+
position_ids,
|
| 452 |
+
)
|
| 453 |
+
else:
|
| 454 |
+
layer_outputs = decoder_layer(
|
| 455 |
+
hidden_states,
|
| 456 |
+
position_embeddings=position_embeddings,
|
| 457 |
+
attention_mask=attention_mask,
|
| 458 |
+
past_key_value=past_kv,
|
| 459 |
+
use_cache=use_cache,
|
| 460 |
+
position_ids=position_ids,
|
| 461 |
+
)
|
| 462 |
+
|
| 463 |
+
hidden_states = layer_outputs[0]
|
| 464 |
+
|
| 465 |
+
hidden_states = self.norm(hidden_states)
|
| 466 |
+
|
| 467 |
+
if output_hidden_states:
|
| 468 |
+
all_hidden_states += (hidden_states,)
|
| 469 |
+
|
| 470 |
+
next_decoder_cache = past_key_values if use_cache else None
|
| 471 |
+
|
| 472 |
+
if not return_dict:
|
| 473 |
+
return tuple(v for v in [hidden_states, next_decoder_cache, all_hidden_states] if v is not None)
|
| 474 |
+
|
| 475 |
+
return BaseModelOutputWithPast(
|
| 476 |
+
last_hidden_state=hidden_states,
|
| 477 |
+
past_key_values=next_decoder_cache,
|
| 478 |
+
hidden_states=all_hidden_states,
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
class JerboaMTPModule(nn.Module):
|
| 483 |
+
"""Multi-Token Prediction (MTP) Module (DeepSeek-V3 / Qwen3 style).
|
| 484 |
+
|
| 485 |
+
Predicts token t+2 given hidden state h_t and token t+1 embedding,
|
| 486 |
+
regularizing future planning during pre-training and accelerating inference via speculative decoding.
|
| 487 |
+
"""
|
| 488 |
+
|
| 489 |
+
def __init__(self, config: JerboaConfig):
|
| 490 |
+
super().__init__()
|
| 491 |
+
self.config = config
|
| 492 |
+
self.proj = nn.Linear(config.hidden_size * 2, config.hidden_size, bias=False)
|
| 493 |
+
self.norm = JerboaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 494 |
+
self.block = JerboaDecoderLayer(config, layer_idx=0)
|
| 495 |
+
|
| 496 |
+
def forward(
|
| 497 |
+
self,
|
| 498 |
+
hidden_states: torch.Tensor,
|
| 499 |
+
next_embeds: torch.Tensor,
|
| 500 |
+
position_embeddings: Tuple[torch.Tensor, torch.Tensor],
|
| 501 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 502 |
+
) -> torch.Tensor:
|
| 503 |
+
combined = torch.cat([hidden_states, next_embeds], dim=-1)
|
| 504 |
+
h = self.norm(self.proj(combined))
|
| 505 |
+
out = self.block(h, position_embeddings=position_embeddings, attention_mask=attention_mask)
|
| 506 |
+
return out[0]
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
class JerboaForCausalLM(JerboaPreTrainedModel, GenerationMixin):
|
| 510 |
+
"""Jerboa Model with a language modeling head on top for Causal Language Modeling."""
|
| 511 |
+
|
| 512 |
+
_tied_weights_keys = {"lm_head.weight": "model.embed_tokens.weight"}
|
| 513 |
+
|
| 514 |
+
def __init__(self, config: JerboaConfig):
|
| 515 |
+
super().__init__(config)
|
| 516 |
+
self.model = JerboaModel(config)
|
| 517 |
+
self.vocab_size = config.vocab_size
|
| 518 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 519 |
+
self.mtp_module = JerboaMTPModule(config) if getattr(config, "enable_mtp", getattr(config, "use_mtp", False)) else None
|
| 520 |
+
|
| 521 |
+
# Initialize weights and tie embeddings
|
| 522 |
+
self.post_init()
|
| 523 |
+
|
| 524 |
+
def get_input_embeddings(self):
|
| 525 |
+
return self.model.embed_tokens
|
| 526 |
+
|
| 527 |
+
def set_input_embeddings(self, value):
|
| 528 |
+
self.model.embed_tokens = value
|
| 529 |
+
|
| 530 |
+
def get_output_embeddings(self):
|
| 531 |
+
return self.lm_head
|
| 532 |
+
|
| 533 |
+
def set_output_embeddings(self, new_embeddings):
|
| 534 |
+
self.lm_head = new_embeddings
|
| 535 |
+
|
| 536 |
+
def forward(
|
| 537 |
+
self,
|
| 538 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 539 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 540 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 541 |
+
past_key_values: Optional[Union[Cache, List[Tuple[torch.Tensor, torch.Tensor]]]] = None,
|
| 542 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 543 |
+
labels: Optional[torch.LongTensor] = None,
|
| 544 |
+
use_cache: Optional[bool] = None,
|
| 545 |
+
output_attentions: Optional[bool] = None,
|
| 546 |
+
output_hidden_states: Optional[bool] = None,
|
| 547 |
+
return_dict: Optional[bool] = None,
|
| 548 |
+
**kwargs,
|
| 549 |
+
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 550 |
+
return_dict = return_dict if return_dict is not None else getattr(self.config, "return_dict", True)
|
| 551 |
+
|
| 552 |
+
outputs = self.model(
|
| 553 |
+
input_ids=input_ids,
|
| 554 |
+
attention_mask=attention_mask,
|
| 555 |
+
position_ids=position_ids,
|
| 556 |
+
past_key_values=past_key_values,
|
| 557 |
+
inputs_embeds=inputs_embeds,
|
| 558 |
+
use_cache=use_cache,
|
| 559 |
+
output_hidden_states=output_hidden_states,
|
| 560 |
+
return_dict=return_dict,
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
+
hidden_states = outputs[0]
|
| 564 |
+
logits = self.lm_head(hidden_states)
|
| 565 |
+
|
| 566 |
+
loss = None
|
| 567 |
+
if labels is not None:
|
| 568 |
+
# Shift so that tokens < n predict n
|
| 569 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 570 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 571 |
+
loss = F.cross_entropy(
|
| 572 |
+
shift_logits.view(-1, self.config.vocab_size),
|
| 573 |
+
shift_labels.view(-1),
|
| 574 |
+
ignore_index=-100,
|
| 575 |
+
)
|
| 576 |
+
|
| 577 |
+
# Multi-Token Prediction loss (t -> t+2)
|
| 578 |
+
if self.mtp_module is not None and shift_labels.shape[1] > 1:
|
| 579 |
+
h_t = hidden_states[:, :-2, :]
|
| 580 |
+
t_plus_1_labels = shift_labels[:, :-1]
|
| 581 |
+
t_plus_2_labels = shift_labels[:, 1:]
|
| 582 |
+
|
| 583 |
+
valid_t_plus_1 = t_plus_1_labels.clamp(min=0)
|
| 584 |
+
e_t_plus_1 = self.model.embed_tokens(valid_t_plus_1)
|
| 585 |
+
|
| 586 |
+
pos_emb_mtp = self.model.rotary_emb(h_t, seq_len=h_t.shape[1])
|
| 587 |
+
mtp_hidden = self.mtp_module(h_t, e_t_plus_1, position_embeddings=pos_emb_mtp)
|
| 588 |
+
mtp_logits = self.lm_head(mtp_hidden)
|
| 589 |
+
|
| 590 |
+
mtp_loss = F.cross_entropy(
|
| 591 |
+
mtp_logits.view(-1, self.config.vocab_size),
|
| 592 |
+
t_plus_2_labels.contiguous().view(-1),
|
| 593 |
+
ignore_index=-100,
|
| 594 |
+
)
|
| 595 |
+
loss = loss + getattr(self.config, "mtp_loss_factor", 0.3) * mtp_loss
|
| 596 |
+
|
| 597 |
+
if not return_dict:
|
| 598 |
+
output = (logits,) + outputs[1:]
|
| 599 |
+
return ((loss,) + output) if loss is not None else output
|
| 600 |
+
|
| 601 |
+
return CausalLMOutputWithPast(
|
| 602 |
+
loss=loss,
|
| 603 |
+
logits=logits,
|
| 604 |
+
past_key_values=outputs.past_key_values,
|
| 605 |
+
hidden_states=outputs.hidden_states,
|
| 606 |
+
)
|
| 607 |
+
|
| 608 |
+
@torch.no_grad()
|
| 609 |
+
def generate_2token_step(self, input_ids: torch.LongTensor) -> Tuple[torch.LongTensor, Optional[torch.LongTensor]]:
|
| 610 |
+
"""Predict next 2 tokens simultaneously in a single forward step using MTP head.
|
| 611 |
+
|
| 612 |
+
Returns:
|
| 613 |
+
Tuple of (token_1, token_2) with shapes [batch_size].
|
| 614 |
+
"""
|
| 615 |
+
outputs = self.model(input_ids=input_ids, use_cache=False)
|
| 616 |
+
last_h = outputs.last_hidden_state[:, -1:, :]
|
| 617 |
+
next_logit = self.lm_head(last_h)
|
| 618 |
+
token_1 = torch.argmax(next_logit[:, -1, :], dim=-1)
|
| 619 |
+
|
| 620 |
+
token_2 = None
|
| 621 |
+
if self.mtp_module is not None:
|
| 622 |
+
t1_tensor = token_1.unsqueeze(1)
|
| 623 |
+
e_t1 = self.model.embed_tokens(t1_tensor)
|
| 624 |
+
pos_emb = self.model.rotary_emb(last_h, seq_len=1)
|
| 625 |
+
mtp_h = self.mtp_module(last_h, e_t1, position_embeddings=pos_emb)
|
| 626 |
+
mtp_logits = self.lm_head(mtp_h)
|
| 627 |
+
token_2 = torch.argmax(mtp_logits[:, -1, :], dim=-1)
|
| 628 |
+
|
| 629 |
+
return token_1, token_2
|
| 630 |
+
|
| 631 |
+
def prepare_inputs_for_generation(
|
| 632 |
+
self,
|
| 633 |
+
input_ids: torch.LongTensor,
|
| 634 |
+
next_sequence_length: Optional[int] = None,
|
| 635 |
+
past_key_values: Optional[Union[Cache, List[Tuple[torch.Tensor, torch.Tensor]]]] = None,
|
| 636 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 637 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 638 |
+
**kwargs,
|
| 639 |
+
):
|
| 640 |
+
if next_sequence_length is not None:
|
| 641 |
+
input_ids = input_ids[:, -next_sequence_length:]
|
| 642 |
+
elif past_key_values is not None:
|
| 643 |
+
if isinstance(past_key_values, Cache):
|
| 644 |
+
past_length = past_key_values.get_seq_length()
|
| 645 |
+
elif len(past_key_values) > 0 and past_key_values[0] is not None:
|
| 646 |
+
past_length = past_key_values[0][0].shape[-2]
|
| 647 |
+
else:
|
| 648 |
+
past_length = 0
|
| 649 |
+
if past_length > 0:
|
| 650 |
+
input_ids = input_ids[:, -1:]
|
| 651 |
+
|
| 652 |
+
position_ids = kwargs.get("position_ids", None)
|
| 653 |
+
if attention_mask is not None and position_ids is None:
|
| 654 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 655 |
+
position_ids.masked_fill_(attention_mask == 0, 1)
|
| 656 |
+
if past_key_values is not None:
|
| 657 |
+
position_ids = position_ids[:, -input_ids.shape[1] :]
|
| 658 |
+
|
| 659 |
+
model_inputs = {
|
| 660 |
+
"input_ids": input_ids,
|
| 661 |
+
"position_ids": position_ids,
|
| 662 |
+
"past_key_values": past_key_values,
|
| 663 |
+
"use_cache": kwargs.get("use_cache", True),
|
| 664 |
+
"attention_mask": attention_mask,
|
| 665 |
+
}
|
| 666 |
+
return model_inputs
|
multimodal.py
ADDED
|
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Jerboa Multimodal Architecture (Vision + Audio + Language).
|
| 2 |
+
|
| 3 |
+
Key Features:
|
| 4 |
+
- Plug-and-play Lightweight Vision Encoder (built-in ViT or SigLIP compatible)
|
| 5 |
+
- 2x2 Spatial Token Compression (downsamples visual tokens 4x for ultra-low memory & fast prefill)
|
| 6 |
+
- Audio Log-Mel Spectrogram Encoder (Whisper-compatible downsampled 1D Conv + Transformer)
|
| 7 |
+
- Multimodal Projectors (2-layer MLP with SiLU and RMSNorm)
|
| 8 |
+
- Seamless placeholder replacement (<|image|>, <|audio|>) into LLM token embeddings
|
| 9 |
+
- End-to-end training and inference on Apple Silicon MPS
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from typing import List, Optional, Tuple, Union
|
| 13 |
+
|
| 14 |
+
import torch
|
| 15 |
+
import torch.nn as nn
|
| 16 |
+
import torch.nn.functional as F
|
| 17 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
from .config import JerboaConfig
|
| 21 |
+
from .modeling import JerboaForCausalLM, JerboaRMSNorm
|
| 22 |
+
except (ImportError, ValueError):
|
| 23 |
+
from config import JerboaConfig
|
| 24 |
+
from modeling import JerboaForCausalLM, JerboaRMSNorm
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class VisionPatchEmbed(nn.Module):
|
| 28 |
+
"""2D Image to Patch Embedding."""
|
| 29 |
+
|
| 30 |
+
def __init__(self, img_size: int = 224, patch_size: int = 16, in_chans: int = 3, embed_dim: int = 384):
|
| 31 |
+
super().__init__()
|
| 32 |
+
self.img_size = img_size
|
| 33 |
+
self.patch_size = patch_size
|
| 34 |
+
self.grid_size = img_size // patch_size
|
| 35 |
+
self.num_patches = self.grid_size * self.grid_size
|
| 36 |
+
|
| 37 |
+
self.proj = nn.Conv2d(in_chans, embed_dim, kernel_size=patch_size, stride=patch_size)
|
| 38 |
+
self.norm = nn.LayerNorm(embed_dim)
|
| 39 |
+
|
| 40 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 41 |
+
# x: [B, C, H, W] -> [B, D, grid_h, grid_w] -> [B, N, D]
|
| 42 |
+
x = self.proj(x).flatten(2).transpose(1, 2)
|
| 43 |
+
x = self.norm(x)
|
| 44 |
+
return x
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class VisionTransformerBlock(nn.Module):
|
| 48 |
+
"""Lightweight Vision Transformer Block."""
|
| 49 |
+
|
| 50 |
+
def __init__(self, dim: int, num_heads: int = 6, mlp_ratio: float = 4.0):
|
| 51 |
+
super().__init__()
|
| 52 |
+
self.norm1 = nn.LayerNorm(dim)
|
| 53 |
+
self.attn = nn.MultiheadAttention(dim, num_heads, dropout=0.0, batch_first=True)
|
| 54 |
+
self.norm2 = nn.LayerNorm(dim)
|
| 55 |
+
mlp_hidden_dim = int(dim * mlp_ratio)
|
| 56 |
+
self.mlp = nn.Sequential(
|
| 57 |
+
nn.Linear(dim, mlp_hidden_dim),
|
| 58 |
+
nn.GELU(),
|
| 59 |
+
nn.Linear(mlp_hidden_dim, dim),
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 63 |
+
norm_x = self.norm1(x)
|
| 64 |
+
attn_out, _ = self.attn(norm_x, norm_x, norm_x)
|
| 65 |
+
x = x + attn_out
|
| 66 |
+
x = x + self.mlp(self.norm2(x))
|
| 67 |
+
return x
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
class LightweightVisionEncoder(nn.Module):
|
| 71 |
+
"""Compact Vision Encoder (ViT-Nano ~15M params) for fast multimodal learning."""
|
| 72 |
+
|
| 73 |
+
def __init__(
|
| 74 |
+
self,
|
| 75 |
+
img_size: int = 224,
|
| 76 |
+
patch_size: int = 16,
|
| 77 |
+
in_chans: int = 3,
|
| 78 |
+
embed_dim: int = 384,
|
| 79 |
+
depth: int = 6,
|
| 80 |
+
num_heads: int = 6,
|
| 81 |
+
):
|
| 82 |
+
super().__init__()
|
| 83 |
+
self.patch_embed = VisionPatchEmbed(img_size, patch_size, in_chans, embed_dim)
|
| 84 |
+
self.num_patches = self.patch_embed.num_patches
|
| 85 |
+
self.pos_embed = nn.Parameter(torch.zeros(1, self.num_patches, embed_dim))
|
| 86 |
+
self.blocks = nn.ModuleList([VisionTransformerBlock(embed_dim, num_heads) for _ in range(depth)])
|
| 87 |
+
self.norm = nn.LayerNorm(embed_dim)
|
| 88 |
+
nn.init.trunc_normal_(self.pos_embed, std=0.02)
|
| 89 |
+
|
| 90 |
+
def forward(self, pixel_values: torch.Tensor) -> torch.Tensor:
|
| 91 |
+
# pixel_values: [B, C, H, W]
|
| 92 |
+
x = self.patch_embed(pixel_values)
|
| 93 |
+
x = x + self.pos_embed
|
| 94 |
+
for block in self.blocks:
|
| 95 |
+
x = block(x)
|
| 96 |
+
x = self.norm(x)
|
| 97 |
+
return x # [B, num_patches, embed_dim]
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
class EmbeddingGemmaVisionEncoder(nn.Module):
|
| 101 |
+
"""Vision Encoder wrapper backed by Google DeepMind's EmbeddingGemma 2.
|
| 102 |
+
|
| 103 |
+
Extracts rich 768-dimensional visual token representations (256 tokens per image)
|
| 104 |
+
aligned with Gemma 4's multimodal embedding space.
|
| 105 |
+
"""
|
| 106 |
+
|
| 107 |
+
def __init__(self, model_id: str = "google/embeddinggemma-2", freeze: bool = True):
|
| 108 |
+
super().__init__()
|
| 109 |
+
from transformers import AutoModel, AutoProcessor
|
| 110 |
+
|
| 111 |
+
self.model_id = model_id
|
| 112 |
+
print(f"[EmbeddingGemma] Loading vision backbone from '{model_id}'...")
|
| 113 |
+
self.processor = AutoProcessor.from_pretrained(model_id)
|
| 114 |
+
self.embedding_model = AutoModel.from_pretrained(model_id, dtype=torch.float32)
|
| 115 |
+
|
| 116 |
+
if freeze:
|
| 117 |
+
for p in self.embedding_model.parameters():
|
| 118 |
+
p.requires_grad = False
|
| 119 |
+
self.embedding_model.eval()
|
| 120 |
+
|
| 121 |
+
self.embed_dim = 768
|
| 122 |
+
|
| 123 |
+
def forward(self, images_or_pixel_values) -> torch.Tensor:
|
| 124 |
+
"""Forward images through EmbeddingGemma 2 and extract visual token sequence."""
|
| 125 |
+
device = next(self.embedding_model.parameters()).device
|
| 126 |
+
dtype = next(self.embedding_model.parameters()).dtype
|
| 127 |
+
|
| 128 |
+
if isinstance(images_or_pixel_values, torch.Tensor):
|
| 129 |
+
# Already tensor: convert to PIL for processor if needed or pass directly
|
| 130 |
+
# If standard [B, C, H, W] tensor in [0, 1]
|
| 131 |
+
from torchvision.transforms.functional import to_pil_image
|
| 132 |
+
b = images_or_pixel_values.shape[0]
|
| 133 |
+
pil_images = [to_pil_image(images_or_pixel_values[i].cpu().float()) for i in range(b)]
|
| 134 |
+
inputs = self.processor(text=["<|image|>"] * b, images=pil_images, return_tensors="pt")
|
| 135 |
+
elif isinstance(images_or_pixel_values, list):
|
| 136 |
+
b = len(images_or_pixel_values)
|
| 137 |
+
inputs = self.processor(text=["<|image|>"] * b, images=images_or_pixel_values, return_tensors="pt")
|
| 138 |
+
else:
|
| 139 |
+
inputs = self.processor(text="<|image|>", images=images_or_pixel_values, return_tensors="pt")
|
| 140 |
+
|
| 141 |
+
inputs = {k: v.to(device) for k, v in inputs.items()}
|
| 142 |
+
|
| 143 |
+
with torch.no_grad():
|
| 144 |
+
outputs = self.embedding_model(**inputs)
|
| 145 |
+
# last_hidden_state: [B, 260, 768]
|
| 146 |
+
# token 0: BOS, 1: BOI, 2..257: 256 visual tokens, 258: EOI, 259: EOS
|
| 147 |
+
visual_tokens = outputs.last_hidden_state[:, 2:258, :].to(dtype)
|
| 148 |
+
|
| 149 |
+
return visual_tokens # [B, 256, 768]
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
class VisionProjector(nn.Module):
|
| 153 |
+
"""Vision-to-Language Projector with 2x2 Spatial Token Compression."""
|
| 154 |
+
|
| 155 |
+
def __init__(self, vision_dim: int, llm_dim: int, spatial_merge_size: int = 2):
|
| 156 |
+
super().__init__()
|
| 157 |
+
self.spatial_merge_size = spatial_merge_size
|
| 158 |
+
in_features = vision_dim * (spatial_merge_size * spatial_merge_size)
|
| 159 |
+
self.linear_1 = nn.Linear(in_features, llm_dim, bias=True)
|
| 160 |
+
self.act = nn.SiLU()
|
| 161 |
+
self.linear_2 = nn.Linear(llm_dim, llm_dim, bias=True)
|
| 162 |
+
self.norm = JerboaRMSNorm(llm_dim)
|
| 163 |
+
|
| 164 |
+
def forward(self, visual_features: torch.Tensor, grid_h: int = 14, grid_w: int = 14) -> torch.Tensor:
|
| 165 |
+
# visual_features: [B, H*W, D]
|
| 166 |
+
b, n, d = visual_features.shape
|
| 167 |
+
m = self.spatial_merge_size
|
| 168 |
+
if n == grid_h * grid_w and grid_h % m == 0 and grid_w % m == 0:
|
| 169 |
+
# Reshape into 2D grid: [B, grid_h, grid_w, D]
|
| 170 |
+
feat = visual_features.view(b, grid_h, grid_w, d)
|
| 171 |
+
# Rearrange into 2x2 spatial blocks: [B, grid_h//2, grid_w//2, 4*D]
|
| 172 |
+
feat = feat.view(b, grid_h // m, m, grid_w // m, m, d)
|
| 173 |
+
feat = feat.permute(0, 1, 3, 2, 4, 5).contiguous()
|
| 174 |
+
feat = feat.view(b, (grid_h // m) * (grid_w // m), m * m * d)
|
| 175 |
+
else:
|
| 176 |
+
feat = visual_features
|
| 177 |
+
|
| 178 |
+
x = self.act(self.linear_1(feat))
|
| 179 |
+
x = self.norm(self.linear_2(x))
|
| 180 |
+
return x
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class LightweightAudioEncoder(nn.Module):
|
| 184 |
+
"""Compact 1D Conv + Transformer Audio Encoder for Mel-Spectrograms."""
|
| 185 |
+
|
| 186 |
+
def __init__(self, num_mel_bins: int = 80, embed_dim: int = 256, depth: int = 4, num_heads: int = 4):
|
| 187 |
+
super().__init__()
|
| 188 |
+
# Downsample temporal dimension 4x using 2 strided Conv1d layers
|
| 189 |
+
self.conv1 = nn.Conv1d(num_mel_bins, embed_dim, kernel_size=3, stride=2, padding=1)
|
| 190 |
+
self.conv2 = nn.Conv1d(embed_dim, embed_dim, kernel_size=3, stride=2, padding=1)
|
| 191 |
+
self.norm = nn.LayerNorm(embed_dim)
|
| 192 |
+
self.layers = nn.ModuleList([
|
| 193 |
+
nn.TransformerEncoderLayer(d_model=embed_dim, nhead=num_heads, dropout=0.0, batch_first=True)
|
| 194 |
+
for _ in range(depth)
|
| 195 |
+
])
|
| 196 |
+
|
| 197 |
+
def forward(self, mel_features: torch.Tensor) -> torch.Tensor:
|
| 198 |
+
# mel_features: [B, Mel_bins, T]
|
| 199 |
+
x = F.gelu(self.conv1(mel_features))
|
| 200 |
+
x = F.gelu(self.conv2(x))
|
| 201 |
+
x = x.transpose(1, 2) # [B, T//4, embed_dim]
|
| 202 |
+
x = self.norm(x)
|
| 203 |
+
for layer in self.layers:
|
| 204 |
+
x = layer(x)
|
| 205 |
+
return x
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class AudioProjector(nn.Module):
|
| 209 |
+
"""Audio-to-Language Projector."""
|
| 210 |
+
|
| 211 |
+
def __init__(self, audio_dim: int, llm_dim: int):
|
| 212 |
+
super().__init__()
|
| 213 |
+
self.linear_1 = nn.Linear(audio_dim, llm_dim, bias=True)
|
| 214 |
+
self.act = nn.SiLU()
|
| 215 |
+
self.linear_2 = nn.Linear(llm_dim, llm_dim, bias=True)
|
| 216 |
+
self.norm = JerboaRMSNorm(llm_dim)
|
| 217 |
+
|
| 218 |
+
def forward(self, audio_features: torch.Tensor) -> torch.Tensor:
|
| 219 |
+
x = self.act(self.linear_1(audio_features))
|
| 220 |
+
x = self.norm(self.linear_2(x))
|
| 221 |
+
return x
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
class JerboaVLForConditionalGeneration(nn.Module):
|
| 225 |
+
"""Jerboa Multimodal Model uniting Vision, Audio, and Language."""
|
| 226 |
+
|
| 227 |
+
def __init__(
|
| 228 |
+
self,
|
| 229 |
+
config: JerboaConfig,
|
| 230 |
+
vision_encoder: Optional[nn.Module] = None,
|
| 231 |
+
audio_encoder: Optional[nn.Module] = None,
|
| 232 |
+
vision_dim: Optional[int] = None,
|
| 233 |
+
audio_dim: int = 256,
|
| 234 |
+
use_embedding_gemma: bool = False,
|
| 235 |
+
):
|
| 236 |
+
super().__init__()
|
| 237 |
+
self.config = config
|
| 238 |
+
self.language_model = JerboaForCausalLM(config)
|
| 239 |
+
self.use_embedding_gemma = use_embedding_gemma
|
| 240 |
+
|
| 241 |
+
# Vision Encoder & Projector
|
| 242 |
+
if vision_encoder is not None:
|
| 243 |
+
self.vision_encoder = vision_encoder
|
| 244 |
+
effective_v_dim = vision_dim or 384
|
| 245 |
+
elif use_embedding_gemma:
|
| 246 |
+
self.vision_encoder = EmbeddingGemmaVisionEncoder(freeze=True)
|
| 247 |
+
effective_v_dim = 768
|
| 248 |
+
else:
|
| 249 |
+
effective_v_dim = vision_dim or 384
|
| 250 |
+
self.vision_encoder = VisionPatchEmbed(img_size=224, patch_size=16, embed_dim=effective_v_dim)
|
| 251 |
+
|
| 252 |
+
# Vision Projector connects 768-dim EmbeddingGemma or ViT to LLM hidden_size (768)
|
| 253 |
+
self.vision_projector = VisionProjector(
|
| 254 |
+
vision_dim=effective_v_dim,
|
| 255 |
+
llm_dim=config.hidden_size,
|
| 256 |
+
spatial_merge_size=1 if use_embedding_gemma else config.vision_spatial_merge_size,
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
# Audio Encoder & Projector
|
| 260 |
+
self.audio_encoder = audio_encoder if audio_encoder is not None else LightweightAudioEncoder(
|
| 261 |
+
num_mel_bins=80, embed_dim=audio_dim, depth=4
|
| 262 |
+
)
|
| 263 |
+
self.audio_projector = AudioProjector(
|
| 264 |
+
audio_dim=audio_dim,
|
| 265 |
+
llm_dim=config.hidden_size,
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
self.image_token_id = config.image_token_id
|
| 269 |
+
self.audio_token_id = config.audio_token_id
|
| 270 |
+
|
| 271 |
+
def forward(
|
| 272 |
+
self,
|
| 273 |
+
input_ids: torch.LongTensor,
|
| 274 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
| 275 |
+
audio_values: Optional[torch.FloatTensor] = None,
|
| 276 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 277 |
+
labels: Optional[torch.LongTensor] = None,
|
| 278 |
+
**kwargs,
|
| 279 |
+
) -> CausalLMOutputWithPast:
|
| 280 |
+
# Get base text token embeddings
|
| 281 |
+
inputs_embeds = self.language_model.model.embed_tokens(input_ids)
|
| 282 |
+
bsz, seq_len, hidden_dim = inputs_embeds.shape
|
| 283 |
+
|
| 284 |
+
# Process and inject visual tokens
|
| 285 |
+
if pixel_values is not None and self.image_token_id is not None:
|
| 286 |
+
vision_feats = self.vision_encoder(pixel_values)
|
| 287 |
+
proj_vision = self.vision_projector(vision_feats) # [B_img, N_vis, hidden_dim]
|
| 288 |
+
|
| 289 |
+
for b in range(bsz):
|
| 290 |
+
img_mask = input_ids[b] == self.image_token_id
|
| 291 |
+
img_count = img_mask.sum().item()
|
| 292 |
+
if img_count > 0:
|
| 293 |
+
vis_tokens = proj_vision[min(b, proj_vision.shape[0] - 1)]
|
| 294 |
+
if len(vis_tokens) >= img_count:
|
| 295 |
+
inputs_embeds[b, img_mask] = vis_tokens[:img_count]
|
| 296 |
+
else:
|
| 297 |
+
indices = torch.where(img_mask)[0][: len(vis_tokens)]
|
| 298 |
+
inputs_embeds[b, indices] = vis_tokens
|
| 299 |
+
|
| 300 |
+
# Process and inject audio tokens
|
| 301 |
+
if audio_values is not None and self.audio_token_id is not None:
|
| 302 |
+
audio_feats = self.audio_encoder(audio_values)
|
| 303 |
+
proj_audio = self.audio_projector(audio_feats) # [B_aud, N_aud, hidden_dim]
|
| 304 |
+
|
| 305 |
+
for b in range(bsz):
|
| 306 |
+
aud_mask = input_ids[b] == self.audio_token_id
|
| 307 |
+
aud_count = aud_mask.sum().item()
|
| 308 |
+
if aud_count > 0:
|
| 309 |
+
aud_tokens = proj_audio[min(b, proj_audio.shape[0] - 1)]
|
| 310 |
+
if len(aud_tokens) >= aud_count:
|
| 311 |
+
inputs_embeds[b, aud_mask] = aud_tokens[:aud_count]
|
| 312 |
+
else:
|
| 313 |
+
indices = torch.where(aud_mask)[0][: len(aud_tokens)]
|
| 314 |
+
inputs_embeds[b, indices] = aud_tokens
|
| 315 |
+
|
| 316 |
+
# Mask labels on image and audio placeholder tokens so loss is computed on response text
|
| 317 |
+
if labels is not None:
|
| 318 |
+
labels = labels.clone()
|
| 319 |
+
if self.image_token_id is not None:
|
| 320 |
+
labels[input_ids == self.image_token_id] = -100
|
| 321 |
+
if self.audio_token_id is not None:
|
| 322 |
+
labels[input_ids == self.audio_token_id] = -100
|
| 323 |
+
|
| 324 |
+
return self.language_model(
|
| 325 |
+
inputs_embeds=inputs_embeds,
|
| 326 |
+
attention_mask=attention_mask,
|
| 327 |
+
labels=labels,
|
| 328 |
+
**kwargs,
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
def generate(
|
| 332 |
+
self,
|
| 333 |
+
input_ids: torch.LongTensor,
|
| 334 |
+
pixel_values: Optional[torch.FloatTensor] = None,
|
| 335 |
+
audio_values: Optional[torch.FloatTensor] = None,
|
| 336 |
+
max_new_tokens: int = 50,
|
| 337 |
+
temperature: float = 0.7,
|
| 338 |
+
top_p: float = 0.9,
|
| 339 |
+
do_sample: bool = False,
|
| 340 |
+
**kwargs,
|
| 341 |
+
):
|
| 342 |
+
"""Multimodal text generation using fast KV cache decoding."""
|
| 343 |
+
# 1. Prefill step with vision and audio embedding injection
|
| 344 |
+
outputs = self(
|
| 345 |
+
input_ids=input_ids,
|
| 346 |
+
pixel_values=pixel_values,
|
| 347 |
+
audio_values=audio_values,
|
| 348 |
+
use_cache=True,
|
| 349 |
+
)
|
| 350 |
+
past_key_values = outputs.past_key_values
|
| 351 |
+
next_token_logits = outputs.logits[:, -1, :]
|
| 352 |
+
|
| 353 |
+
if do_sample and temperature > 0:
|
| 354 |
+
probs = torch.softmax(next_token_logits / temperature, dim=-1)
|
| 355 |
+
next_token = torch.multinomial(probs, num_samples=1)
|
| 356 |
+
else:
|
| 357 |
+
next_token = torch.argmax(next_token_logits, dim=-1, keepdim=True)
|
| 358 |
+
|
| 359 |
+
generated = [next_token]
|
| 360 |
+
cur_input_ids = next_token
|
| 361 |
+
|
| 362 |
+
# 2. Autoregressive decoding with KV cache
|
| 363 |
+
eos_id = kwargs.get("eos_token_id", getattr(self.config, "eos_token_id", None))
|
| 364 |
+
for _ in range(max_new_tokens - 1):
|
| 365 |
+
outputs = self.language_model(
|
| 366 |
+
input_ids=cur_input_ids,
|
| 367 |
+
past_key_values=past_key_values,
|
| 368 |
+
use_cache=True,
|
| 369 |
+
)
|
| 370 |
+
past_key_values = outputs.past_key_values
|
| 371 |
+
next_token_logits = outputs.logits[:, -1, :]
|
| 372 |
+
|
| 373 |
+
if do_sample and temperature > 0:
|
| 374 |
+
probs = torch.softmax(next_token_logits / temperature, dim=-1)
|
| 375 |
+
cur_input_ids = torch.multinomial(probs, num_samples=1)
|
| 376 |
+
else:
|
| 377 |
+
cur_input_ids = torch.argmax(next_token_logits, dim=-1, keepdim=True)
|
| 378 |
+
|
| 379 |
+
generated.append(cur_input_ids)
|
| 380 |
+
if eos_id is not None and (cur_input_ids == eos_id).all():
|
| 381 |
+
break
|
| 382 |
+
|
| 383 |
+
return torch.cat([input_ids] + generated, dim=-1)
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<|endoftext|>",
|
| 5 |
+
"clean_up_tokenization_spaces": false,
|
| 6 |
+
"eos_token": "<|endoftext|>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"extra_special_tokens": [
|
| 9 |
+
"<think>",
|
| 10 |
+
"</think>",
|
| 11 |
+
"<answer>",
|
| 12 |
+
"</answer>",
|
| 13 |
+
"<|image|>",
|
| 14 |
+
"<|audio|>",
|
| 15 |
+
"<tool_call>",
|
| 16 |
+
"</tool_call>",
|
| 17 |
+
"<tool_response>",
|
| 18 |
+
"</tool_response>",
|
| 19 |
+
"<|quad_space|>"
|
| 20 |
+
],
|
| 21 |
+
"is_local": false,
|
| 22 |
+
"local_files_only": false,
|
| 23 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 24 |
+
"pad_token": "<|pad|>",
|
| 25 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 26 |
+
"unk_token": "<|endoftext|>",
|
| 27 |
+
"vocab_size": 49152
|
| 28 |
+
}
|
training_state.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"last_completed_chunk": "interrupted_chunk_0095",
|
| 3 |
+
"next_chunk_idx": 95,
|
| 4 |
+
"global_step": 24185,
|
| 5 |
+
"stream_cursor": 95400,
|
| 6 |
+
"cumulative_tokens": 111749912,
|
| 7 |
+
"timestamp": "2026-10-07 14:34:03",
|
| 8 |
+
"is_interrupted": true
|
| 9 |
+
}
|
training_state.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:00c7206e4edb423170b54ea00c9bcce4bfa3012305fd0568b8be6f0be1182b8b
|
| 3 |
+
size 1167480986
|