Skip to content

Latest commit

 

History

History
65 lines (31 loc) · 1.57 KB

E2E_Inference_ORT.md

File metadata and controls

65 lines (31 loc) · 1.57 KB

Inference your Fine-tuning models

After fine-tuning, you can access the new model through reference, which is implemented here using ONNX Runtime GenAI.

Install ORT GenAI SDK

Notes - Please Install CUDA 12.1 firstly,if you don't know how to do this , please read this guideline https://developer.nvidia.com/cuda-12-1-0-download-archive

after finish cuda, please install onnxruntime genai sdk with cuda

pip install numpy

pip install onnxruntime-genai-cuda --pre --index-url=https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/onnxruntime-genai/pypi/simple/

Inference Model

import onnxruntime_genai as og

model = og.Model('Your onnx model folder location')
tokenizer = og.Tokenizer(model)
tokenizer_stream = tokenizer.create_stream()

search_options = {"max_length": 1024,"temperature":0.3}

params = og.GeneratorParams(model)
params.try_use_cuda_graph_with_max_batch_size(1)
params.set_search_options(**search_options)

prompt = "prompt = "<|user|>Who are you not allowed to marry in the UK?<|end|><|assistant|>""
input_tokens = tokenizer.encode(prompt)
params.input_ids = input_tokens

generator = og.Generator(model, params)

while not generator.is_done():
                generator.compute_logits()
                generator.generate_next_token()

                new_token = generator.get_next_tokens()[0]
                print(tokenizer_stream.decode(new_token), end='', flush=True)

Testing Your result

result