deeplearning4j/deeplearning4j · error · java.lang.IllegalArgumentException

Illegal arg type

Error message

Illegal arg type ${descriptor.argType}

What it means

BaseAttributeExtractionRule.serialize() iterates the rule's transformerArgs and maps each ArgDescriptor's argType to an input category (string attr, bool, float, int, tensor). If a transformer arg declares an argType outside that set (e.g. DOUBLE-only outputs like OUTPUT_TENSOR, DATA_TYPE, or UNRECOGNIZED), the exhaustive when falls to the else branch and throws IllegalArgumentException('Illegal arg type ...'). The library throws it because serialize() cannot classify the descriptor into the MappingRule's typed input-name lists.

Solutions

  1. Inspect the rule's transformerArgs and change the offending descriptor's argType to one supported here (STRING, BOOL, DOUBLE, FLOAT, INT32, INT64, or INPUT_TENSOR)
  2. Move the offending descriptor out of transformerArgs — output-tensor/data-type descriptors belong in output mapping, not as transformer args
  3. Regenerate the op descriptor (nd4j ops .proto) so the named arg has the expected input arg type
  4. Patch serialize()'s when to handle the missing ArgType if it is legitimately needed

Example fix

// before
transformerArgs = mapOf("axis" to listOf(ArgDescriptor { name="axis"; argType = ArgType.OUTPUT_TENSOR }))
// after
transformerArgs = mapOf("axis" to listOf(ArgDescriptor { name="axis"; argType = ArgType.INT64 }))
Defensive patterns

Strategy: validation

Validate before calling

val allowed = setOf(ArgType.STRING, ArgType.BOOL, ArgType.DOUBLE, ArgType.FLOAT, ArgType.INT32, ArgType.INT64, ArgType.INPUT_TENSOR)
require(rule.transformerArgs().values.flatten().all { it.argType in allowed }) { "transformer arg ${it.name} has unsupported argType ${it.argType}" }

Type guard

fun isSerializableInputArgType(t: OpNamespace.ArgDescriptor.ArgType) = t in setOf(
    ArgType.STRING, ArgType.BOOL, ArgType.DOUBLE, ArgType.FLOAT,
    ArgType.INT32, ArgType.INT64, ArgType.INPUT_TENSOR)

Try / catch

try { rule.serialize() } catch (e: IllegalArgumentException) { if (!e.message!!.startsWith("Illegal arg type")) throw e; log.error("Fix transformerArgs argType: ${e.message}") }

Prevention

When it happens

Trigger: Calling serialize() on an attribute extraction rule whose transformerArgs map contains an OpNamespace.ArgDescriptor with argType not in {STRING, BOOL, DOUBLE, FLOAT, INT32, INT64, INPUT_TENSOR} — e.g. a transformer arg of type OUTPUT_TENSOR, DATA_TYPE, or a protobuf-parsed UNRECOGNIZED enum value.

Common situations: Hand-written or generated op mapping definitions (import config for TF/ONNX/PyTorch graphs) that list transformer args with output-tensor or data-type arg types in input position; version drift where the nd4j op descriptor file assigns a new arg type to a named arg used as a transformer arg; copy-pasting an output descriptor into transformerArgs.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/112a83301230c857. Report an issue: GitHub.

Appendix: source

Thrown at nd4j/samediff-import/samediff-import-api/src/main/kotlin/org/nd4j/samediff/frameworkimport/rule/attribute/BaseAttributeExtractionRule.kt:104


    override fun serialize(): MapperNamespace.MappingRule {
        val builder = MapperNamespace.MappingRule.newBuilder()
        builder.ruleName = name()
        builder.functionName = name()
        builder.ruleType = "attribute"
        builder.inputFrameworkOpName = this.inputFrameworkOpName
        val descriptorList = opDescriptor!!.argDescriptorList
        println("Serializing op ${opDescriptor!!.name}")
        for ((k, v) in transformerArgs) {
            v.forEach { descriptor ->
                when (descriptor.argType) {
                    OpNamespace.ArgDescriptor.ArgType.STRING -> builder.addInputStringAttrName(descriptor.name)
                    OpNamespace.ArgDescriptor.ArgType.BOOL -> builder.addInputBooleanName(descriptor.name)
                    OpNamespace.ArgDescriptor.ArgType.DOUBLE, OpNamespace.ArgDescriptor.ArgType.FLOAT -> builder.addInputFloatName(descriptor.name)
                    OpNamespace.ArgDescriptor.ArgType.INT32, OpNamespace.ArgDescriptor.ArgType.INT64 -> builder.addInputIntName(descriptor.name)
                    OpNamespace.ArgDescriptor.ArgType.INPUT_TENSOR -> builder.addInputTensorName(descriptor.name)
                    else -> {throw IllegalArgumentException("Illegal arg type ${descriptor.argType}")}

                }

                builder.addTransformerArgs(MapperNamespace.TransformerArgs.newBuilder().setKey(k).addAllTransformerArgs(v))
            }

        }

        /**
         * TODO: metadata (perhaps looking up from each framework for each attribute)
         * what each named type is.
         */
        mappingNamesToPerform.forEach { outputName, inputName ->
            val descriptorForName = opDescriptor!!.argDescriptorList.first { descriptor -> descriptor.name == outputName }
            builder.putInputToOutput(outputName,inputName)
            when(descriptorForName.argType) {
                OpNamespace.ArgDescriptor.ArgType.BOOL -> { builder.addOutputBooleanName(outputName)}
                OpNamespace.ArgDescriptor.ArgType.INT64 -> {builder.addOutputIntName(outputName)}

View on GitHub (pinned to 4c22ac5fe4)