MAMBA_7B / src /make_mamba_pptx.py
namanadep's picture
Upload src/make_mamba_pptx.py with huggingface_hub
b9259a1 verified
Raw
History Blame Contribute Delete
19.7 kB
import os
import json
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_presentation():
pptx_path = "/home/adminuser/aiops_pocs/MAMBA_7B/CODESTRAL_MAMBA_7B_VS_QWEN_7B_COMPARISON.pptx"
json_path = "/home/adminuser/aiops_pocs/MAMBA_7B/mamba_vs_qwen_results.json"
with open(json_path, "r", encoding="utf-8") as f:
benchmarks = json.load(f)
prs = Presentation()
prs.slide_width = Inches(13.333)
prs.slide_height = Inches(7.5)
# Color Palette
COLOR_BG = RGBColor(15, 23, 42) # Slate 900
COLOR_CARD = RGBColor(30, 41, 59) # Slate 800
COLOR_ACCENT = RGBColor(6, 182, 212) # Cyan 500
COLOR_MAMBA = RGBColor(16, 185, 129) # Emerald 500
COLOR_QWEN = RGBColor(59, 130, 246) # Blue 500
COLOR_TEXT = RGBColor(248, 250, 252) # Slate 50
COLOR_MUTED = RGBColor(148, 163, 184) # Slate 400
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, category_text="BENCHMARK ANALYSIS"):
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 = category_text.upper()
p_cat.font.size = Pt(11)
p_cat.font.bold = True
p_cat.font.color.rgb = COLOR_ACCENT
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
# -------------------------------------------------------------
slide1 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide1)
tb = slide1.shapes.add_textbox(Inches(1.0), Inches(2.2), Inches(11.3), Inches(3.2))
tf = tb.text_frame
tf.word_wrap = True
p1 = tf.paragraphs[0]
p1.text = "TECHNICAL BENCHMARK & ARCHITECTURAL EVALUATION"
p1.font.size = Pt(14)
p1.font.bold = True
p1.font.color.rgb = COLOR_ACCENT
p2 = tf.add_paragraph()
p2.text = "Codestral Mamba 7B vs. Qwen 2.5 7B"
p2.font.size = Pt(38)
p2.font.bold = True
p2.font.color.rgb = COLOR_TEXT
p3 = tf.add_paragraph()
p3.text = "Empirical comparison of Selective State Space Models (SSM) vs Multi-Head Self-Attention Transformers across 10 Technical Benchmarks on NVIDIA H200 GPUs"
p3.font.size = Pt(16)
p3.font.color.rgb = COLOR_MUTED
# -------------------------------------------------------------
# SLIDE 2: Executive Summary
# -------------------------------------------------------------
slide2 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide2)
add_header(slide2, "Executive Summary & Core Findings", "Overview")
cards = [
("42.2% Faster Completion", "Codestral Mamba 7B achieved an average query latency of 4.28s vs Qwen 2.5's 7.40s, delivering ultra-fast time-to-first-token.", COLOR_MAMBA),
("~195 Tokens / Sec Speed", "Both models saturated hardware limits at ~194.8 t/s (Mamba) vs ~193.3 t/s (Qwen) on NVIDIA H200 NVL GPUs.", COLOR_ACCENT),
("2.25x Explanation Density", "Qwen 2.5 7B generated 4,347 chars/response vs Mamba's 1,930 chars, providing rich docstrings & edge cases.", COLOR_QWEN),
("Constant O(1) Memory State", "Mamba maintains a fixed recurrent state buffer, eliminating KV-cache VRAM expansion at long context (up to 256k).", COLOR_MAMBA)
]
for idx, (title, desc, color) in enumerate(cards):
row = idx // 2
col = idx % 2
x = Inches(0.8 + col * 5.9)
y = Inches(1.6 + row * 2.6)
card = slide2.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(18)
p_t.font.bold = True
p_t.font.color.rgb = color
p_d = tf.add_paragraph()
p_d.text = desc
p_d.font.size = Pt(13)
p_d.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 3: Architectural Mechanics (SSM vs Transformer)
# -------------------------------------------------------------
slide3 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide3)
add_header(slide3, "Architectural Mechanics: Selective SSM vs. Self-Attention", "Deep Dive")
# Left Card: Mamba
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_MAMBA
c1.line.width = Pt(2)
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "🟢 Codestral Mamba 7B (Selective SSM S6)"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_MAMBA
bullets1 = [
"• Core Mechanism: Input-dependent Selective State Space Model (S6).",
"• Time Complexity: O(N) Linear scaling with sequence length.",
"• Hardware Scanning: Parallel associative scan algorithm utilizing SRAM.",
"• Memory Footprint: Recurrent O(1) constant-size hidden state buffer.",
"• Key Advantage: Zero KV-cache VRAM inflation during 256k long-context inference."
]
for b in bullets1:
p = tf1.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
# Right Card: Qwen Transformer
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_QWEN
c2.line.width = Pt(2)
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "🔵 Qwen 2.5 7B (Multi-Head Self-Attention)"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_QWEN
bullets2 = [
"• Core Mechanism: Multi-Head Self-Attention with Rotary Position Embeddings (RoPE).",
"• Time Complexity: O(N²) Quadratic attention scaling.",
"• Hardware Optimization: FlashAttention-2 & deep Tensor Core integration.",
"• Memory Footprint: Grows linearly per token (KV Cache memory inflation).",
"• Key Advantage: Deep global contextual reasoning, extensive docstring synthesis."
]
for b in bullets2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 4: Quantitative Performance Table
# -------------------------------------------------------------
slide4 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide4)
add_header(slide4, "Quantitative Benchmark Performance Summary", "Metrics")
rows = len(benchmarks) + 1
cols = 7
table_shape = slide4.shapes.add_table(rows, cols, Inches(0.8), Inches(1.5), Inches(11.7), Inches(5.3))
table = table_shape.table
headers = ["ID", "Technical Task Title", "Mamba Time", "Qwen Time", "Mamba Speed", "Qwen Speed", "Output Delta"]
widths = [Inches(0.6), Inches(4.5), Inches(1.3), Inches(1.3), Inches(1.3), Inches(1.3), Inches(1.4)]
for idx, w in enumerate(widths):
table.columns[idx].width = w
for c_idx, h in enumerate(headers):
cell = table.cell(0, c_idx)
cell.fill.solid()
cell.fill.fore_color.rgb = COLOR_CARD
p = cell.text_frame.paragraphs[0]
p.text = h
p.font.size = Pt(11)
p.font.bold = True
p.font.color.rgb = COLOR_ACCENT
for r_idx, b in enumerate(benchmarks, start=1):
m = b["mamba"]
q = b["qwen"]
delta = f"+{(q['char_len'] - m['char_len'])/m['char_len']*100:.0f}% Qwen"
vals = [
f"{b['id']:02d}",
b["title"],
f"{m['time_sec']:.2f}s",
f"{q['time_sec']:.2f}s",
f"{m['tps']} t/s",
f"{q['tps']} t/s",
delta
]
for c_idx, val in enumerate(vals):
cell = table.cell(r_idx, c_idx)
cell.fill.solid()
cell.fill.fore_color.rgb = RGBColor(20, 30, 48) if r_idx % 2 == 0 else COLOR_BG
p = cell.text_frame.paragraphs[0]
p.text = val
p.font.size = Pt(10)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 5: Benchmark Category 1 - Algorithms & Data Structures
# -------------------------------------------------------------
slide5 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide5)
add_header(slide5, "Benchmark Spotlight: Algorithms & Data Structures", "Test 01 & 02")
# Test 1 Card
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
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "Test 01: Lock-Free LRU Cache in Python"
p.font.size = Pt(16)
p.font.bold = True
p.font.color.rgb = COLOR_ACCENT
p = tf1.add_paragraph()
p.text = "• Mamba (7.16s | 1,504 chars):\nLeveraged collections.OrderedDict for a minimal, working 15-line implementation. Extremely fast & compact.\n\n• Qwen 2.5 (24.97s | 4,970 chars):\nBuilt full double-linked node class, explicit generic typing, thread safety locks, comprehensive docstrings & edge cases."
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
# Test 2 Card
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
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "Test 02: Red-Black Tree Balancing in C++"
p.font.size = Pt(16)
p.font.bold = True
p.font.color.rgb = COLOR_ACCENT
p = tf2.add_paragraph()
p.text = "• Mamba (6.56s | 4,200 chars):\nProduced clean C++ rotation logic (left/right rotate) and color fixup helper methods directly without boilerplate.\n\n• Qwen 2.5 (8.19s | 5,793 chars):\nGenerated full C++ template struct, explicit enum Color { RED, BLACK }, driver main() function, and memory destruction logic."
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 6: Benchmark Category 2 - System Engineering & eBPF
# -------------------------------------------------------------
slide6 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide6)
add_header(slide6, "Benchmark Spotlight: Systems Engineering & eBPF", "Test 03 & 04")
# Test 3 Card
c1 = slide6.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
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "Test 03: Asyncio WebSockets Gateway"
p.font.size = Pt(16)
p.font.bold = True
p.font.color.rgb = COLOR_ACCENT
p = tf1.add_paragraph()
p.text = "• Mamba (6.13s | 3,398 chars):\nConcise Python asyncio server with heartbeat ping/pong & token check middleware.\n\n• Qwen 2.5 (5.46s | 4,874 chars):\nFull async server architecture with sliding-window rate limiting, signal handlers for graceful shutdown, and client connection registry."
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
# Test 4 Card
c2 = slide6.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
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "Test 04: Linux eBPF Packet Tracing (C/BCC)"
p.font.size = Pt(16)
p.font.bold = True
p.font.color.rgb = COLOR_ACCENT
p = tf2.add_paragraph()
p.text = "• Mamba (3.32s | 1,147 chars):\nShort eBPF C snippet hooking kprobe/sys_enter_connect with basic BCC python print loop.\n\n• Qwen 2.5 (4.56s | 2,947 chars):\nDetailed C eBPF kernel program using BPF_HASH maps, IP byte-order conversions, error checking, and formatted BCC CLI table output."
p.font.size = Pt(12)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 7: Strategic Comparison - Codestral Mamba 7B
# -------------------------------------------------------------
slide7 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide7)
add_header(slide7, "Model Profile: Codestral Mamba 7B", "Mistral AI")
c1 = slide7.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_MAMBA
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "🌟 Core Strengths & Advantages"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_MAMBA
b1 = [
"1. Ultra-Low Latency: 42.2% faster average response completion.",
"2. Constant O(1) Memory State: Eliminates KV-cache VRAM expansion at long context (up to 256k tokens).",
"3. High Code Autocomplete Efficiency: Delivers direct, fluff-free code snippets instantly.",
"4. High Throughput: ~194.8 t/s generation speed on H200 GPUs."
]
for b in b1:
p = tf1.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
c2 = slide7.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 = RGBColor(239, 68, 68)
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "⚠️ Known Bottlenecks & Trade-offs"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = RGBColor(239, 68, 68)
b2 = [
"1. Minimal Inline Documentation: Frequently omits docstrings, type hints, and code comments.",
"2. Concise Edge-Case Handling: May require follow-up prompts to handle complex exception paths.",
"3. Higher Recurrent State Complexity: Requires custom SSM CUDA kernels for peak training."
]
for b in b2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 8: Strategic Comparison - Qwen 2.5 7B Instruct
# -------------------------------------------------------------
slide8 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide8)
add_header(slide8, "Model Profile: Qwen 2.5 7B Instruct", "Alibaba Cloud")
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_QWEN
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "🌟 Core Strengths & Advantages"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_QWEN
b1 = [
"1. Exhaustive Code Density: 2.25x higher output character count (4,347 chars avg).",
"2. Complete Edge-Case Coverage: Includes explicit error checking, logging, and type hints.",
"3. Superior Explanatory Power: Accompanies code with thorough architectural breakdowns.",
"4. Versatile Multi-Domain Logic: Excellent performance across math proofs, code & general QA."
]
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 = RGBColor(239, 68, 68)
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "⚠️ Known Bottlenecks & Trade-offs"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = RGBColor(239, 68, 68)
b2 = [
"1. Higher Total Response Time: Takes 7.40s avg due to generating comprehensive explanations.",
"2. Transformer Memory Expansion: O(N) KV-cache growth at extreme long contexts (32k+ tokens)."
]
for b in b2:
p = tf2.add_paragraph()
p.text = b
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
# -------------------------------------------------------------
# SLIDE 9: Production Deployment Roadmap
# -------------------------------------------------------------
slide9 = prs.slides.add_slide(prs.slide_layouts[6])
apply_bg(slide9)
add_header(slide9, "Strategic Production Deployment Roadmap", "Recommendations")
c1 = slide9.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_MAMBA
tf1 = c1.text_frame
tf1.word_wrap = True
p = tf1.paragraphs[0]
p.text = "🚀 Deploy Codestral Mamba 7B For:"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_MAMBA
recs1 = [
"1. Real-Time IDE Inline Autocomplete:\nInstant sub-second code completions where speed is critical.",
"2. Massive Repository Context Processing:\nProcessing 100k+ token codebases without VRAM KV-cache exhaustion.",
"3. High-Throughput Streaming API Microservices:\nLow-cost, low-latency microservice integrations."
]
for r in recs1:
p = tf1.add_paragraph()
p.text = r
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
c2 = slide9.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_QWEN
tf2 = c2.text_frame
tf2.word_wrap = True
p = tf2.paragraphs[0]
p.text = "🚀 Deploy Qwen 2.5 7B Instruct For:"
p.font.size = Pt(18)
p.font.bold = True
p.font.color.rgb = COLOR_QWEN
recs2 = [
"1. Full-Stack System Architecture Design:\nGenerating complete production microservices with docstrings.",
"2. Automated Refactoring & Unit Test Suites:\nCreating high-coverage pytest/unittest suites with mocks.",
"3. Complex Debugging & Security Auditing:\nComprehensive race condition and memory leak repair."
]
for r in recs2:
p = tf2.add_paragraph()
p.text = r
p.font.size = Pt(13)
p.font.color.rgb = COLOR_TEXT
prs.save(pptx_path)
print("Successfully generated PowerPoint presentation:", pptx_path)
if __name__ == "__main__":
create_presentation()