DebasishDhal99's picture
feat: add explanation on `hidden_size = num_attention_heads * dim_per_head`
4ed3b70
|
Raw History Blame Contribute Delete
1.83 kB
---
title: RoPE Embedding Visualization
emoji: πŸ“š
colorFrom: gray
colorTo: green
sdk: gradio
sdk_version: 6.26.0
python_version: 3.11
app_file: app.py
pinned: false
short_description: Visualize how RoPE rotates query and key vectors
---
# RoPE Explorer
Interactive Gradio app for **Rotary Position Embedding**. The Hugging Face Space
runs `app.py` (`sdk: gradio`). Local Docker (`Dockerfile`, `compose.yaml`) is for
running `python app.py` on port **7860**.
Production math lives in [`src/`](src/) (`rope.py`, `absolute_pe.py`, `extract.py`,
`plots.py`). Scratch scripts under `rope_implementation/`,
`absolute_sinusoidal_position_embedding/`, and `relative_pos_embedding/` are
learning notes only and are **not** imported by the app.
## Modes
1. **Random matrix** β€” sample even-width Q (and K) tensors, apply numpy RoPE,
inspect heatmaps, pairwise 2D rotation, `QK^T`, and additive sinusoidal PE.
2. **Real model** β€” lazy-load an ungated Llama-like checkpoint (default
`HuggingFaceTB/SmolLM2-135M`; `HuggingFaceM4/tiny-random-LlamaForCausalLM`
is included for a very small test model), take `embed_tokens`, first-layer `q_proj` /
`k_proj` (GQA-aware), and compare educational numpy RoPE (`llama` pairing)
to the model's `rotary_emb`. No Hugging Face token is required. Gated models
are not used.
First load of a model downloads weights into the cache; later runs reuse the
last loaded model in memory.
CPU is enough for SmolLM2 and Qwen2.5-0.5B. TinyLlama is included for a larger
example and may be slow on CPU. This Space does **not** require ZeroGPU
(`@spaces.GPU` is unused).
## Local run
```bash
pip install -r requirements.txt
python app.py
```
Or `docker compose up`. Hugging Face Cloud uses the README YAML (`sdk: gradio`),
not the Docker image, unless the Space SDK is switched to Docker.