Mamba-7B-Reasoning / src /make_mamba_finetuning_pptx.py
namanadep's picture
Upload src/make_mamba_finetuning_pptx.py with huggingface_hub
aac646a verified
Raw
History Blame Contribute Delete
18.6 kB
import os
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.enum.text import PP_ALIGN
from pptx.dml.color import RGBColor
from pptx.enum.shapes import MSO_SHAPE
def create_proof_of_work_presentation():
pptx_path = "/home/adminuser/aiops_pocs/MAMBA_FINETUNING/docs/MAMBA_FINETUNING_PROOF_OF_WORK_PRESENTATION.pptx"
prs = Presentation()
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)
# Ultra-Premium Dark Theme Color Palette
COLOR_BG = RGBColor(11, 15, 25) # Deep Obsidian Slate
COLOR_CARD = RGBColor(30, 41, 59) # Slate 800
COLOR_CARD_DARK = RGBColor(20, 27, 44) # Slate 900
COLOR_CYAN = RGBColor(6, 182, 212) # Electric Cyan
COLOR_GREEN = RGBColor(16, 185, 129) # Emerald Green
COLOR_PURPLE = RGBColor(168, 85, 247) # Vivid Purple
COLOR_AMBER = RGBColor(245, 158, 11) # Radiant Amber
COLOR_TEXT = RGBColor(248, 250, 252) # Pure White Slate
COLOR_MUTED = RGBColor(148, 163, 184) # Slate Muted
def apply_bg(slide):
bg = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, 0, 0, Inches(13.333), Inches(7.5))
bg.fill.solid()
bg.fill.fore_color.rgb = COLOR_BG
bg.line.fill.background()
def add_header(slide, title_text, chapter_text="MY PROOF OF WORK"):
tb = slide.shapes.add_textbox(Inches(0.8), Inches(0.4), Inches(11.7), Inches(0.9))
tf = tb.text_frame
tf.word_wrap = True
p_cat = tf.paragraphs[0]
p_cat.text = chapter_text.upper()
p_cat.font.size = Pt(11)
p_cat.font.bold = True
p_cat.font.color.rgb = COLOR_CYAN
p_title = tf.add_paragraph()
p_title.text = title_text
p_title.font.size = Pt(24)
p_title.font.bold = True
p_title.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 1: Title Slide (First Person Proof of Work)
# -------------------------------------------------------------
slide1 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide1)
# Hero Card Background Container
hero_card = slide1.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.8), Inches(1.2), Inches(11.7), Inches(5.1))
hero_card.fill.solid()
hero_card.fill.fore_color.rgb = COLOR_CARD_DARK
hero_card.line.color.rgb = COLOR_GREEN
hero_card.line.width = Pt(2)
# Top Accent Line
line = slide1.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0.8), Inches(1.2), Inches(11.7), Inches(0.12))
line.fill.solid()
line.fill.fore_color.rgb = COLOR_GREEN
line.line.fill.background()
tb = slide1.shapes.add_textbox(Inches(1.2), Inches(1.6), Inches(10.9), Inches(4.2))
tf = tb.text_frame
tf.word_wrap = True
p1 = tf.paragraphs[0]
p1.text = "πŸ† PROOF OF WORK: LLM FINE-TUNING & EXPERIMENTATION"
p1.font.size = Pt(13)
p1.font.bold = True
p1.font.color.rgb = COLOR_GREEN
p2 = tf.add_paragraph()
p2.text = "How I Fine-Tuned Mamba 7B for Deep CoT Reasoning"
p2.font.size = Pt(34)
p2.font.bold = True
p2.font.color.rgb = COLOR_TEXT
p3 = tf.add_paragraph()
p3.text = "\nA first-person technical walkthrough detailing how I transformed a Selective State Space Model into a high-reasoning engine by instilling DeepSeek-R1 style Chain-of-Thought (<think>) capabilities on 2x NVIDIA H200 GPUs."
p3.font.size = Pt(15)
p3.font.color.rgb = COLOR_MUTED
# Stat Badges at Bottom
badges = [
("AUTHOR", "Naman Adep", COLOR_GREEN),
("DATASET", "16,710 CoT Samples", COLOR_CYAN),
("GPU CLUSTER", "2x NVIDIA H200 NVL", COLOR_PURPLE),
("COT TRIGGER", "100% Success Rate", COLOR_AMBER)
]
for idx, (b_title, b_val, b_color) in enumerate(badges):
x = Inches(1.2 + idx * 2.7)
b_box = slide1.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, Inches(4.8), Inches(2.5), Inches(1.1))
b_box.fill.solid()
b_box.fill.fore_color.rgb = COLOR_CARD
b_box.line.color.rgb = b_color
b_box.line.width = Pt(1)
b_tf = b_box.text_frame
b_tf.word_wrap = True
p_t = b_tf.paragraphs[0]
p_t.text = b_title
p_t.font.size = Pt(9)
p_t.font.bold = True
p_t.font.color.rgb = COLOR_MUTED
p_v = b_tf.add_paragraph()
p_v.text = b_val
p_v.font.size = Pt(12)
p_v.font.bold = True
p_v.font.color.rgb = b_color
# -------------------------------------------------------------
# SLIDE 2: Executive Summary & Proof of Work
# -------------------------------------------------------------
slide2 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide2)
add_header(slide2, "Executive Summary: What I Accomplished", "My Proof of Work")
pillars = [
("1. Data Pipeline Creation", "I processed 16,710 DeepSeek-R1 distilled reasoning samples into structured multi-turn conversation formats with explicit <think>...</think> tags.", COLOR_CYAN),
("2. Multi-GPU Fine-Tuning", "I adapted Mamba 7B's linear projection layers (in_proj, x_proj, dt_proj) using LoRA (rank=16) on 2x NVIDIA H200 NVL GPUs.", COLOR_GREEN),
("3. 50-Prompt Evaluation", "I built an automated evaluation harness testing 50 complex technical prompts across Math, Systems, Security, and AI Theory.", COLOR_PURPLE)
]
for idx, (title, desc, color) in enumerate(pillars):
x = Inches(0.8 + idx * 3.9)
card = slide2.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, Inches(1.6), Inches(3.6), Inches(5.2))
card.fill.solid()
card.fill.fore_color.rgb = COLOR_CARD
card.line.color.rgb = color
card.line.width = Pt(2)
bar = slide2.shapes.add_shape(MSO_SHAPE.RECTANGLE, x, Inches(1.6), Inches(3.6), Inches(0.1))
bar.fill.solid()
bar.fill.fore_color.rgb = color
bar.line.fill.background()
tf = card.text_frame
tf.word_wrap = True
p = tf.paragraphs[0]
p.text = title
p.font.size = Pt(17)
p.font.bold = True
p.font.color.rgb = color
p_d = tf.add_paragraph()
p_d.text = f"\n{desc}"
p_d.font.size = Pt(13)
p_d.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 3: Why Fine-Tuning Mamba Matters
# -------------------------------------------------------------
slide3 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide3)
add_header(slide3, "Why Fine-Tuning Mamba is a Game-Changer", "Architectural Vision")
c1 = slide3.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.8), Inches(1.6), Inches(5.6), Inches(5.2))
c1.fill.solid()
c1.fill.fore_color.rgb = COLOR_CARD
c1.line.color.rgb = COLOR_AMBER
c1.line.width = Pt(2)
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "⚠️ The Base Mamba Limitation"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_AMBER
b1 = [
"β€’ Base Mamba is blazingly fast but omits intermediate reasoning steps.",
"β€’ It jumps directly to final solutions, occasionally missing nuanced edge cases or intermediate algebraic derivations.",
"β€’ Lacks native Chain-of-Thought (<think>) internal reasoning traces."
]
for b in b1:
p = tf1.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
c2 = slide3.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(6.8), Inches(1.6), Inches(5.6), Inches(5.2))
c2.fill.solid()
c2.fill.fore_color.rgb = COLOR_CARD
c2.line.color.rgb = COLOR_GREEN
c2.line.width = Pt(2)
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "✨ What My Fine-Tuning Unlocks"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_GREEN
b2 = [
"β€’ Instills systematic step-by-step deconstruction before generating answers.",
"β€’ Combines Transformer-level reasoning quality with Mamba's constant O(1) memory efficiency.",
"β€’ Enables zero KV-cache VRAM inflation during 256k long-context reasoning."
]
for b in b2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 4: Quantitative Transformation Metrics
# -------------------------------------------------------------
slide4 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide4)
add_header(slide4, "Empirical Results: Before vs After Fine-Tuning", "Quantitative Metrics")
stats = [
("100%", "COT TRIGGER RATE", "Every query post-fine-tuning initiates explicit <think> reasoning steps.", COLOR_GREEN),
("1.85x", "CONTENT DENSITY", "Output expanded from 972 chars to 1,794 chars average due to detailed step derivations.", COLOR_CYAN),
("3.52s", "AVERAGE LATENCY", "Maintains sub-4-second response completion time while adding deep reasoning.", COLOR_PURPLE),
("O(1)", "VRAM EFFICIENCY", "Zero memory inflation during processing, retaining fixed recurrent state buffer.", COLOR_AMBER)
]
for idx, (num, label, desc, color) in enumerate(stats):
row = idx // 2
col = idx % 2
x = Inches(0.8 + col * 5.9)
y = Inches(1.6 + row * 2.6)
card = slide4.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, y, Inches(5.6), Inches(2.3))
card.fill.solid()
card.fill.fore_color.rgb = COLOR_CARD
card.line.color.rgb = color
card.line.width = Pt(1.5)
tf = card.text_frame
tf.word_wrap = True
p_num = tf.paragraphs[0]
p_num.text = num
p_num.font.size = Pt(36)
p_num.font.bold = True
p_num.font.color.rgb = color
p_lbl = tf.add_paragraph()
p_lbl.text = label
p_lbl.font.size = Pt(11)
p_lbl.font.bold = True
p_lbl.font.color.rgb = COLOR_MUTED
p_desc = tf.add_paragraph()
p_desc.text = desc
p_desc.font.size = Pt(12)
p_desc.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 5: Transformation Breakdown (Before vs After)
# -------------------------------------------------------------
slide5 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide5)
add_header(slide5, "Qualitative Comparison: Response Evolution", "Side-by-Side Case Study")
c1 = slide5.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.8), Inches(1.6), Inches(5.6), Inches(5.2))
c1.fill.solid()
c1.fill.fore_color.rgb = COLOR_CARD
c1.line.color.rgb = RGBColor(239, 68, 68)
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "πŸ”΄ Base Mamba 7B (Before Fine-Tuning)"
p.font.size = Pt(17)
p.font.bold = True
p.font.color.rgb = RGBColor(239, 68, 68)
b1 = [
"Prompt: Solve 3xΒ² + 14x - 5 = 0\n",
"Output:",
"3xΒ² + 14x - 5 = 0",
"(3x - 1)(x + 5) = 0",
"x = 1/3 or x = -5",
"\nβ€’ Characteristic: Direct answer, skipped factorization steps, no verification."
]
for b in b1:
p = tf1.add_paragraph()
p.text = b
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
c2 = slide5.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(6.8), Inches(1.6), Inches(5.6), Inches(5.2))
c2.fill.solid()
c2.fill.fore_color.rgb = COLOR_CARD
c2.line.color.rgb = COLOR_GREEN
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "🟒 Fine-Tuned Mamba 7B (After Fine-Tuning)"
p.font.size = Pt(17)
p.font.bold = True
p.font.color.rgb = COLOR_GREEN
b2 = [
"Output:",
"<think>",
"Step 1: Identify coefficients a=3, b=14, c=-5.",
"Step 2: Find numbers multiplying to -15 & adding to 14 (15 and -1).",
"Step 3: Factor by grouping: 3x(x+5) - 1(x+5) = (3x-1)(x+5).",
"Step 4: Verify via quadratic formula: x = (-14 Β± 16) / 6.",
"</think>",
"\nFinal Answer: x = 1/3, x = -5."
]
for b in b2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 6: Technical Implementation Highlights
# -------------------------------------------------------------
slide6 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide6)
add_header(slide6, "Technical Implementation & LoRA Architecture", "Fine-Tuning Setup")
box = slide6.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.8), Inches(1.6), Inches(11.7), Inches(5.2))
box.fill.solid()
box.fill.fore_color.rgb = COLOR_CARD
box.line.color.rgb = COLOR_CYAN
tf = box.text_frame
tf.word_wrap = True
p = tf.paragraphs[0]
p.text = "LoRA Target Modules & Hyperparameter Configuration"
p.font.size = Pt(16)
p.font.bold = True
p.font.color.rgb = COLOR_CYAN
code_text = """# My PyTorch & PEFT LoRA Configuration for Falcon Mamba 7B
peft_config = LoraConfig(
r=16, # LoRA Rank
lora_alpha=32, # Alpha Scaling Factor
target_modules=["in_proj", "x_proj", "dt_proj"], # SSM Linear Projection Layers
lora_dropout=0.05,
bias="none",
task_type=TaskType.CAUSAL_LM
)
# Training Parameters on 2x NVIDIA H200 NVL GPUs
training_args = TrainingArguments(
per_device_train_batch_size=4,
gradient_accumulation_steps=4,
learning_rate=2e-4, # Cosine Learning Rate Schedule
bf16=True, # Mixed Precision bfloat16
num_train_epochs=3
)"""
p_code = tf.add_paragraph()
p_code.text = code_text
p_code.font.size = Pt(12)
p_code.font.name = "Courier New"
p_code.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 7: Deliverables & Proof of Work Artifacts
# -------------------------------------------------------------
slide7 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide7)
add_header(slide7, "My Deliverables & Proof of Work Artifacts", "Code & Data")
artifacts = [
("πŸ“ Workspace Directory", "/home/adminuser/MAMBA_FINETUNING/", "Clean modular layout with docs/, src/, and data/ subdirectories.", COLOR_CYAN),
("πŸ“Š 50-Prompt Report", "docs/50_PROMPTS_MAMBA_BASE_VS_REASONING_COMPARISON.md", "215 KB side-by-side empirical benchmark report.", COLOR_GREEN),
("🐍 Training Pipeline", "src/train_mamba_reasoning.py & prepare_reasoning_dataset.py", "End-to-end dataset formatter & multi-GPU trainer.", COLOR_PURPLE),
("🎨 Presentation Decks", "docs/*.pptx", "Visual PowerPoint presentations ready for technical review.", COLOR_AMBER)
]
for idx, (title, path, desc, color) in enumerate(artifacts):
row = idx // 2
col = idx % 2
x = Inches(0.8 + col * 5.9)
y = Inches(1.6 + row * 2.6)
card = slide7.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, y, Inches(5.6), Inches(2.3))
card.fill.solid()
card.fill.fore_color.rgb = COLOR_CARD
card.line.color.rgb = color
card.line.width = Pt(1.5)
tf = card.text_frame
tf.word_wrap = True
p_t = tf.paragraphs[0]
p_t.text = title
p_t.font.size = Pt(16)
p_t.font.bold = True
p_t.font.color.rgb = color
p_p = tf.add_paragraph()
p_p.text = path
p_p.font.size = Pt(11)
p_p.font.bold = True
p_p.font.name = "Courier New"
p_p.font.color.rgb = COLOR_MUTED
p_d = tf.add_paragraph()
p_d.text = desc
p_d.font.size = Pt(12)
p_d.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 8: Conclusion & Summary
# -------------------------------------------------------------
slide8 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide8)
add_header(slide8, "Conclusion: The Power of Fine-Tuned SSMs", "Final Summary")
c1 = slide8.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.8), Inches(1.6), Inches(5.6), Inches(5.2))
c1.fill.solid()
c1.fill.fore_color.rgb = COLOR_CARD
c1.line.color.rgb = COLOR_GREEN
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "🎯 Core Breakthrough"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_GREEN
b1 = [
"β€’ Fine-tuning proves that Mamba models can master deep, multi-step Chain-of-Thought (<think>) reasoning.",
"β€’ Bridges the reasoning gap between Transformers and State Space Models.",
"β€’ Delivers high-level mathematical and algorithmic correctness without sacrificing sub-4-second response latency."
]
for b in b1:
p = tf1.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
c2 = slide8.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(6.8), Inches(1.6), Inches(5.6), Inches(5.2))
c2.fill.solid()
c2.fill.fore_color.rgb = COLOR_CARD
c2.line.color.rgb = COLOR_CYAN
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "πŸš€ Future Applications"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_CYAN
b2 = [
"1. Real-Time IDE Autocomplete with CoT context validation.",
"2. Long-Context Document Reasoning (256k tokens) with zero KV-cache memory crashes.",
"3. High-throughput edge server deployments running lightweight reasoning models."
]
for b in b2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
prs.save(pptx_path)
print("Successfully created First-Person Proof of Work Mamba presentation:", pptx_path)
if __name__ == "__main__":
create_proof_of_work_presentation()