{"record":{"id":"4494e932f103cb37","repo":"dotnet/machinelearning","slug":"either-input-ids-or-inputs-embeds-must-be-set-4494e9","errorCode":null,"errorMessage":"Either input_ids or inputs_embeds must be set","messagePattern":"Either input_ids or inputs_embeds must be set","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.GenAI.Mistral/MistralModel.cs","lineNumber":87,"sourceCode":"        {\n            throw new ArgumentException(\"Only one of input_ids or inputs_embeds may be set\");\n        }\n        else if (inputIds is not null)\n        {\n            batchSize = inputIds.IntShape()[0];\n            seqLength = inputIds.IntShape()[1];\n            inputsEmbeds = this.embed_tokens.forward(inputIds);\n            device = inputIds.device;\n        }\n        else if (inputsEmbeds is not null)\n        {\n            batchSize = inputsEmbeds.IntShape()[0];\n            seqLength = inputsEmbeds.IntShape()[1];\n            device = inputsEmbeds.device;\n        }\n        else\n        {\n            throw new ArgumentException(\"Either input_ids or inputs_embeds must be set\");\n        }\n\n        var pastKeyValuesLength = input.PastKeyValuesLength;\n\n        if (positionIds is null)\n        {\n            positionIds = torch.arange(pastKeyValuesLength, seqLength + pastKeyValuesLength, device: device);\n            positionIds = positionIds.unsqueeze(0).view(-1, seqLength);\n        }\n        else\n        {\n            positionIds = ((long)positionIds.view(-1, seqLength));\n        }\n\n        if (this._config.AttnImplementation == \"flash_attention_2\")\n        {\n            throw new NotImplementedException();\n        }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.GenAI.Mistral/MistralModel.cs#L69-L105","documentation":"Validation in MistralModel.forward: exactly one of input_ids or inputs_embeds must be supplied. Both set -> \"Only one of ...\" ArgumentException; neither set -> this error. Without one of these tensors the model cannot determine batch size, sequence length, or device, so the forward pass is rejected.","triggerScenarios":"Calling MistralModel.forward with both InputIds and InputEmbeddings null — e.g. only PositionIds or AttentionMask was populated on the input.","commonSituations":"Custom generation loops that forgot to tokenize; deserialized request objects missing the token field; refactor that renamed the ids property without updating the assignment.","solutions":["Set InputIds from tokenizer output before calling forward.","Or set InputEmbeddings with precomputed embedding tensors.","Add an up-front null check on both fields and throw a descriptive error early."],"exampleFix":"// before\nvar input = new MistralModelInput();\nvar output = model.forward(input); // throws\n// after\nvar input = new MistralModelInput { InputIds = tokenizer.EncodeToIds(prompt) };\nvar output = model.forward(input);","handlingStrategy":"validation","validationCode":"if (input.InputIds is null && input.InputEmbeddings is null) throw new ArgumentException(\"Input requires InputIds or InputEmbeddings.\");","typeGuard":"bool HasNoInput(MistralModelInput i) => i.InputIds is null && i.InputEmbeddings is null;","tryCatchPattern":"try { output = model.forward(input); } catch (ArgumentException) { /* set InputIds from tokenizer output and retry */ }","preventionTips":["Tokenize before constructing MistralModelInput","Use a factory helper that always populates InputIds or InputEmbeddings","Fail fast with your own descriptive check before forward"],"tags":["argument-validation","mistral","missing-input"],"backgroundTag":"missing-required-argument","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}