Buckets:
| """Real single-GPU batch sweep; no microbatching or shortened history. | |
| Run each case in a fresh process. Capacity exclusions are distinguished from | |
| runtime OOM; persistent KV alone is a strict memory lower bound. | |
| """ | |
| import argparse | |
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| import subprocess | |
| import sys | |
| import statistics | |
| import torch | |
| from four_way import ROOT,elapsed | |
| from benchmark_widths import SyntheticModel | |
| def check_exclusive(): | |
| gpu=os.environ.get('CUDA_VISIBLE_DEVICES','0') | |
| result=subprocess.run(['nvidia-smi','-i',gpu,'--query-compute-apps=pid','--format=csv,noheader'],capture_output=True,text=True,check=True) | |
| other=[int(x.strip()) for x in result.stdout.splitlines() if x.strip().isdigit() and int(x.strip())!=os.getpid()] | |
| if other: | |
| raise RuntimeError(f'External compute processes on GPU {gpu}: {other}; refusing contaminated timing.') | |
| def case(variant,batch,context): | |
| check_exclusive() | |
| torch.set_num_threads(4) | |
| torch.backends.cuda.matmul.allow_tf32=False | |
| steps=8 | |
| model=SyntheticModel(variant) | |
| free,total=torch.cuda.mem_get_info() | |
| cache_bytes=batch*(context+steps)*model.cache_elements_per_token*2 | |
| row=dict(variant=variant,batch=batch,context=context,persistent_cache_bytes=cache_bytes, | |
| device_total_bytes=total,free_before_cache_bytes=free,config=model.config()) | |
| if cache_bytes>free: | |
| return dict(row,status='cache_exceeds_available_memory',reason='Persistent KV alone exceeds free GPU memory; no allocation attempted.') | |
| try: | |
| torch.manual_seed(5000) | |
| cache=model.cache(batch,context+steps) | |
| for v in cache.values():v.normal_(std=.2) | |
| ids=torch.randint(0,50257,(batch,steps),device='cuda') | |
| def run(): | |
| for j in range(steps):out=model.forward(ids[:,j:j+1],cache,context+j) | |
| return out | |
| for _ in range(3):run() | |
| ref=run().clone() | |
| graph=torch.cuda.CUDAGraph() | |
| torch.cuda.reset_peak_memory_stats() | |
| with torch.cuda.graph(graph):out=run() | |
| peak=torch.cuda.max_memory_allocated() | |
| graph.replay() | |
| torch.cuda.synchronize() | |
| error=float((ref.float()-out.float()).norm()/ref.float().norm()) | |
| assert error<.001,error | |
| # Long warmup also for small-batch cases; no clock setting changes. | |
| for _ in range(20):graph.replay() | |
| def repeat(): | |
| for _ in range(5):graph.replay() | |
| samples=[elapsed(repeat)[1]/(steps*5) for _ in range(7)] | |
| check_exclusive() | |
| ms=statistics.median(samples) | |
| return dict(row,status='ok',ms_per_step=ms,tokens_per_second=batch*1000/ms, | |
| samples=samples,graph_relative_l2=error,peak_allocated_bytes=peak) | |
| except torch.cuda.OutOfMemoryError as exc: | |
| return dict(row,status='runtime_oom',reason=str(exc)) | |
| def main(): | |
| parser=argparse.ArgumentParser() | |
| parser.add_argument('--variant') | |
| parser.add_argument('--batch',type=int) | |
| parser.add_argument('--context',type=int) | |
| args=parser.parse_args() | |
| if args.variant: | |
| row=case(args.variant,args.batch,args.context) | |
| path=ROOT/f'inference/results/batch_sweep_{args.variant}_b{args.batch}_t{args.context}.json' | |
| path.write_text(json.dumps(row,indent=2)+'\n') | |
| print(json.dumps(row),flush=True) | |
| return | |
| report=dict(physical_gpu=os.environ.get('CUDA_VISIBLE_DEVICES','0'),protocol='Current production Triton dispatch, A100 40GiB, BF16 synthetic weights seed5000, random historical compact cache, 8 growing decode steps, 20 graph warmups, 7 rounds of 5 replays. Full-model decode. No prefill, microbatching, offload or context truncation. Exclusive GPU checked before and after each successful case.', | |
| source_sha256={f:hashlib.sha256((ROOT/f).read_bytes()).hexdigest() for f in ['inference/four_way.py','inference/compact_triton.py','inference/benchmark_decode_batches.py']},results=[]) | |
| for batch in [1,8,64,512]: | |
| for context in [2048,8192,32768]: | |
| for variant in ['gqa','concat_64_16']: | |
| result=subprocess.run([sys.executable,__file__,'--variant',variant,'--batch',str(batch),'--context',str(context)],capture_output=True,text=True,env=os.environ.copy()) | |
| print(result.stdout,flush=True) | |
| if result.returncode: | |
| print(result.stderr,flush=True) | |
| raise RuntimeError((variant,batch,context,result.returncode)) | |
| path=ROOT/f'inference/results/batch_sweep_{variant}_b{batch}_t{context}.json' | |
| report['results'].append(json.loads(path.read_text())) | |
| (ROOT/'inference/results/decode_batch_sweep.json').write_text(json.dumps(report,indent=2)+'\n') | |
| if __name__=='__main__':main() | |
Xet Storage Details
- Size:
- 4.81 kB
- Xet hash:
- 587dc7685e6072c701b731f2b4caaceb3226358638608da736bcb6324cf65c35
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.