File size: 2,571 Bytes
87cc7f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Short independent hardware-value benchmark, not a math evaluation."""
import os

import modal,json
from pathlib import Path
app=modal.App('modelclinic-gpu-value');vol=modal.Volume.from_name(os.environ.get("MODELCLINIC_MODAL_VOLUME", "modelclinic-cache"),create_if_missing=False)
image=(modal.Image.debian_slim(python_version='3.11').pip_install('torch==2.8.0').pip_install('transformers==5.20.2','accelerate==1.12.0','huggingface-hub==2.4.0','safetensors==0.8.0','math-verify==0.9.0').add_local_file('code/src/long_protocol.py','/root/project/long_protocol.py'))
@app.function(image=image,gpu='A10',volumes={'/cache':vol},cpu=2,memory=8192,timeout=360,scaledown_window=2)
def bench():
 import time,sys,torch
 from transformers import AutoTokenizer,Qwen3_5ForConditionalGeneration,LogitsProcessorList
 sys.path.insert(0,'/root/project');from long_protocol import build_prompt,GeneratedPresencePenalty
 vol.reload();t0=time.monotonic();torch.set_num_threads(2);torch.set_grad_enabled(False)
 p='/cache/modelclinic/base-2fc06364715b967f1860aea9cf38778875588b17';tok=AutoTokenizer.from_pretrained(p,local_files_only=True);m=Qwen3_5ForConditionalGeneration.from_pretrained(p,dtype=torch.bfloat16,local_files_only=True).eval().to('cuda');v=tok.apply_chat_template([{'role':'user','content':build_prompt('What is the sum of 11 and 13?')}],tokenize=True,add_generation_prompt=True,enable_thinking=True,return_tensors='pt');x=(v['input_ids'] if hasattr(v,'keys') else v).to('cuda');torch.manual_seed(0);torch.cuda.manual_seed_all(0);start=time.monotonic()
 with torch.inference_mode():out=m.generate(input_ids=x,max_new_tokens=1024,min_new_tokens=1024,max_time=180,do_sample=True,temperature=.6,top_p=.95,top_k=20,logits_processor=LogitsProcessorList([GeneratedPresencePenalty(x.shape[1])]),pad_token_id=tok.eos_token_id,use_cache=True)
 torch.cuda.synchronize();elapsed=time.monotonic()-start;n=out.shape[1]-x.shape[1];return {'gpu':torch.cuda.get_device_name(),'tokens':n,'generation_seconds':elapsed,'total_function_seconds':time.monotonic()-t0,'tokens_per_second':n/elapsed,'note':'1024-token synthetic prompt throughput; longer-context throughput can differ'}
@app.local_entrypoint()
def main():
 handles={g:bench.with_options(gpu=g).spawn() for g in ['A10','L40S','H100']};out={}
 for g,h in handles.items():
  try:out[g]=h.get(timeout=300);print(g,json.dumps(out[g]),flush=True)
  except Exception as e:out[g]={'error':str(e)};print(g,'error',str(e),flush=True)
 Path('results/long_diagnostic/gpu_value.json').write_text(json.dumps(out,indent=2))