# Safetensors Studio & Bench > **Run, test, and benchmark local Safetensors models with surgical VRAM observability.** [![Next.js](https://img.shields.io/badge/Next.js-14-black?logo=next.js)](https://nextjs.org/) [![FastAPI](https://img.shields.io/badge/FastAPI-0.110-009688?logo=fastapi)](https://fastapi.tiangolo.com/) [![Python](https://img.shields.io/badge/Python-3.12-3776AB?logo=python)](https://www.python.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE) [![Hugging Face](https://img.shields.io/badge/๐Ÿค—-Hugging%20Face-FFD21E)](./docs/HUGGINGFACE.md) **Safetensors Studio & Bench** is a full-stack, local-first platform to **load any `*.safetensors` + `config.json` + `tokenizer.json` folder, stream chat with real TPS/TTFT, run automated benchmarks (Reasoning/Coding/Arabic/Summarization), and profile GPU/CPU/RAM live** โ€” no cloud required. ๐Ÿ“– **Arabic README:** [`README_AR.md`](./README_AR.md) | ๐Ÿ“š **Docs:** [`docs/`](./docs/) | ๐Ÿค **Contribute:** [`CONTRIBUTING.md`](./CONTRIBUTING.md) --- ## โœจ Key Features | Area | What you get | |------|--------------| | **Safetensors Loader** | Local folder picker โ€ข `Float16 / Bfloat16 / Float32` โ€ข `4-bit NF4 / 8-bit` via `bitsandbytes` โ€ข `device_map: auto / balanced / cpu / cuda:0` + offloading | | **Live Playground** | Token Streaming (SSE) โ€ข Real `Tokens/sec` & `TTFT` โ€ข Temperature / Top-P / Max Tokens โ€ข Copy & clear | | **Automated Benchmark** | 15 preset tasks: Reasoning (4), Coding (4), Arabic Quality (4), Summarization (3) โ€ข `Exact / Regex / LLM-as-Judge` โ€ข **Custom datasets:** drop any folder with `.csv/.json/.jsonl/.txt/.md` โ†’ auto-detects language (Arabic/English) & category | | **Hardware Profiling** | `pynvml + psutil` โ†’ live VRAM/CPU/RAM/Power via `Recharts` โ€ข VRAM peak timeline โ€ข TPS vs VRAM scatter โ€ข 600-point history | | **Reports & Sharing** | Export `PDF (Arabic-capable)` / `JSON` / `CSV` โ€ข Shareable link `/share/{token}` โ€ข Full tables + `by_category` insights | --- ## ๐ŸŒ Supported Languages | Language | Coverage | |----------|----------| | **English** | UI, prompts, docs, code, benchmarks (`Reasoning`, `Coding`, `Summarization`) | | **Arabic (ุงู„ุนุฑุจูŠุฉ)** | Full UI RTL, benchmarks (`Arabic Quality`, `Summarization`), PDF with `tahoma.ttf` + `arabic-reshaper`, auto-detection `\u0600-\u06FF` for custom datasets | | **Mixed** | Auto `language_counts: {ar, en}` per folder, per report | > Add a new language: add prompts to `backend/app/benchmark.py:14` and categories to `dataset_parser.py:11`. See [`SUPPORTED_LANGUAGES.md`](./SUPPORTED_LANGUAGES.md). --- ## ๐Ÿš€ Quick Start ### 1. Requirements - Node 22+ / Python 3.12+ - 8GB RAM minimum (CPU mode), 12GB+ VRAM recommended for 7B models on GPU ### 2. Backend ```bash cd backend pip install -r requirements.txt # torch CPU + transformers are included # optional GPU: pip install torch --index-url https://download.pytorch.org/whl/cu121 uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload # โ†’ http://localhost:8000/docs ``` ### 3. Frontend ```bash cd frontend npm install npm run dev # โ†’ http://localhost:3000 # env: frontend/.env.local โ†’ NEXT_PUBLIC_API_URL=http://localhost:8000 ``` ### 4. Docker (alternative) ```bash docker compose up --build # frontend http://localhost:3000 backend http://localhost:8000 ``` ### 5. Load a model - Place a HF-style folder anywhere, e.g. `C:\models\mistral-7b` containing `model.safetensors`, `config.json`, `tokenizer.json` - In UI `/` or `/models` or **new:** top bar of `/benchmark` โ†’ paste path โ†’ `Validate` โ†’ `Load` - Or via API: `POST /api/model/load {"model_path":"C:\\models\\my-model","dtype":"float16","quantization":"4bit","device_map":"auto"}` > **No GPU?** The platform auto-enters **Demo Mode** (simulated generation) so you can still test all features. --- ## ๐Ÿ“ Project Structure ``` backend/app/ main.py # FastAPI + CORS + routers model_manager.py # Safetensors loader (torch dtype/quant/device_map) telemetry.py # pynvml/psutil + 600-point history benchmark.py # 15 tasks + evaluate_answer() dataset_parser.py # CSV/JSON/JSONL/TXT/MD โ†’ BenchmarkTask + lang detect schemas.py routers/{model,inference,telemetry,benchmark,custom_benchmark,share,export}.py frontend/src/ app/{page, playground, benchmark, hardware, models, share/[token]} components/{ModelLoader, ModelPathSelector, Playground, BenchmarkPanel, CustomDatasetPanel, TelemetryCharts} lib/{api.ts, utils.ts} example_dataset/ # 9-task mixed sample (AR/EN) docs/ # English developer docs ``` --- ## ๐Ÿ”Œ API Reference (core) | Method | Path | Description | |--------|------|-------------| | `POST` | `/api/model/load` | Load Safetensors folder | | `GET` | `/api/model/status` | Loaded info | | `GET` | `/api/model/validate?path=` | Check `*.safetensors + config.json` | | `POST` | `/api/generate` (SSE) | Stream tokens with `ttft_ms`, `tokens_per_sec` | | `GET` | `/api/telemetry/` | Snapshot (VRAM/GPU/CPU/RAM) | | `WS` | `/ws/telemetry` | Live push (fallback to HTTP polling) | | `POST` | `/api/benchmark/run` | Sync benchmark (blocking) | | `POST` | `/api/benchmark/run-stream` | **SSE progress** (`type: progress/task_done/done`) | | `POST` | `/api/benchmark/custom/scan?folder_path=` | Scan custom folder | | `POST` | `/api/benchmark/custom/run-from-folder` | Run on custom folder | | `POST` | `/api/benchmark/custom/upload` | Multipart upload | | `POST` | `/api/share/{report_id}` | Create share token | | `GET` | `/api/share/{token}` | Fetch shared report | | `GET` | `/api/export/{json,csv,pdf}?report_id=` | Export | Full spec: http://localhost:8000/docs --- ## ๐Ÿงช Benchmark Suites | Suite | Tasks | Judge | |-------|-------|-------| | `reasoning` | arithmetic, sequence, logic puzzle, fraction | Regex `\b7\b` | | `coding` | fibonacci, loop output, reverse_string, sorted | Regex `def\s+` | | `arabic` | spelling, synonym, i'rab, summarization | Regex `ุฐู‡ุจุช`, `ูุฑุญ` | | `summarization` | tech text, Transformer, bullet points | Regex `7 ู…ู„ูŠุงุฑ` | Custom folder example (`CSV`): ``` prompt,expected,expected_regex,category,name "ู…ุง ู…ุฑุงุฏู ุณุนูŠุฏุŸ",ูุฑุญ,ูุฑุญ,arabic,syn ``` --- ## ๐Ÿ“Š Hardware Profiling - `telemetry.py:19` polls `pynvml.nvmlDeviceGetMemoryInfo` + `psutil.virtual_memory` every 1.2s - `Recharts` Area/Line/Scatter: VRAM timeline, CPU/RAM %, Power vs VRAM, TPS vs VRAM - `vram_peak_mb` tracked per task and globally --- ## ๐Ÿ“„ Export & Sharing - **PDF:** Unicode via `tahoma.ttf` + `arabic-reshaper` + `python-bidi` (fallback to `?` sanitization) - **Share:** in-memory `share_store[token]=report_id` โ†’ `/share/{token}` page --- ## ๐Ÿ› ๏ธ Development See [`docs/DEVELOPMENT.md`](./docs/DEVELOPMENT.md) and [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md). ```bash # Frontend npm run build # production npm run lint # Backend python -m pytest # (add tests) pip install -r requirements.txt ``` --- ## ๐Ÿค— Hugging Face - Use any HF model: download `snapshots` and point `model_path` to it. - Model card template: [`docs/HUGGINGFACE.md`](./docs/HUGGINGFACE.md) - Dataset parser auto-handles HF `datasets` exported as JSONL/CSV. --- ## ๐Ÿค Contributing Please read [`CONTRIBUTING.md`](./CONTRIBUTING.md) and [`CODE_OF_CONDUCT.md`](./CODE_OF_CONDUCT.md). PRs for new languages, benchmarks, and quant backends are welcome! ## ๐Ÿ”’ Security See [`SECURITY.md`](./SECURITY.md). ## ๐Ÿ“ License MIT โ€” see [`LICENSE`](./LICENSE). --- Built with โค๏ธ for local AI โ€” no cloud, full control.