Ling-3.0-tiny-ONNX / conversion /foundry_cpu /runtime_session.py
hecz-showcase's picture TechWithRay's picture
[Ling] Add a working Foundry Local CPU adapter for the BF16 model (#1)
d00cac4
Raw History Blame Contribute Delete
798 Bytes
import onnxruntime as ort
class CpuSession:
def __init__(self, path):
options = ort.SessionOptions()
options.intra_op_num_threads = 12
options.inter_op_num_threads = 1
options.enable_cpu_mem_arena = False
options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
self.session = ort.InferenceSession(
str(path), options, providers=["CPUExecutionProvider"])
if self.session.get_providers() != ["CPUExecutionProvider"]:
raise RuntimeError(f"Unexpected execution providers: {self.session.get_providers()}")
def run(self, feeds, output_names):
return dict(zip(output_names, self.session.run(output_names, feeds)))
def close(self):
self.session = None