repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
cs249r_book | interviews/vault/visuals/cloud/cloud-2860.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
hours = np.arange(24)
traffic = 20 + 80 * np.exp(-((hours - 14)**2) / 4)
active_gpus = np.where((hours >= 13) & (hours <= 17), 100, 20)
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(hours, traffic, label='Traffic Demand', color='#c87b2a', linewidth=2)
ax.s... | 19 | 774 |
cs249r_book | interviews/vault/visuals/cloud/cloud-2851.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(8, 5))
stages = ['Network\nCapacity', 'PCIe Gen5\nCapacity', 'Required Load\n(Raw FP16)', 'Required Load\n(JPEG)']
bandwidths = [6.25, 128.0, 32.2, 1.0]
colors = ['#e74c3c', '#3498db', '#f39c12', '#2ecc71']
bars = ax.bar(stag... | 25 | 905 |
cs249r_book | interviews/vault/visuals/cloud/cloud-2859.py | .py | import os
import matplotlib.pyplot as plt
stages = ['S3 Read\n(5 GB/s)', 'CPU Decode\n(50 Cores)', 'PCIe Gen5\n(30 GB/s)', 'GPU Process\n(8x H100)']
capacity = [100, 100, 600, 400]
fig, ax = plt.subplots(figsize=(8, 4))
ax.bar(stages, capacity, color='#4a90c4')
ax.axhline(y=100, color='red', linestyle='--', label='Ta... | 14 | 559 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4501.py | .py | import os
import numpy as np
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 50)
y_uncontrolled = np.exp(x * 0.4)
y_controlled = np.clip(y_uncontrolled, 0, 15)
plt.plot(x, y_uncontrolled, color='#c87b2a', linestyle='--', label='Uncontrolled')
plt.plot(x, y_controlled, color='#3d9e5a', label='Admit Cap')
plt.lege... | 13 | 473 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4491.py | .py | import os
import matplotlib.pyplot as plt
stages = [1, 2, 3, 4]
start_times = [0, 1, 2, 3]
durations = [4, 4, 4, 4]
fig, ax = plt.subplots(figsize=(6, 4))
for i in range(4):
ax.barh(stages[i], durations[i], left=start_times[i], color='#3d9e5a')
ax.barh(stages[i], start_times[i], left=0, color='#fdebd0', hatch... | 18 | 585 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4525.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
intervals = np.linspace(0.5, 5, 50)
overhead = (intervals/2) + (24/intervals)*0.0833
fig, ax = plt.subplots(figsize=(5,3))
ax.plot(intervals, overhead, color='#c87b2a')
ax.axvline(2, color='red', linestyle='--', label='Optimal (2 hrs)')
ax.set_xlabel('Checkpo... | 12 | 474 |
cs249r_book | interviews/vault/visuals/cloud/cloud-2864.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
cats = ['Total HBM3', 'Allocation']
total = [192, 0]
w = [0, 140]
a = [0, 38.4]
k = [0, 13.6]
ax1.bar(cats, total, label='Total Capacity (192GB)', color='lightgray')
ax1.bar(cats, w, label='Weights (140GB)... | 23 | 862 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4526.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(5,2))
ax.barh(['vRAM'], [80], color='#cfe2f3', edgecolor='#4a90c4', label='H100 Capacity')
ax.barh(['KV Demand'], [85.9], color='#fdebd0', edgecolor='#c87b2a', label='KV Cache')
ax.set_xlabel('Gigabytes (GB)')
ax.legend(loc='lo... | 9 | 424 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4522.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6,3))
stages = np.arange(4)
for s in stages:
ax.barh(s, 10, left=s, color='#cfe2f3', edgecolor='#4a90c4')
ax.barh(s, s, left=0, color='#fdebd0', edgecolor='#c87b2a', hatch='//')
ax.set_ylabel('Pipeline Stage')
ax.set_xl... | 12 | 453 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4528.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(5,3))
stages = ['CPU', 'PCIe', 'GPU']
rates = [1, 64, 15]
ax.bar(stages, rates, color=['#fdebd0', '#d4edda', '#cfe2f3'], edgecolor=['#c87b2a', '#3d9e5a', '#4a90c4'])
ax.set_ylabel('Throughput (GB/s)')
plt.savefig(os.environ.get... | 9 | 386 |
cs249r_book | interviews/vault/visuals/cloud/cloud-4516.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
rho = np.linspace(0.1, 0.95, 50)
wait_mm1 = rho / (1 - rho)
wait_md1 = 0.5 * wait_mm1
plt.figure(figsize=(6, 3))
plt.plot(rho, wait_mm1, color='#c87b2a', label='M/M/1')
plt.plot(rho, wait_md1, color='#4a90c4', label='M/D/1')
plt.xlabel('Utilization (rho)')
... | 16 | 477 |
cs249r_book | interviews/vault/visuals/edge/edge-2343.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3))
stages = ['Stage 2', 'Stage 1']
ax.barh(1, 10, left=0, color='#cfe2f3', edgecolor='#4a90c4', label='Frame 1')
ax.barh(0, 10, left=10, color='#cfe2f3', edgecolor='#4a90c4')
ax.barh(1, 10, left=10, color='#d4edda', edgecolor='#3d9e5a', labe... | 15 | 576 |
cs249r_book | interviews/vault/visuals/edge/edge-2300.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,2))
ax.plot([0, 4], [0, 0], color='#4a90c4', linewidth=2, label='Deep Sleep')
ax.plot([4, 4], [0, 10], color='#c87b2a', linestyle='--')
ax.plot([4, 6], [10, 10], color='#3d9e5a', linewidth=2, label='Active Infer')
ax.set_yticks([])
ax.set_xlabe... | 11 | 444 |
cs249r_book | interviews/vault/visuals/edge/edge-2281.py | .py | import os
import matplotlib.pyplot as plt
labels = ['Shared RAM Capacity']
weights = [14]
os_mem = [2]
kv_cache = [16]
fig, ax = plt.subplots(figsize=(6,2))
ax.barh(labels, weights, label='Weights', color='#4a90c4')
ax.barh(labels, os_mem, left=weights, label='OS', color='#c87b2a')
ax.barh(labels, kv_cache, left=[16], ... | 13 | 469 |
cs249r_book | interviews/vault/visuals/edge/edge-2290.py | .py | import os
import matplotlib.pyplot as plt
plt.figure(figsize=(6, 2))
plt.barh(['Hailo-8'], [60], color='#4a90c4')
plt.xlim(0, 100)
plt.axvline(100, color='red', linestyle='--')
plt.xlabel('Utilization (%)')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig(out, format='svg', bbox_inches='tight') | 11 | 311 |
cs249r_book | interviews/vault/visuals/edge/edge-2352.py | .py | import os
import matplotlib.pyplot as plt
bw_types = ['Orin Available', 'Required (20 tok/s)']
values = [204.8, 280]
plt.figure(figsize=(6, 3))
plt.barh(bw_types, values, color=['#3d9e5a', '#c87b2a'])
plt.xlabel('Bandwidth (GB/s)')
plt.axvline(204.8, color='black', linestyle='--')
plt.title('Bandwidth Requirement vs ... | 12 | 429 |
cs249r_book | interviews/vault/visuals/edge/edge-2287.py | .py | import os
import matplotlib.pyplot as plt
labels = ['LPDDR5 Bandwidth', 'PCIe Bottleneck']
values = [204.8, 0]
plt.figure(figsize=(6, 4))
plt.bar(labels, values, color=['#3d9e5a', '#c87b2a'])
plt.ylabel('Bandwidth (GB/s)')
plt.title('Jetson Unified Memory')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savef... | 12 | 362 |
cs249r_book | interviews/vault/visuals/edge/edge-2355.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 4))
labels = ['L1 Cache (Est)', 'L2 Cache (Est)', 'LPDDR5']
bw = [2000, 800, 204.8]
ax.bar(labels, bw, color=['#cfe2f3', '#d4edda', '#fdebd0'], edgecolor='#4a90c4')
ax.set_ylabel('Bandwidth (GB/s)')
ax.set_title('AGX Orin Memory Tier Bandwidth... | 11 | 471 |
cs249r_book | interviews/vault/visuals/edge/edge-2362.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 4))
ax.barh(['Static Max', 'Paged KV'], [100, 15], color=['#fdebd0', '#cfe2f3'], edgecolor=['#c87b2a', '#4a90c4'])
ax.set_xlabel('Memory Allocated per Request (%)')
ax.set_title('KV Cache Memory Waste Avoidance')
plt.savefig(os.environ['VISUAL... | 7 | 367 |
cs249r_book | interviews/vault/visuals/edge/edge-2358.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 3))
ax.fill_between([0, 100, 100, 1000], [15, 15, 5, 5], color='#d4edda', alpha=0.7)
ax.plot([0, 100, 100, 1000], [15, 15, 5, 5], color='#3d9e5a', lw=2)
ax.set_xlabel('Time (ms)')
ax.set_ylabel('Power (W)')
ax.set_title('AGX Orin Frame Process... | 9 | 409 |
cs249r_book | interviews/vault/visuals/edge/edge-2351.py | .py | import os
import matplotlib.pyplot as plt
page_sizes = ['256-Token Page', '16-Token Page']
max_waste = [255, 15]
plt.figure(figsize=(6, 3))
plt.bar(page_sizes, max_waste, color=['#c87b2a', '#3d9e5a'], width=0.5)
plt.ylabel('Max Wasted Tokens')
plt.title('Internal Fragmentation Reduction')
plt.savefig(os.environ.get('... | 11 | 384 |
cs249r_book | interviews/vault/visuals/edge/edge-0976.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(8, 4))
# Data: [(start, duration), ...]
m4_tasks = [(0, 20), (20, 20), (40, 20)]
bt_tasks = [(20, 10), (40, 10), (60, 10)]
npu_tasks = [(30, 2), (50, 2), (70, 2)]
for i, (start, duration) in enumerate(m4_tasks):
ax.barh('M4 Compute', durati... | 23 | 901 |
cs249r_book | interviews/vault/visuals/edge/edge-2270.py | .py | import os
import matplotlib.pyplot as plt
tokens = [1, 512, 1024, 2048]
mem = [1/1024, 0.5, 1.0, 2.0]
plt.figure(figsize=(6,4))
plt.bar([str(t) for t in tokens], mem, color='#cfe2f3', edgecolor='#4a90c4')
plt.xlabel('Sequence Length')
plt.ylabel('KV Cache Size (GB)')
plt.tight_layout()
plt.savefig(os.environ.get('VISU... | 11 | 380 |
cs249r_book | interviews/vault/visuals/edge/edge-2354.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
rho = np.linspace(0, 0.95, 100)
wait = rho / (1 - rho)
fig, ax = plt.subplots(figsize=(5, 4))
ax.plot(rho, wait, color='#c87b2a', linewidth=2)
ax.set_xlabel('Utilization (ρ)')
ax.set_ylabel('Queueing Delay')
ax.set_title('Hockey Stick Curve: Latency vs Utiliz... | 12 | 421 |
cs249r_book | interviews/vault/visuals/edge/edge-0974.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
tiers = ['SRAM (256KB)', 'Flash (1MB)']
activations = [50, 0]
weights = [206, 94]
unused = [0, 930]
fig, ax = plt.subplots(figsize=(8, 3))
ax.barh(tiers, activations, label='Activations (50KB)', color='#fdebd0')
ax.barh(tiers, weights, left=activations, label... | 17 | 658 |
cs249r_book | interviews/vault/visuals/edge/edge-2369.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6,2))
ax.barh(['Recovery'], [2.0], color='#fdebd0', edgecolor='#c87b2a', label='SSD Read')
ax.set_xlabel('Time (s)')
ax.legend()
plt.savefig(os.environ.get('VISUAL_OUT_PATH', 'out.svg'), format='svg', bbox_inches='tight') | 8 | 314 |
cs249r_book | interviews/vault/visuals/edge/edge-2293.py | .py | import os
import matplotlib.pyplot as plt
phases = ['Crash', 'Rebooting', 'Reloading State', 'Active']
times = [0, 5, 2, 3]
colors = ['white', '#c87b2a', '#fdebd0', '#3d9e5a']
fig, ax = plt.subplots(figsize=(6, 2))
left = 0
for i in range(1, 4):
ax.barh('System Status', times[i], left=left, color=colors[i], label... | 17 | 548 |
cs249r_book | interviews/vault/visuals/edge/edge-2276.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
t = np.linspace(0, 2, 400)
power = np.where(t % 1.0 < 0.1, 2.5, 0.1)
plt.plot(t, power, color='#c87b2a', drawstyle='steps-pre')
plt.xlabel('Time (s)')
plt.ylabel('Power (W)')
plt.ylim(0, 3)
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig(out, f... | 11 | 353 |
cs249r_book | interviews/vault/visuals/edge/edge-2286.py | .py | import os
import matplotlib.pyplot as plt
time = [0, 20, 20, 100, 100, 120, 120, 200]
power = [2.5, 2.5, 0, 0, 2.5, 2.5, 0, 0]
plt.figure(figsize=(6, 3))
plt.fill_between(time, power, step='pre', color='#4a90c4', alpha=0.5)
plt.plot(time, power, color='#4a90c4', drawstyle='steps-pre')
plt.ylabel('Power (W)')
plt.xlabe... | 14 | 465 |
cs249r_book | interviews/vault/visuals/edge/edge-2296.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,2))
ax.broken_barh([(0,1)], (0,1), facecolors='#c87b2a', label='Reset (0.5s)')
ax.broken_barh([(1,4)], (0,1), facecolors='#cfe2f3', label='Reload (2.0s)')
ax.set_xlim(0, 6)
ax.set_yticks([])
ax.legend(loc='upper right')
out = os.environ.get('VI... | 10 | 398 |
cs249r_book | interviews/vault/visuals/edge/edge-2282.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,3))
colors = ['#cfe2f3', '#d4edda', '#fdebd0', '#4a90c4']
for i in range(4):
ax.broken_barh([(i*16, 16)], (40 - i*10, 8), facecolors=colors[i])
ax.set_yticks([14, 24, 34, 44])
ax.set_yticklabels(['Display', 'NPU', 'ISP', 'Sensor'])
ax.set_x... | 11 | 441 |
cs249r_book | interviews/vault/visuals/edge/edge-0977.py | .py | import os
import numpy as np
import matplotlib.pyplot as plt
rho = np.linspace(0.1, 0.95, 100)
queue_length = (rho**2) / (2 * (1 - rho))
fig, ax = plt.subplots(figsize=(6, 4))
ax.plot(rho, queue_length, color='#c87b2a', linewidth=2)
ax.axvline(x=0.9, color='red', linestyle='--', label='Current Load (0.9)')
ax.set_xla... | 19 | 614 |
cs249r_book | interviews/vault/visuals/edge/edge-2277.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
tiers = ['L1 Cache', 'L2 Cache', 'LPDDR5 Main']
bw = [2000, 800, 204.8]
plt.barh(tiers, bw, color=['#fdebd0', '#d4edda', '#cfe2f3'])
plt.xlabel('Theoretical Bandwidth (GB/s)')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig(out, format='svg', b... | 9 | 339 |
cs249r_book | interviews/vault/visuals/edge/edge-2271.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(4,4))
ax.bar(['Requested'], [150], label='CNN (150)', color='#cfe2f3')
ax.bar(['Requested'], [80], bottom=[150], label='GPU (80)', color='#fdebd0')
ax.axhline(204.8, color='red', linestyle='--', label='204.8 GB/s Limit')
ax.set_ylabel('Bandwidth... | 11 | 454 |
cs249r_book | interviews/vault/visuals/edge/edge-2280.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
rho = np.linspace(0.1, 0.9, 100)
wq = (rho * 20) / (2 * (1 - rho))
plt.plot(rho, wq, color='#4a90c4')
plt.axhline(40, color='#c87b2a', linestyle='--')
plt.axvline(0.8, color='#3d9e5a', linestyle=':')
plt.xlabel('Utilization (rho)')
plt.ylabel('Avg Queue Wait ... | 12 | 434 |
cs249r_book | interviews/vault/visuals/edge/edge-0979.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 5))
stages = ['Raw Data\n(5 GB/s)', 'Ring Buffer', 'A17 NE Filter', 'NVMe Storage']
volumes = [144, 144, 16, 16]
colors = ['#cfe2f3', '#cfe2f3', '#fdebd0', '#d4edda']
edges = ['#4a90c4', '#4a90c4', '#c87b2a', '#3d9e5a']
ax.bar(stages, volume... | 19 | 737 |
cs249r_book | interviews/vault/visuals/edge/edge-2297.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,2))
ax.broken_barh([(0,5)], (1, 1), facecolors='#fdebd0', label='Cold Start')
ax.broken_barh([(0,1)], (3, 1), facecolors='#d4edda', label='NVMe Reload')
ax.set_yticks([1.5, 3.5])
ax.set_yticklabels(['Without CP', 'With CP'])
ax.set_xlabel('Reco... | 10 | 438 |
cs249r_book | interviews/vault/visuals/edge/edge-2337.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 2))
ax.barh(['Bandwidth'], [60], color='#4a90c4', label='KV Cache (60 GB/s)')
ax.barh(['Bandwidth'], [144.8], left=[60], color='#d4edda', alpha=0.3, label='Headroom')
ax.axvline(204.8, color='red', linestyle='--', label='Orin Max (204.8 GB/s)'... | 10 | 478 |
cs249r_book | interviews/vault/visuals/edge/edge-2346.py | .py | import os
import matplotlib.pyplot as plt
batch_sizes = [1, 5, 11, 12]
memory_gb = [2.14 * b for b in batch_sizes]
plt.figure(figsize=(6, 3))
plt.bar(batch_sizes, memory_gb, color='#cfe2f3', edgecolor='#4a90c4')
plt.axhline(24, color='#c87b2a', linestyle='--', label='24GB Limit')
plt.xlabel('Batch Size')
plt.ylabel('... | 13 | 446 |
cs249r_book | interviews/vault/visuals/edge/edge-0972.py | .py | import os
import numpy as np
import matplotlib.pyplot as plt
# System parameters
mu = 50.0 # service rate (fps)
service_time_ms = (1.0 / mu) * 1000 # 20 ms
# Utilization
rho = np.linspace(0.01, 0.95, 100)
# M/D/1 Wait time: Wq = rho / (2*mu*(1-rho)) * 1000
# Total Latency = Wq + service_time
latency_md1 = (rho / (... | 41 | 1,578 |
cs249r_book | interviews/vault/visuals/edge/edge-2365.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6,3))
ax.bar(['15W Mode', '60W Mode'], [2.25, 3.0], color=['#d4edda', '#fdebd0'], edgecolor=['#3d9e5a', '#c87b2a'])
ax.set_ylabel('Energy per Inference (Joules)')
plt.savefig(os.environ.get('VISUAL_OUT_PATH', 'out.svg'), format... | 7 | 348 |
cs249r_book | interviews/vault/visuals/edge/edge-2359.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6,4))
ax.bar(['Sequential', 'Random Access'], [160, 30], color=['#cfe2f3', '#fdebd0'], edgecolor=['#4a90c4', '#c87b2a'])
ax.axhline(204.8, color='red', linestyle='--', label='Theoretical Peak (204.8)')
ax.set_ylabel('Effective Bandwidth (GB/s)')
... | 9 | 453 |
cs249r_book | interviews/vault/visuals/edge/edge-2363.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
rho = np.linspace(0.1, 0.95, 50)
latency = 1 / (50 * (1 - rho))
fig, ax = plt.subplots(figsize=(5,3))
ax.plot(rho, latency, color='#c87b2a')
ax.axvline(0.8, color='red', linestyle='--', label='80% Load (100ms)')
ax.set_xlabel('Utilization (rho)')
ax.set_ylabe... | 12 | 447 |
cs249r_book | interviews/vault/visuals/edge/edge-0982.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
T = np.linspace(50, 1000, 100)
C = 50
lam = 1/720
cost_waste = C / T
cost_fail = lam * T / 2
cost_total = cost_waste + cost_fail
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(T, cost_waste * 100, label='Checkpoint Overhead', color='#4a90c4', ls='--')
ax.pl... | 24 | 851 |
cs249r_book | interviews/vault/visuals/edge/edge-0980.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(8, 3))
t = np.linspace(0, 400, 4000)
power = np.where(t % 100 < 10, 5, 0.1)
ax.plot(t, power, color='#4a90c4', lw=2)
ax.set_title('VAD Duty Cycle Power Consumption')
ax.set_xlabel('Time (ms)')
ax.set_ylabel('Power (mW)')
ax.se... | 16 | 473 |
cs249r_book | interviews/vault/visuals/edge/edge-2340.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5, 3))
ax.barh(['LPDDR5', 'On-Chip SRAM'], [100, 2000], color=['#c87b2a', '#4a90c4'])
ax.set_xlabel('Bandwidth (GB/s)')
ax.set_title('Tier Bandwidth Profiles')
out_path = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
fig.savefig(out_path, format='... | 9 | 361 |
cs249r_book | interviews/vault/visuals/edge/edge-2294.py | .py | import os
import numpy as np
import matplotlib.pyplot as plt
rho = np.linspace(0, 0.95, 100)
delay = rho / (1 - rho)
plt.plot(rho, delay, color='#4a90c4', linewidth=2)
plt.xlabel('Utilization (rho)')
plt.ylabel('Queueing Delay')
plt.title('Delay Explosion')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig... | 11 | 360 |
cs249r_book | interviews/vault/visuals/edge/edge-2265.py | .py | import matplotlib.pyplot as plt
import numpy as np
import os
time = np.linspace(0, 10, 100)
# Arrival = 40 Hz, Service = 1000/25.5 = 39.2 Hz
queue_size = time * (40 - 39.21)
fig, ax = plt.subplots(figsize=(6, 3))
ax.plot(time, queue_size, color='#c87b2a', linewidth=2)
ax.set_xlabel('Time (s)')
ax.set_ylabel('Events i... | 18 | 550 |
cs249r_book | interviews/vault/visuals/edge/edge-2357.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5,4))
ax.bar(['16-token', '256-token'], [0.05, 0.45], color=['#cfe2f3', '#fdebd0'], edgecolor=['#4a90c4', '#c87b2a'])
ax.set_ylabel('Internal Fragmentation Ratio')
ax.set_title('PagedAttention KV Cache Fragmentation')
plt.savefig(os.environ['VISU... | 7 | 369 |
cs249r_book | interviews/vault/visuals/edge/edge-2367.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(6,2))
ax.barh([1], [10], left=[0], color='#cfe2f3', edgecolor='#4a90c4')
ax.barh([0], [15], left=[10], color='#d4edda', edgecolor='#3d9e5a')
ax.set_yticks([0, 1])
ax.set_yticklabels(['Recognition', 'Detection'])
ax.set_xlabel('... | 10 | 424 |
cs249r_book | interviews/vault/visuals/edge/edge-2350.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 2))
ax.plot([0, 1, 1, 3, 3, 5], [1, 1, 0, 0, 1, 1], color='#4a90c4', lw=2)
ax.axvspan(1, 3, color='#fdebd0', alpha=0.5, label='2s RTO Window')
ax.text(2, 0.5, 'Reboot & Restore', ha='center')
ax.set_yticks([])
ax.set_xlabel('Time (s)')
ax.leg... | 11 | 418 |
cs249r_book | interviews/vault/visuals/edge/edge-2283.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
rho = np.linspace(0.1, 0.95, 100)
queue_len = rho**2 / (1 - rho) # M/D/1 approx queue length
plt.plot(rho, queue_len, color='#4a90c4')
plt.axvline(0.8, color='#3d9e5a', linestyle='--', label='Operating Point')
plt.xlabel('Utilization (rho)')
plt.ylabel('Mean ... | 12 | 450 |
cs249r_book | interviews/vault/visuals/edge/edge-2361.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7, 3))
ax.plot([0, 10, 20, 30, 40], [0, 0.5, 0, 0.5, 0], color='#4a90c4', label='Local Delta')
ax.plot([0, 60], [0, 5], color='#c87b2a', linestyle='--', label='Cloud Full')
ax.set_xlabel('Time (min)')
ax.set_ylabel('Checkpoint Size (GB)')
ax.set_... | 10 | 444 |
cs249r_book | interviews/vault/visuals/edge/edge-0984.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(8, 3))
blocks = ['Sys Prompt\n(Sink)', 'Past Context', 'Evicted', 'Recent', 'Current\nGen']
values = [1.0, 1.0, 0.0, 1.0, 1.0]
colors = ['#4a90c4', '#4a90c4', '#fdebd0', '#4a90c4', '#3d9e5a']
bars = ax.bar(blocks, values, col... | 16 | 564 |
cs249r_book | interviews/vault/visuals/edge/edge-2295.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(5,3))
ax.barh(['Seq A', 'Seq B', 'Seq C'], [64, 32, 48], color='#cfe2f3', edgecolor='#4a90c4')
ax.set_xlabel('Allocated Pages')
plt.title('Paged KV Cache Allocation')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig(out, format='svg... | 8 | 343 |
cs249r_book | interviews/vault/visuals/edge/edge-2353.py | .py | import os
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(6, 2))
ax.scatter([0, 60], [1, 1], color='#3d9e5a', s=100, label='Checkpoint')
ax.axvspan(0, 59, color='#fdebd0', label='Unsaved Progress')
ax.axvline(59, color='#c87b2a', linestyle='--', label='Crash')
ax.set_yticks([])
ax.set_xlabel('Time (min... | 11 | 474 |
cs249r_book | interviews/vault/visuals/edge/edge-2292.py | .py | import os
import matplotlib.pyplot as plt
labels = ['x1 Lane', 'x4 Lanes']
bw = [0.985, 3.94]
plt.figure(figsize=(4, 4))
plt.bar(labels, bw, color='#4a90c4')
plt.ylabel('Bandwidth (GB/s)')
plt.title('PCIe Gen 3 Link')
out = os.environ.get('VISUAL_OUT_PATH', 'out.svg')
plt.savefig(out, format='svg', bbox_inches='tigh... | 13 | 323 |
cs249r_book | interviews/vault/visuals/edge/edge-2368.py | .py | import os
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(4,3))
ax.bar(['Capacity', 'Camera'], [204.8, 1.49], color=['#cfe2f3', '#fdebd0'], edgecolor=['#4a90c4', '#c87b2a'])
ax.set_ylabel('Bandwidth (GB/s)')
plt.savefig(os.environ.get('VISUAL_OUT_PATH', 'out.svg'), format='svg', bbox_... | 7 | 335 |
cs249r_book | interviews/vault/visuals/edge/edge-2266.py | .py | import matplotlib.pyplot as plt
import os
labels = ['Naive (Memcpy)', 'Zero-Copy (Unified)']
bw = [12.0, 6.0]
colors = ['#c87b2a', '#3d9e5a']
fig, ax = plt.subplots(figsize=(6, 2))
ax.barh(labels, bw, color=colors, edgecolor='black')
ax.set_xlabel('Unified Memory Bandwidth (GB/s)')
ax.set_title('Pipeline Bandwidth Op... | 15 | 461 |
cs249r_book | interviews/vault/schema/resolve.py | .py | #!/usr/bin/env python3
"""Topic resolver — maps old taxonomy fields to the new 79-topic system.
This is the bridge between the old corpus (primary_concept, reasoning_mode,
reasoning_competency, knowledge_area) and the new system (topic, zone).
Usage:
# As a library
from schema.resolve import resolve_topic, re... | 273 | 9,558 |
cs249r_book | interviews/vault/schema/zones.py | .py | """Ikigai competency zones — the mapping between zones and skills.
The four fundamental skills:
recall — facts, definitions, specifications
analyze — tradeoffs, reasoning, root cause analysis
design — architecture decisions, requirements-to-system
implement — napkin math, optimization, concrete... | 132 | 5,123 |
cs249r_book | interviews/vault/schema/enums.py | .py | """Single source of truth for Python enum values.
These values mirror ``question_schema.yaml`` (LinkML). That file is the
canonical schema; this module exists only to provide Python-importable
constants for validators and typed models that can't read LinkML directly.
Any change here MUST be mirrored in question_schem... | 223 | 9,716 |
cs249r_book | interviews/vault/schema/graph.py | .py | #!/usr/bin/env python3
"""Topic graph explorer — visualize and query the StaffML taxonomy.
Usage:
python3 graph.py # Full graph SVG
python3 graph.py --topic kv-cache-management # Neighborhood of one topic
python3 graph.py --area compute # Subgraph for one area
... | 349 | 13,181 |
cs249r_book | interviews/vault-cli/tests/test_legacy_export.py | .py | """Tests for the legacy-JSON exporter (v1.0)."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from vault_cli.legacy_export import (
emit_corpus_summary,
emit_legacy_corpus,
emit_manifest,
select_release_items,
)
from vault_cli.loader import LoadedQuestion
fro... | 248 | 9,314 |
cs249r_book | interviews/vault-cli/tests/test_yaml_io.py | .py | """Tests for the hardened YAML loader (REVIEWS.md H-7)."""
from __future__ import annotations
import pytest
from vault_cli.yaml_io import MAX_BYTES, VaultYamlError, load_bytes
def test_simple_mapping_loads() -> None:
assert load_bytes(b"a: 1\nb: 2\n") == {"a": 1, "b": 2}
def test_size_cap() -> None:
big ... | 32 | 883 |
cs249r_book | interviews/vault-cli/tests/test_policy.py | .py | """Tests for the release-policy filter.
Critical invariant (REVIEWS.md H-21): every exporter must call the SAME
policy.filter_questions function. This test is the runtime analogue; CI's
import-graph check is the static-analysis complement.
"""
from __future__ import annotations
from vault_cli.policy import filter_qu... | 58 | 1,625 |
cs249r_book | interviews/vault-cli/tests/test_book_refs.py | .py | """Tests for the topic → textbook chapter resolver and its link-checker."""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from vault_cli.book_refs import BookRefError, BookRefResolver
from vault_cli.legacy_export import emit_corpus_summary
from vault_cli.loader import LoadedQ... | 146 | 5,739 |
cs249r_book | interviews/vault-cli/tests/test_hashing.py | .py | """Tests for the canonical hashing layer.
Key invariants:
- Same semantic content hashes identically regardless of YAML key order.
- Whitelist fields drive the hash; metadata doesn't.
- Merkle construction stable across re-ordering of leaves.
"""
from __future__ import annotations
from vault_cli.hashing import CANON... | 124 | 4,081 |
cs249r_book | interviews/vault-cli/tests/test_models.py | .py | """Tests for the v0.1.2 Pydantic validators.
Three validators added in the 2026-04-25 release-readiness push:
1. Visual class hardening — kind enum, path regex, alt/caption min lengths.
2. Question._zone_bloom_compatible — zone × bloom_level matrix.
3. Question._visual_path_resolves — visual.path must point at a real... | 298 | 10,083 |
cs249r_book | interviews/vault-cli/tests/test_chain_validation.py | .py | """Tests for ``validate_chain`` in ``scripts/build_chains_with_gemini.py``.
Phase 1.3 of CHAIN_ROADMAP.md added a ``mode`` parameter that toggles the
allowed Bloom-level deltas:
strict → Δ ∈ {1, 2}
lenient → Δ ∈ {1, 2, 3}
These tests pin both directions: that lenient mode accepts a Δ=3
missing-rung jump str... | 198 | 6,177 |
cs249r_book | interviews/vault-cli/tests/test_smoke.py | .py | """Phase 0 smoke tests.
These assert the package imports, exposes a version, and the Typer app's
``--version`` flag returns cleanly. They are intentionally minimal —
per-command contract tests arrive in Phase 1.
"""
from __future__ import annotations
from typer.testing import CliRunner
from vault_cli import __versi... | 50 | 1,628 |
cs249r_book | interviews/vault-cli/tests/test_audit_batching.py | .py | """Smoke tests for the audit_corpus_batched batching helper.
Verifies that pack_batches:
- preserves every input item across batches (no dropped items)
- preserves input order within and across batches
- respects max_chars (batch payload character total stays within budget)
- respects max_items_per_batch (hard... | 99 | 3,358 |
cs249r_book | interviews/vault-cli/tests/test_authoring_scaffold.py | .py | """Tests for the `vault new` scaffold templates.
Guards against accidental removal or rewording of the markup-convention
markers in `vault new`'s scaffolded YAML. The format-compliance gate
(currently in validate_drafts.py; CORPUS_HARDENING_PLAN.md Phase 6
lifts it into vault check --strict) requires these exact bold ... | 60 | 2,274 |
cs249r_book | interviews/vault-cli/tests/test_commands.py | .py | """Tests for the newer subcommands: doctor, diff, stats, codegen.
These exercise the command surfaces end-to-end via Typer's CliRunner so a
stale --json schema, exit-code drift, or a regression in one of the
subchecks is caught in CI.
"""
from __future__ import annotations
import json
import sqlite3
from pathlib imp... | 154 | 5,981 |
cs249r_book | interviews/vault-cli/tests/test_ship.py | .py | """Tests for vault ship commit protocol (§6.1.1, Dean R3-NH-1)."""
from __future__ import annotations
from pathlib import Path
import pytest
from vault_cli.ship import LegPlan, LegState, ShipError, ShipJournal, ShipOutcome, run_ship
def test_all_legs_succeed(tmp_path: Path) -> None:
journal = tmp_path / ".shi... | 109 | 4,665 |
cs249r_book | interviews/vault-cli/tests/test_release.py | .py | """Tests for release pipeline primitives."""
from __future__ import annotations
import sqlite3
from pathlib import Path
from vault_cli.release import emit_migrations, snapshot
def _make_db(path: Path, rows: list[tuple]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
conn = sqlite3.connect(path)
... | 155 | 7,022 |
cs249r_book | interviews/vault-cli/scripts/check_schema_sync.py | .py | #!/usr/bin/env python3
"""Verify enums.py stays in sync with question_schema.yaml.
Runs in CI as a drift check. Exits non-zero if the hand-maintained Python
enum constants disagree with the authoritative LinkML schema.
Usage:
python3 interviews/vault-cli/scripts/check_schema_sync.py
"""
from __future__ import an... | 86 | 2,636 |
cs249r_book | interviews/vault-cli/scripts/_judges.py | .py | """Shared infrastructure for Gemini-judge gates across vault-cli scripts.
Extracted to keep the gate constants and the Gemini-call wrapper in one
place rather than duplicated across:
- validate_drafts.py (single-draft gate flow)
- audit_chains_with_gemini.py (chain audit)
- audit_math.py (math spot-c... | 215 | 8,604 |
cs249r_book | interviews/vault-cli/scripts/generate_question_for_gap.py | .py | #!/usr/bin/env python3
"""Author a candidate question to fill a chain gap (Phase 3.a).
Reads a gap entry (from gaps.proposed.json / gaps.proposed.lenient.json)
that names two existing questions and a missing Bloom level between
them, then prompts Gemini-3.1-pro-preview to draft a bridging question
that fits the (track... | 587 | 23,864 |
cs249r_book | interviews/vault-cli/scripts/audit_chains_with_gemini.py | .py | #!/usr/bin/env python3
"""Independent audit of the Phase 1-3 chain work via gemini-3.1-pro-preview.
Designed to be a complementary check on the output of the chain-build,
tier-classification, and gap-detection pipeline — running an
independent Gemini pass over the artifacts that human review would
otherwise have to sp... | 723 | 29,038 |
cs249r_book | interviews/vault-cli/scripts/ship_d1.py | .py | #!/usr/bin/env python3
"""Ship the current vault.db to the live Cloudflare D1 database.
Generates a full-reload SQL script (DROP + CREATE + INSERT) from a fresh
vault.db build, then applies it via `wrangler d1 execute --remote`.
Usage:
# Fresh build + push to production D1:
python3 interviews/vault-cli/script... | 133 | 5,134 |
cs249r_book | interviews/vault-cli/scripts/apply_proposed_chains.py | .py | #!/usr/bin/env python3
"""Apply a Gemini-proposed chains.json to replace the live registry.
Reads `interviews/vault/chains.proposed.json` (output of
build_chains_with_gemini.py), validates it against the YAML corpus and
chain invariants, and on success replaces `interviews/vault/chains.json`.
Validation:
- Every me... | 166 | 5,768 |
cs249r_book | interviews/vault-cli/scripts/calibrate_chain_embeddings.py | .py | #!/usr/bin/env python3
"""Calibrate which embedding model best discriminates real chain members.
Uses the existing 726 healthy chains as labeled ground truth:
positives = pairs of questions in the same chain
negatives = pairs of questions in the same (track, topic) bucket but
different chains, OR on... | 318 | 12,238 |
cs249r_book | interviews/vault-cli/scripts/fix_missing_metadata.py | .py | #!/usr/bin/env python3
"""Add explicit status / provenance / deletion_reason where the YAML is
silently relying on Pydantic defaults or violating soft-delete pairing.
Three classes of fix:
A. status field missing entirely
Pydantic defaults to 'draft', but the YAML on disk lacks the field.
Add explicit... | 102 | 3,199 |
cs249r_book | interviews/vault-cli/scripts/summarize_proposed_chains.py | .py | #!/usr/bin/env python3
"""Summarize a proposed chains.json — distribution, stats, sample inspection.
Run after build_chains_with_gemini.py to see what was produced before
applying. Produces a quick-read text report.
"""
from __future__ import annotations
import argparse
import json
from collections import Counter
fr... | 101 | 3,332 |
cs249r_book | interviews/vault-cli/scripts/promote_drafts.py | .py | #!/usr/bin/env python3
"""Promote LLM-authored question drafts to the corpus (Phase 3.d helper).
A draft is a `<id>.yaml.draft` file under `interviews/vault/questions/`,
written by `generate_question_for_gap.py`. Promotion does five things:
1. Strips the private ``_authoring`` block and replaces it with the
re... | 222 | 8,648 |
cs249r_book | interviews/vault-cli/scripts/normalize_chain_positions.py | .py | #!/usr/bin/env python3
"""One-shot: normalize chain positions to contiguous [1..N] per chain.
The Phase-1 split preserved legacy ``chain_ids[0]`` as each question's chain
and took ``position + 1`` from the legacy 0-indexed value. Legacy corpus had
multi-chain membership: a single question could appear in up to 4 chain... | 68 | 2,585 |
cs249r_book | interviews/vault-cli/scripts/emit_d1_schema.py | .py | #!/usr/bin/env python3
"""Emit the D1 schema DDL from the compiler module.
Output file lives at ``interviews/vault-cli/scripts/d1-schema.sql`` — committed
so ``wrangler d1 execute ... --file`` can apply it to a fresh D1 instance.
The schema fingerprint in wrangler.toml should be set to SHA-256 of the
normalized DDL (... | 39 | 1,145 |
cs249r_book | interviews/vault-cli/scripts/validate_drafts.py | .py | #!/usr/bin/env python3
"""Validate Gemini-authored draft questions (Phase 3.b).
For each ``*.yaml.draft`` under interviews/vault/questions/, run a
multi-gate scorecard:
1. schema — Pydantic Question model (same gate as published)
2. originality — cosine vs nearest neighbour in the same (track, topic);
... | 555 | 21,724 |
cs249r_book | interviews/vault-cli/scripts/backfill_provenance.py | .py | #!/usr/bin/env python3
"""Backfill the explicit ``provenance: imported`` line on YAMLs that lack it.
Pydantic was already filling ``provenance="imported"`` as a default at
load time, so this is a clarity-only fix: 407 published YAMLs in the
corpus have no explicit ``provenance:`` line, and we want every YAML to
carry ... | 149 | 5,200 |
cs249r_book | interviews/vault-cli/scripts/exemplar_coverage_audit.py | .py | #!/usr/bin/env python3
"""Phase-0 exemplar-coverage audit.
Reads the current ``corpus.json`` and reports the per-(track, level, zone) cell
distribution of questions, flagging cells with fewer than 3 eligible exemplars.
As of Phase 0, the corpus does not carry a ``provenance`` field (that lands with
the YAML split in ... | 145 | 5,114 |
cs249r_book | interviews/vault-cli/scripts/apply_format_skip_level.py | .py | #!/usr/bin/env python3
"""Apply marker-compliant common_mistake / napkin_math corrections for
published qids whose proposed format fix got skipped during Phase 5.
Phase 6 (schema tightening) wants a LinkML pattern requiring the
authoring markers (Pitfall/Rationale/Consequence and
Assumptions/Calculations/Conclusion). ... | 154 | 5,513 |
cs249r_book | interviews/vault-cli/scripts/merge_chain_passes.py | .py | #!/usr/bin/env python3
"""Merge primary (live) + secondary (lenient-sweep) chains into chains.json.
Phase 1.5 of CHAIN_ROADMAP.md. Inputs:
--primary <path> chains.json from the strict pass — entries are
backfilled tier="primary" if not already tagged
--secondary <path> chains.proposed.le... | 214 | 7,536 |
cs249r_book | interviews/vault-cli/scripts/build_chains_with_gemini.py | .py | #!/usr/bin/env python3
"""Build pedagogical chains within (track, topic) buckets via Gemini CLI.
For each bucket of published questions, prompts gemini-3.1-pro-preview to
identify natural chains (groups of 2-6 questions progressing through Bloom
levels, where one builds on another). Output is validated against the
cha... | 591 | 24,306 |
cs249r_book | interviews/vault-cli/scripts/cross_encoder_rerank_experiment.py | .py | #!/usr/bin/env python3
"""Quick experiment: does a cross-encoder rerank improve over bi-encoder?
Uses the same calibration set (existing chains) and measures whether reranking
the top-10 bi-encoder candidates with bge-reranker-base improves precision@1.
"""
from __future__ import annotations
import random
import tim... | 158 | 5,404 |
cs249r_book | interviews/vault-cli/scripts/apply_math_skip_level.py | .py | #!/usr/bin/env python3
"""Apply math-only corrections for the 13 qids whose level relabel was blocked.
Phase 5 verify_math_corrections.py applied 204 of 217 Gemini-verified math
fixes. The remaining 13 were skipped because their accompanying level
relabel violated chain monotonicity or was a relabel-up (against §10 Q3... | 149 | 5,366 |
cs249r_book | interviews/vault-cli/scripts/merge_audit_runs.py | .py | #!/usr/bin/env python3
"""Merge multiple audit_corpus_batched output dirs into one canonical run.
Phase 4's parallel runs split work by --tracks, each writing to its
own output dir. This script merges them into a single 01_audit.json
suitable for downstream consumers (apply_corrections.py,
summarize_audit.py).
Merge ... | 125 | 4,555 |
cs249r_book | interviews/vault-cli/scripts/audit_corpus_batched.py | .py | #!/usr/bin/env python3
"""Full-corpus audit of StaffML published questions, batched per Gemini call.
The single call audits 30-40 questions for ALL judge dimensions at once
(format compliance, level fit, scenario coherence, math correctness,
title quality), and optionally proposes corrections.
Cost (full corpus, 9,44... | 706 | 28,185 |
cs249r_book | interviews/vault-cli/scripts/apply_corrections.py | .py | #!/usr/bin/env python3
"""Interactive accept/reject for Gemini-proposed corrections.
Reads a 01_audit.json file produced by audit_corpus_batched.py
--propose-fixes, walks each row that has a non-empty
``suggested_corrections`` block, and prompts the operator to:
[a]ccept — apply the proposed correction(s) to the Y... | 481 | 18,019 |
cs249r_book | interviews/vault-cli/scripts/suggest_exemplars.py | .py | #!/usr/bin/env python3
"""Suggest candidate questions for the exemplar pool.
Queries vault.db for the highest-quality questions per topic, scored by:
- Has napkin_math (+3)
- Has common_mistake (+2)
- Solution length > 500 chars (+2)
- Scenario length > 300 chars (+1)
Outputs a ranked list and optionally a sh... | 118 | 3,983 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.