I encountered a problem while using ML.NET
An error occurred while calling ONNX for an open source project, and I don't know how to handle it
System.InvalidOperationException:“Error initializing model :Microsoft.ML.OnnxRuntime.OnnxRuntimeException: [ErrorCode:Fail] Deserialize tensor transformer.word_embeddings.weight failed.open file transformer.word_embeddings.weight fail, errcode = 2 - ϵͳ�Ҳ���ָ�����ļ���
at Microsoft.ML.OnnxRuntime.NativeApiStatus.VerifySuccess(IntPtr nativeStatus)
at Microsoft.ML.OnnxRuntime.InferenceSession.Init(String modelPath, SessionOptions options, PrePackedWeightsContainer prepackedWeightsContainer)
at Microsoft.ML.OnnxRuntime.InferenceSession..ctor(String modelPath, SessionOptions options)
at Microsoft.ML.Transforms.Onnx.OnnxModel..ctor(String modelFile, Nullable`1 gpuDeviceId, Boolean fallbackToCpu, Boolean ownModelFile, IDictionary`2 shapeDictionary, Int32 recursionLimit, Nullable`1 interOpNumThreads, Nullable`1 intraOpNumThreads)
at Microsoft.ML.Transforms.Onnx.OnnxTransformer..ctor(IHostEnvironment env, Options options, Byte[] modelBytes)”
public static EmbeddingInputEmbeds Gen_embedding(List<Int64> ids, bool useGpu)
{
if (ids.Count > 0)
{
EmbeddingInputids _input_id = new();
MLContext _mlContext = new();
_input_id.input_ids = ids.ToArray();
var pipeline = _mlContext.Transforms.ApplyOnnxModel(modelFile: modelfile + "embedding.onnx",
gpuDeviceId: useGpu ? 0 : (int?)null,
inputColumnNames: new[] { "input_ids" },
outputColumnNames: new[] { "inputs_embeds" },
fallbackToCpu: true
);
IDataView data = _mlContext.Data.LoadFromEnumerable(new List<EmbeddingInputids>() { _input_id });
var model = pipeline.Fit(data);
IDataView transformedValues = model.Transform(data);
IEnumerable<EmbeddingInputEmbeds> results = transformedValues.GetColumn<EmbeddingInputEmbeds>("inputs_embeds");
if (results.Count() > 0)
return results?.ElementAtOrDefault(0);
}
return new EmbeddingInputEmbeds();
}
Onnx fromhttps://github.com/wangzhaode/ChatGLM-MNN/releases/tag/v0.4