dotnet/machinelearning · error · NotImplementedException

Softmax's PFA exporter is not implemented yet.

Error message

Softmax's PFA exporter is not implemented yet.

What it means

The OneVersusAll trainer wraps a binary trainer into a multiclass model. Its softmax model parameters implement SaveAsPfa (export to Portable Format for Analytics) by throwing NotImplementedException because PFA export for the softmax combiner was never written.

Solutions

  1. Use ONNX export instead of PFA (SaveAsOnnx is implemented for softmax with opset >= 9).
  2. Choose a different combiner/calibration that supports PFA export, or use a trainer whose multiclass output is directly PFA-exportable.
  3. Implement SaveAsPfa for the softmax parameters in a fork/patch of Microsoft.ML.
  4. Catch the NotImplementedException at export time and skip PFA export with a warning for softmax-based models.

Example fix

// before
var pipeline = mlContext.MulticlassClassification.Trainers.OneVersusAll(binaryTrainer);
var pfa = converter.ConvertToPfa(model); // throws
// after
var pipeline = mlContext.MulticlassClassification.Trainers.OneVersusAll(binaryTrainer);
using var onnxStream = mlContext.Model.ConvertToOnnx(model, data); // supported path
Defensive patterns

Strategy: fallback

Validate before calling

bool supportsPfa = model is not OneVersusAllModelParameters { }; // detect softmax OvA before export

Try / catch

try { ExportPfa(model); }
catch (NotImplementedException) { ExportOnnx(model); // softmax PFA unsupported
}

Prevention

When it happens

Trigger: Training a multiclass model with OneVersusAllTrainer (whose calibration is softmax) and then calling the PFA export path, e.g. via schema/export pipelines that convert the model to PFA (ml.NET PFA conversion APIs).

Common situations: Exporting a trained OneVsAll/softmax model for scoring in another runtime (e.g. a PFA-compatible serving system); CI jobs that auto-export all trained models to PFA; upgrading tooling that newly exercises the PFA exporter.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/fca74daa70f10bae. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.ML.StandardTrainers/Standard/MulticlassClassification/OneVersusAllTrainer.cs:911

            private void NormalizeSoftmax(float[] scores, int count)
            {
                double sum = 0;
                var score = new double[count];

                for (int i = 0; i < count; i++)
                {
                    score[i] = Math.Exp(scores[i]);
                    sum += score[i];
                }

                for (int i = 0; i < count; i++)
                    scores[i] = (float)(score[i] / sum);
            }

            public override JToken SaveAsPfa(BoundPfaContext ctx, JToken input)
            {
                throw new NotImplementedException("Softmax's PFA exporter is not implemented yet.");
            }

            public override bool SaveAsOnnx(OnnxContext ctx, string[] outputNames, string featureColumn)
            {
                Contracts.Assert(outputNames.Length >= 2);
                const int minimumOpSetVersion = 9;
                ctx.CheckOpSetVersion(minimumOpSetVersion, LoaderSignature);

                var probabilityOutputs = base.SaveAsOnnxPreProcess(ctx, featureColumn, false);

                string opType;
                opType = "Concat";
                var type = new VectorDataViewType(NumberDataViewType.Single, probabilityOutputs.Length);
                var concatOutput = ctx.AddIntermediateVariable(type, "ConcatOutputSoftMax");
                var concatNode = ctx.CreateNode(opType, probabilityOutputs, new[] { concatOutput }, ctx.GetNodeName(opType), "");
                concatNode.AddAttribute("axis", 1);

                opType = "Exp";

View on GitHub (pinned to 7b76e69cf9)