| import os |
| import sys |
| from huggingface_hub import HfApi, create_repo |
|
|
| def load_naman_token(): |
| env_file = "/home/adminuser/.env" |
| token = None |
| if os.path.exists(env_file): |
| with open(env_file, "r", encoding="utf-8") as f: |
| for line in f: |
| line = line.strip() |
| if line.startswith("NAMAN_HF_TOKEN="): |
| _, val = line.split("=", 1) |
| val = val.strip().strip("'").strip('"') |
| if val: |
| token = val |
| break |
| return token |
|
|
| def create_readme_card(repo_id): |
| return f"""--- |
| license: apache-2.0 |
| tags: |
| - mamba |
| - codestral-mamba |
| - qwen2.5 |
| - state-space-model |
| - benchmark |
| - evaluation |
| --- |
| |
| # MAMBA_7B: Codestral Mamba 7B Installation, Benchmarks & Architectural Research |
| |
| This repository contains the complete codebase, benchmark suite, evaluation datasets, research documents, and visual PowerPoint presentations for **MAMBA_7B**. |
| |
| Published to **namanadep** Hugging Face profile using `NAMAN_HF_TOKEN`. |
| |
| --- |
| |
| ## 📊 Summary Benchmark Metrics (Codestral Mamba 7B vs. Qwen 2.5 7B) |
| |
| | Metric | Codestral Mamba 7B | Qwen 2.5 7B Instruct | Takeaway | |
| | :--- | :---: | :---: | :--- | |
| | **Architecture** | **Selective State Space Model (SSM S6)** | **Multi-Head Self-Attention Transformer** | Mamba eliminates $O(N^2)$ quadratic KV-cache memory scaling. | |
| | **Average Latency** | **4.28s** | **7.40s** | **42.2% faster completion** for Codestral Mamba. | |
| | **Generation Speed** | **194.8 t/s** | **193.3 t/s** | Identical throughput on NVIDIA H200 GPUs. | |
| | **Memory Footprint** | **Constant $O(1)$ Memory State** | $O(N)$ Growth | Fixed VRAM up to 256k long-context reasoning. | |
| |
| --- |
| |
| ## 📂 Repository Layout & Uploaded Artifacts |
| |
| - `docs/CODESTRAL_MAMBA_7B_VS_QWEN_7B_COMPARISON.md`: 71 KB Exhaustive 10-Prompt Benchmark Report. |
| - `docs/CODESTRAL_MAMBA_7B_VS_QWEN_7B_COMPARISON.pptx`: 9-Slide Visual Benchmark Comparison Deck. |
| - `docs/MAMBA_7B_INSTALLATION_AND_ARCHITECTURE_GUIDE.pptx`: 8-Slide Hands-on Installation & Architecture Journey Deck. |
| - `docs/MAMBA_MODELS_RESEARCH_OLLAMA_HUGGINGFACE.md`: State Space Models Architectural Research Document. |
| - `data/mamba_vs_qwen_results.json`: Raw Evaluation JSON transcripts across 10 technical categories. |
| - `src/`: Complete Python benchmark test harness and slide generation scripts. |
| """ |
|
|
| def main(): |
| base_dir = "/home/adminuser/aiops_pocs/MAMBA_7B" |
| print("Loading NAMAN_HF_TOKEN from /home/adminuser/.env...") |
| token = load_naman_token() |
| if not token: |
| print("Error: Could not find NAMAN_HF_TOKEN in /home/adminuser/.env") |
| sys.exit(1) |
| |
| api = HfApi(token=token) |
| user_info = api.whoami() |
| username = user_info.get("name", "namanadep") |
| repo_id = f"{username}/MAMBA_7B" |
| |
| print(f"Authenticated as '{username}'. Creating repository: https://huggingface.co/{repo_id}...") |
| try: |
| create_repo(repo_id, token=token, exist_ok=True, repo_type="model") |
| print(f"Repository ready: https://huggingface.co/{repo_id}") |
| except Exception as e: |
| print(f"Repo creation status: {e}") |
|
|
| |
| readme_path = os.path.join(base_dir, "README.md") |
| with open(readme_path, "w", encoding="utf-8") as f: |
| f.write(create_readme_card(repo_id)) |
|
|
| print(f"Uploading files from {base_dir} to Hugging Face repository https://huggingface.co/{repo_id}...") |
| |
| |
| api.upload_file( |
| path_or_fileobj=readme_path, |
| path_in_repo="README.md", |
| repo_id=repo_id, |
| token=token |
| ) |
| print(" -> Uploaded README.md") |
|
|
| |
| docs_dir = os.path.join(base_dir, "docs") |
| if os.path.exists(docs_dir): |
| for fname in os.listdir(docs_dir): |
| fpath = os.path.join(docs_dir, fname) |
| if os.path.isfile(fpath): |
| api.upload_file( |
| path_or_fileobj=fpath, |
| path_in_repo=f"docs/{fname}", |
| repo_id=repo_id, |
| token=token |
| ) |
| print(f" -> Uploaded docs/{fname}") |
|
|
| |
| src_dir = os.path.join(base_dir, "src") |
| if os.path.exists(src_dir): |
| for fname in os.listdir(src_dir): |
| fpath = os.path.join(src_dir, fname) |
| if os.path.isfile(fpath): |
| api.upload_file( |
| path_or_fileobj=fpath, |
| path_in_repo=f"src/{fname}", |
| repo_id=repo_id, |
| token=token |
| ) |
| print(f" -> Uploaded src/{fname}") |
|
|
| |
| data_dir = os.path.join(base_dir, "data") |
| if os.path.exists(data_dir): |
| for fname in os.listdir(data_dir): |
| fpath = os.path.join(data_dir, fname) |
| if os.path.isfile(fpath): |
| api.upload_file( |
| path_or_fileobj=fpath, |
| path_in_repo=f"data/{fname}", |
| repo_id=repo_id, |
| token=token |
| ) |
| print(f" -> Uploaded data/{fname}") |
|
|
| print("==========================================================================") |
| print(f" Successfully published MAMBA_7B to Hugging Face: https://huggingface.co/{repo_id} ") |
| print("==========================================================================") |
|
|
| if __name__ == "__main__": |
| main() |
|
|