Download predict_example.py from ya9919/sharp-322m-mlx: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/ya9919/sharp-322m-mlx/resolve/main/predict_example.py
- Command line
-
hf download hf://ya9919/sharp-322m-mlx/predict_example.py
-
curl -L -o predict_example.py https://huggingface.co/ya9919/sharp-322m-mlx/resolve/main/predict_example.py
1.1 kB
| """Run an independent synthetic structured-choice example.""" | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument('--backend', choices=('torch', 'mlx'), default='torch') | |
| parser.add_argument('--model', type=Path, default=Path(__file__).resolve().parent) | |
| parser.add_argument('--request', type=Path) | |
| parser.add_argument('--device') | |
| parser.add_argument('--output', type=Path) | |
| args = parser.parse_args() | |
| request = json.loads((args.request or args.model / 'example_request.json').read_text(encoding='utf-8')) | |
| if args.backend == 'mlx': | |
| from laya_mlx.agent import Agent | |
| agent = Agent(str(args.model), dtype='float32', device=args.device) | |
| else: | |
| import torch | |
| from laya.agent import Agent | |
| torch.set_num_threads(4) | |
| agent = Agent(str(args.model), device=args.device or 'cuda', compile=False) | |
| result = agent.predict(request['state'], request['questions']) | |
| serialized = json.dumps(result, ensure_ascii=False, indent=2) + '\n' | |
| if args.output: | |
| args.output.write_text(serialized, encoding='utf-8') | |
| print(serialized) | |