File size: 2,101 Bytes
27fd2eb
 
 
 
 
 
 
 
e4de392
27fd2eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4de392
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
---
library_name: transformers
tags:
- text-generation
- custom-code
- hybrid-attention
- state-space-model
- wikitext
- ml-intern
license: mit
datasets:
- Salesforce/wikitext
---

# Hybrid Tiny LM POC on WikiText-2

Proof-of-concept causal language model combining multiple token-mixing approaches:

- local/full causal self-attention for exact token lookup
- gated causal depthwise convolution for local pattern mixing
- input-gated diagonal recurrent mixer as a tiny SSM/RWKV-like compressed memory
- hybrid blocks that run attention + conv + recurrence in parallel and fuse them

Dataset: `Salesforce/wikitext`, config `wikitext-2-raw-v1`.
Tokenizer: `openai-community/gpt2`.

## POC metrics

```json
{
  "eval_loss": 7.388123512268066,
  "eval_runtime": 9.5676,
  "eval_samples_per_second": 26.757,
  "eval_steps_per_second": 3.345,
  "epoch": 0.78125,
  "perplexity": 1616.6696041601817,
  "train_loss": 7.8487934923172,
  "params": 10403040
}
```

This is intentionally tiny and trained briefly as an architecture POC, not a competitive LM.

## Reproduce

```bash
pip install "transformers>=4.54.0" datasets torch accelerate trackio
python hybrid_lm_poc.py \
  --max_steps 200 \
  --max_train_samples 2048 \
  --max_eval_samples 256 \
  --batch_size 8 \
  --d_model 96 \
  --n_layer 6 \
  --block_size 64 \
  --learning_rate 8e-4
```

Sample generation after the short run is in `sample_generation.txt`.

<!-- ml-intern-provenance -->
## Generated by ML Intern

This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.

- Try ML Intern: https://smolagents-ml-intern.hf.space
- Source code: https://github.com/huggingface/ml-intern

## Usage

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_id = 'rahulshetty/hybrid-tiny-wikitext-poc'
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id)
```

For non-causal architectures, replace `AutoModelForCausalLM` with the appropriate `AutoModel` class.