{"record":{"id":"e4b51061ea868a45","repo":"dotnet/machinelearning","slug":"activation-function-name-not-supported","errorCode":null,"errorMessage":"Activation function {name} not supported.","messagePattern":"Activation function (.+?) not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.TorchSharp/NasBert/Modules/ActivationFunction.cs","lineNumber":28,"sourceCode":"\nnamespace Microsoft.ML.TorchSharp.NasBert.Modules\n{\n\n    internal sealed class ActivationFunction : torch.nn.Module<torch.Tensor, torch.Tensor>\n    {\n        private readonly torch.nn.Module<torch.Tensor, torch.Tensor> _function;\n        private bool _disposedValue;\n\n        public ActivationFunction(string name) : base(name)\n        {\n            _function = name?.ToLower() switch\n            {\n                \"relu\" => torch.nn.ReLU(),\n                \"gelu\" => torch.nn.GELU(),\n                \"gelu_fast\" => new GeLUFast(),\n                \"tanh\" => torch.nn.Tanh(),\n                \"linear\" => torch.nn.Identity(),\n                _ => throw new NotSupportedException($\"Activation function {name} not supported.\")\n            };\n        }\n\n        [System.Diagnostics.CodeAnalysis.SuppressMessage(\"Naming\", \"MSML_GeneralName:This name should be PascalCased\", Justification = \"Need to match TorchSharp.\")]\n        public override torch.Tensor forward(torch.Tensor x)\n        {\n            return _function.forward(x);\n        }\n\n        public override string GetName()\n        {\n            return _function.GetName();\n        }\n\n        protected override void Dispose(bool disposing)\n        {\n            if (!_disposedValue)\n            {","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.TorchSharp/NasBert/Modules/ActivationFunction.cs#L10-L46","documentation":"ActivationFunction is a switch over known activation names (relu, gelu, gelu_fast, tanh, linear); any other name falls through to a NotSupportedException. The library only implements these activations for NasBERT modules, so unknown or misspelled configuration values are rejected at module construction time.","triggerScenarios":"Constructing ActivationFunction (directly or via a NasBERT/Roberta options object where Activation is read from config) with a name other than \"relu\", \"gelu\", \"gelu_fast\", \"tanh\", or \"linear\" — e.g. \"sigmoid\", \"GELU\" (wrong case), or \"gelu-fast\".","commonSituations":"Copy-pasting activation names from other frameworks (PyTorch/tensorflow configs) whose supported sets differ, misspelling the name in an ML.NET options class, or case mismatch since the match is case-sensitive.","solutions":["Set the activation name to one of the supported strings: \"relu\", \"gelu\", \"gelu_fast\", \"tanh\", \"linear\".","Normalize the incoming config value to lowercase and trim whitespace before constructing the module.","If another activation is genuinely needed, add a case to the switch in ActivationFunction's constructor implementing it with TorchSharp primitives.","Wrap module construction in try-catch on NotSupportedException to report the unsupported name clearly."],"exampleFix":"// before\noptions.Activation = \"gelu-fast\"; // NotSupportedException\n\n// after\noptions.Activation = \"gelu_fast\"; // supported name","handlingStrategy":"validation","validationCode":"var allowed = new[] { \"relu\", \"gelu\", \"gelu_fast\", \"tanh\", \"linear\" };\nif (!allowed.Contains(options.Activation?.Trim().ToLowerInvariant()))\n    throw new ArgumentException($\"Unsupported activation '{options.Activation}'. Use one of: {string.Join(\", \", allowed)}.\");","typeGuard":null,"tryCatchPattern":"try { var act = new ActivationFunction(name, dropout); }\ncatch (NotSupportedException ex) { log.LogError(ex, \"Unsupported activation: {Name}\", name); throw new ConfigValidationException(...); }","preventionTips":["Keep activation names in a validated options class with a fixed set.","Normalize case/whitespace of config values before use.","Don't copy activation names from other ML frameworks without checking this library's supported list."],"tags":["csharp","activation-function","unsupported-value","config"],"backgroundTag":"unsupported-enum-value","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"}