amos-1-mini-CoreAI / smoke_mini.py
maxffarrell's picture
Pin reproducible runtime dependencies and checkpoint-specific export settings
27ca70c verified
Raw History Blame Contribute Delete
1.21 kB
import asyncio,json
from pathlib import Path
import torch
from coreai_mini import AmosMini
async def main():
def forbidden(*a,**kw):raise AssertionError('PyTorch neural execution is forbidden in runtime smoke')
torch.nn.Linear.forward=forbidden;torch.nn.Embedding.forward=forbidden;torch.nn.Conv2d.forward=forbidden
root=Path('bundles/amos-1-mini-CoreAI');m=await AmosMini.load(root)
out=await m.request({'state':'Please refund the duplicate charge.','questions':{'refund':{'type':'noul','instructions':'Is a refund requested?'}}})
assert out['answers']['refund']['noul']>0.5,out
from PIL import Image
image_result=await m.predict('A red image.',[{'type':'region','text':'Point to the red area.'}],[Image.new('RGB',(360,240),'red')])
assert image_result[0]['type']=='region'
try:await m.predict('word '*1000,[{'type':'noul','text':'Is there text?'}])
except ValueError:capacity_guard=True
else:raise AssertionError('Over-capacity request was accepted')
(root/'runtime-smoke.json').write_text(json.dumps({'passed':True,'pytorch_neural_execution_disabled':True,'capacity_guard':capacity_guard,'result':out,'image_result':image_result},indent=2))
print(out)
if __name__=='__main__':asyncio.run(main())