Instructions to use namanadep/Mamba-7B-Reasoning with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use namanadep/Mamba-7B-Reasoning with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Upload docs/MAMBA_REASONING_FINETUNING_PLAN.md with huggingface_hub
Browse files
docs/MAMBA_REASONING_FINETUNING_PLAN.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Implementation Plan: Fine-Tuning Mamba 7B for Deep Chain-of-Thought Reasoning
|
| 2 |
+
|
| 3 |
+
This project aims to fine-tune a 7-billion parameter State Space Model (**Mamba 7B**) to endow it with native **DeepSeek-R1 style Chain-of-Thought (`<think>`) internal reasoning capabilities**.
|
| 4 |
+
|
| 5 |
+
Mamba's constant $O(1)$ memory state and $O(N)$ linear-time complexity make it exceptionally efficient. Infusing it with deep step-by-step CoT reasoning allows Mamba to perform complex mathematical logic, system architecture design, and algorithm derivation without suffering from Transformer KV-cache memory expansion.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## π― Primary Goals
|
| 10 |
+
|
| 11 |
+
1. **Dataset Pipeline**: Download and format a high-density DeepSeek-R1 distilled reasoning dataset ([`BespokeLabs/Bespoke-Stratos-17k`](https://huggingface.co/datasets/BespokeLabs/Bespoke-Stratos-17k) or [`open-thoughts/OpenThoughts-114k`](https://huggingface.co/datasets/open-thoughts/OpenThoughts-114k)) into standard multi-turn chat format with explicit `<think>...</think>` tags.
|
| 12 |
+
2. **Multi-GPU SFT Fine-Tuning**: Execute fine-tuning of Mamba 7B (`tiiuae/falcon-mamba-7b-instruct` or `mistralai/mamba-codestral-7b`) on 2x NVIDIA H200 NVL GPUs (282 GB VRAM) utilizing PyTorch, `transformers`, and optimized `mamba-ssm` CUDA kernels.
|
| 13 |
+
3. **Reasoning Benchmark Evaluation**: Evaluate the fine-tuned Mamba Reasoning model against the base Mamba 7B on 100 complex mathematical, logical, and software architecture benchmarks.
|
| 14 |
+
4. **GGUF Export & Ollama Registration**: Convert merged weights to F16 GGUF and register in local Ollama as `mamba-7b-reasoning:latest`.
|
| 15 |
+
5. **Hugging Face Publication**: Publish adapter weights, GGUF binary, Model Card, and benchmark report to Hugging Face (`namanadep/Mamba-7B-Reasoning`).
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
## ποΈ Proposed Architecture & File Layout
|
| 20 |
+
|
| 21 |
+
All code, scripts, configuration, and documentation will reside in `/home/adminuser/aiops_pocs/MAMBA_FINETUNING/` (symlinked as `/home/adminuser/MAMBA_FINETUNING/`). All datasets, heavy model weights, checkpoints, and GGUF binaries will reside under `/data/pocs_models_and_checkpoints/MAMBA_FINETUNING/`.
|
| 22 |
+
|
| 23 |
+
### Directory Structure:
|
| 24 |
+
```
|
| 25 |
+
/home/adminuser/MAMBA_FINETUNING/
|
| 26 |
+
βββ docs/ # Documentation & Walkthroughs
|
| 27 |
+
β βββ MAMBA_REASONING_FINETUNING_PLAN.md
|
| 28 |
+
βββ src/ # Source Code Pipeline
|
| 29 |
+
β βββ config.py # Project & Model Paths Configuration
|
| 30 |
+
β βββ prepare_reasoning_dataset.py # Dataset Processing & CoT Formatting
|
| 31 |
+
β βββ train_mamba_reasoning.py # Multi-GPU Fine-Tuning Training Script
|
| 32 |
+
β βββ eval_reasoning_prompts.py # 100-Prompt Pre/Post CoT Evaluation
|
| 33 |
+
β βββ build_reasoning_report.py # Benchmark Markdown Builder
|
| 34 |
+
β βββ export_and_register_ollama.py # GGUF Conversion & Ollama Registration
|
| 35 |
+
β βββ push_to_hub.py # Hugging Face Publisher
|
| 36 |
+
βββ data -> /data/pocs_models_and_checkpoints/MAMBA_FINETUNING/data
|
| 37 |
+
βββ results -> /data/pocs_models_and_checkpoints/MAMBA_FINETUNING/results
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## π οΈ Step-by-Step Proposed Changes
|
| 43 |
+
|
| 44 |
+
### Component 1: Dataset Preparation (`src/prepare_reasoning_dataset.py`)
|
| 45 |
+
- Load `BespokeLabs/Bespoke-Stratos-17k` / `open-thoughts/OpenThoughts-114k`.
|
| 46 |
+
- Format system prompt: `"You are an advanced AI reasoning assistant powered by a Selective State Space Model. You solve complex problems step-by-step using internal reasoning traces wrapped in <think>...</think> tags."`
|
| 47 |
+
- Structure response into:
|
| 48 |
+
```
|
| 49 |
+
<think>
|
| 50 |
+
Step 1: Deconstruct the problem constraints...
|
| 51 |
+
Step 2: Derive the mathematical or algorithmic formulation...
|
| 52 |
+
</think>
|
| 53 |
+
Final Solution / Executable Code...
|
| 54 |
+
```
|
| 55 |
+
- Output splits: `train.jsonl` (15,000 items), `val.jsonl` (1,500 items), `eval_100_prompts.jsonl` (100 holdout prompts).
|
| 56 |
+
|
| 57 |
+
### Component 2: Multi-GPU Training Engine (`src/train_mamba_reasoning.py`)
|
| 58 |
+
- Base Model: `tiiuae/falcon-mamba-7b-instruct` or `mistralai/mamba-codestral-7b`.
|
| 59 |
+
- Fine-Tuning Setup: SFTTrainer with `bf16` precision across 2x H200 GPUs.
|
| 60 |
+
- Target Module Adaptations for SSM: `in_proj`, `out_proj`, `x_proj`, `dt_proj`.
|
| 61 |
+
- Save adapter weights to `/data/pocs_models_and_checkpoints/MAMBA_FINETUNING/results/adapter`.
|
| 62 |
+
|
| 63 |
+
### Component 3: Benchmark Evaluation & Report (`src/eval_reasoning_prompts.py`)
|
| 64 |
+
- Compare Base Mamba 7B vs. Fine-Tuned Mamba Reasoning 7B across 100 holdout prompts.
|
| 65 |
+
- Evaluate `<think>` CoT trigger rate, reasoning depth, and mathematical correctness.
|
| 66 |
+
|
| 67 |
+
### Component 4: Export, Ollama Registration & HF Publish
|
| 68 |
+
- Convert merged model to GGUF using `llama.cpp`'s `convert_hf_to_gguf.py`.
|
| 69 |
+
- Register as `mamba-7b-reasoning:latest` in Ollama.
|
| 70 |
+
- Upload to Hugging Face repository `namanadep/Mamba-7B-Reasoning`.
|
| 71 |
+
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## π¬ Verification & Validation Plan
|
| 75 |
+
|
| 76 |
+
1. **Automated Training Check**: Confirm training loss convergence (e.g. initial `3.50` $\rightarrow$ final `1.20` validation loss).
|
| 77 |
+
2. **CoT Reasoning Verification**: Test generated outputs for mandatory `<think>...</think>` internal reasoning blocks.
|
| 78 |
+
3. **Local Ollama Functionality**: Verify instant execution via `ollama run mamba-7b-reasoning:latest`.
|
| 79 |
+
4. **Hugging Face Live Verification**: Inspect model card, files, and GGUF download link on Hugging Face.
|