microsoft / onnxruntime-genai

Generative AI extensions for onnxruntime
MIT License
500 stars 126 forks source link

An error occurred: Number of unique image tags does not match the number of images in WebAPI by ProcessImages(prompt, images); #712

Closed airforcefirer closed 3 months ago

airforcefirer commented 3 months ago

Describe the issue

Has anyone ever used Microsoft.ML.OnnxRuntimeGenAI in a C# .NET 6 WebAPI environment?

In the following code snippet, executing processor.ProcessImages(prompt, images); in the WebAPI environment throws an error (the same component configuration works without this error when executed in a WinForm application):

**An error occurred: Number of unique image tags does not match the number of images.

at Microsoft.ML.OnnxRuntimeGenAI.MultiModalProcessor.ProcessImages(String prompt, Images images) at Phi3MultimodalProcess.Controllers.Phi3RecognitionController.PostRecognitionWithCPU(GPTParameter parameter) in D:\WebApplication\WebService\Phi3MultimodalProcess\Controllers\Phi3RecognitionController.cs:line 131**

螢幕擷取畫面 2024-07-18 170445

To reproduce

[Code snippet:] public string onnxPathCPU = "D:\Phi-3-vision-128k-instruct-onnx-cpu\cpu-int4-rtn-block-32-acc-level-4"; using var model = new Model(onnxPathCPU); using MultiModalProcessor processor = new MultiModalProcessor(model);

Images? images = hasImage ? Images.Load(parameter.imagePath) : null;

string prompt = parameter.prompt; using var inputs = processor.ProcessImages(prompt, images);

[My .csproj setting:]

SAK SAK SAK SAK net6.0 enable enable

Urgency

No response

Platform

Windows

OS Version

.NET 6 WebAPI

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

Microsoft.ML.OnnxRuntimeGenAI (0.3.0-rc2)

ONNX Runtime API

C#

Architecture

X64

Execution Provider

Default CPU

Execution Provider Library Version

No response

yuslepukhin commented 3 months ago

This appears to be a GenAi issue. Please, file there for visibility.

baijumeswani commented 3 months ago

This happens when the number of image tags in your prompt <|image_1|> does not match the number of images provided to the processor.

Could you please paste your prompt and mention whether image is null or not?

baijumeswani commented 3 months ago

Will close this issue now. Please let me know if the above information was not helpful or if you believe this needs further investigation.