{"record":{"id":"0dc855ef8288dd86","repo":"dotnet/machinelearning","slug":"inputembeddings-is-not-supported","errorCode":null,"errorMessage":"inputEmbeddings is not supported","messagePattern":"inputEmbeddings is not supported","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.GenAI.Phi/Module/Phi2Model.cs","lineNumber":66,"sourceCode":"    public Phi2Config Config => this._config;\n\n#pragma warning disable MSML_GeneralName // This name should be PascalCased\n    public override (Tensor, Tensor?, Tensor?) forward(\n#pragma warning restore MSML_GeneralName // This name should be PascalCased\n        Tensor inputIds,\n        Tensor? attentionMask = null,\n        int pastKeyValueLength = 0,\n        Tensor? positionIds = null,\n        Tensor? inputEmbeddings = null,\n        (bool, bool, bool) options = default) // use_cache, output_attentions, output_hidden_states\n    {\n        (var outputAttentions, var outputHiddenStates, var useCache) = options;\n\n        // TODO\n        // add support for inputEmbeddings\n        if (inputEmbeddings is not null)\n        {\n            throw new NotImplementedException(\"inputEmbeddings is not supported\");\n        }\n        inputEmbeddings = this.embed_tokens.forward(inputIds);\n        inputEmbeddings = this.embed_dropout.forward(inputEmbeddings);\n        var batchSize = inputIds.shape[0];\n        var seqLen = (int)inputIds.shape[1];\n\n        if (positionIds is null)\n        {\n            positionIds = torch.arange(pastKeyValueLength, seqLen + pastKeyValueLength, dtype: inputIds.dtype, device: inputIds.device);\n            positionIds = positionIds.unsqueeze(0);\n        }\n\n        // attention\n        // use 4d attention mask\n        if (attentionMask is not null)\n        {\n            attentionMask = this.Prepare4DCausalAttentionMask(attentionMask, seqLen, pastKeyValueLength, inputEmbeddings.dtype);\n        }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.GenAI.Phi/Module/Phi2Model.cs#L48-L84","documentation":"Phi2Model.forward does not support passing precomputed input embeddings; if inputEmbeddings is non-null it throws NotImplementedException('inputEmbeddings is not supported'). Embeddings are always computed internally from inputIds.","triggerScenarios":"Calling Phi2Model.forward with both/independent inputEmbeddings, e.g. continuing generation from hidden states, passing decoder inputs_embeds, or a generic pipeline that always supplies embeddings.","commonSituations":"Porting HuggingFace code that uses inputs_embeds; piping outputs of one model into Phi-2 without tokenizing; shared inference harness passing null inputIds with non-null embeddings.","solutions":["Pass inputIds and let the model compute embeddings itself","Tokenize your inputs before calling forward instead of pre-embedding them","Implement embedding-input support in Phi2Model (skip embed_tokens when embeddings supplied) if you own the code"],"exampleFix":"// before\nmodel.forward(inputIds: null, inputEmbeddings: embeddings, ...);\n// after\nvar ids = tokenizer.Encode(text); model.forward(inputIds: ids, inputEmbeddings: null, ...);","handlingStrategy":"validation","validationCode":"if (embeddings is not null) throw new InvalidOperationException(\"Phi2Model does not accept input embeddings; pass inputIds instead\");","typeGuard":null,"tryCatchPattern":"try { output = model.forward(inputIds: ids, inputEmbeddings: null, options); }\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"inputEmbeddings\")) { throw new NotSupportedException(\"Tokenize inputs before calling Phi2Model.forward\", ex); }","preventionTips":["Never populate inputEmbeddings for Phi-2","Tokenize at the boundary of the inference call","Track TODO/roadmap for embedding-input support before using it"],"tags":["csharp","phi-2","not-implemented"],"backgroundTag":"unsupported-operation","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}