{"record":{"id":"4bf22aba01a7f520","repo":"dotnet/machinelearning","slug":"only-one-of-input-ids-or-inputs-embeds-may-be-set","errorCode":null,"errorMessage":"Only one of input_ids or inputs_embeds may be set","messagePattern":"Only one of input_ids or inputs_embeds may be set","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.GenAI.LLaMA/Module/LlamaModel.cs","lineNumber":76,"sourceCode":"            this._cache = input.OverrideCache;\n        }\n        else if (!input.UseCache)\n        {\n            this._cache = null;\n        }\n\n        var outputAttentions = input.OutputAttentions;\n        var outputHiddenStates = input.OutputHiddenStates;\n        var attentionMask = input.AttentionMask;\n        Device device;\n        var inputIds = input.InputIds;\n        var positionIds = input.PositionIds;\n        var inputsEmbeds = input.InputEmbeddings;\n        int batchSize;\n        int seqLength;\n        if (inputIds is not null && inputsEmbeds is not null)\n        {\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        }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.GenAI.LLaMA/Module/LlamaModel.cs#L58-L94","documentation":"LlamaModel.forward requires exactly one of input_ids or input embeddings; passing both is ambiguous so it throws ArgumentException. The two representations are mutually exclusive ways to specify the input sequence.","triggerScenarios":"Constructing a LlamaModelInput/CausalLMInput where both InputIds and InputEmbeddings are non-null and calling LlamaModel.forward.","commonSituations":"Pipeline or agent code that pre-computes embeddings but forgets to clear the token ids, or custom code wrapping the model that always sets both fields.","solutions":["Populate only one of InputIds or InputEmbeddings on the input object.","If you have embeddings, set InputIds to null; if you have tokens, leave InputEmbeddings null.","Trace back to the code constructing the input and make the choice mutually exclusive at construction time."],"exampleFix":"// before\nvar input = new LlamaModelInput { InputIds = ids, InputEmbeddings = embeds };\n// after\nvar input = new LlamaModelInput { InputIds = ids }; // embeddings computed internally","handlingStrategy":"validation","validationCode":"if (input.InputIds is not null && input.InputEmbeddings is not null) throw new ArgumentException(\"Set only one of InputIds or InputEmbeddings.\");","typeGuard":"bool HasAmbiguousInput(LlamaModelInput i) => i.InputIds is not null && i.InputEmbeddings is not null;","tryCatchPattern":"try { output = model.forward(input); } catch (ArgumentException) { /* fix input construction: clear one of the two fields */ }","preventionTips":["Treat InputIds and InputEmbeddings as mutually exclusive at input-construction time","If you precompute embeddings, never also assign token ids","Add unit tests covering both input modes"],"tags":["argument-validation","llama","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","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"}