deeplearning4j/deeplearning4j · error · RuntimeException
unknown distribution type:
Error message
unknown distribution type:
What it means
Distributions.createDistribution() maps deeplearning4j Distribution config objects (from org.deeplearning4j.nn.conf.distribution) to their Nd4j-backed random distribution implementations. It supports the known types (UniformDistribution, GaussianDistribution, NormalDistribution, BinomialDistribution, TruncatedNormalDistribution, OrthogonalDistribution, ConstantDistribution) via instanceof checks and throws an unchecked RuntimeException for anything else. This means a new/custom Distribution subclass exists that createDistribution has no mapping for.
Solutions
- Use only the built-in distribution classes supported by createDistribution (UniformDistribution, GaussianDistribution/NormalDistribution, BinomialDistribution, TruncatedNormalDistribution, OrthogonalDistribution, ConstantDistribution).
- If using a newer distribution type, upgrade the deeplearning4j-nn / deeplearning4j-core dependency to a version whose Distributions.createDistribution supports it.
- If a custom Distribution is required, extend Distributions or handle the mapping yourself instead of routing through createDistribution, or add an instanceof branch to the switch.
- Print dist.getClass().getName() from the exception context to identify exactly which type is unsupported, then check that type's availability in your DL4J version.
Example fix
// before Distribution dist = new MyCustomDistribution(...); // unsupported subclass IDistribution rnd = Distributions.createDistribution(dist); // throws // after Distribution dist = new GaussianDistribution(mean, std); // built-in supported type IDistribution rnd = Distributions.createDistribution(dist);
Defensive patterns
Strategy: validation
Validate before calling
Set<String> supported = Set.of(
UniformDistribution.class, GaussianDistribution.class, NormalDistribution.class,
BinomialDistribution.class, TruncatedNormalDistribution.class,
OrthogonalDistribution.class, ConstantDistribution.class);
if (!supported.contains(dist.getClass())) {
throw new IllegalArgumentException("Distribution type not supported by createDistribution: " + dist.getClass().getName());
} Type guard
boolean isSupported(Distribution d) {
return d instanceof UniformDistribution || d instanceof GaussianDistribution
|| d instanceof NormalDistribution || d instanceof BinomialDistribution
|| d instanceof TruncatedNormalDistribution || d instanceof OrthogonalDistribution
|| d instanceof ConstantDistribution;
} Try / catch
try {
IDistribution rnd = Distributions.createDistribution(dist);
} catch (RuntimeException e) {
if (e.getMessage() != null && e.getMessage().startsWith("unknown distribution type")) {
// fall back to a supported default, e.g. GaussianDistribution
rnd = Nd4j.getDistributions().createNormal(0.0, 0.01);
} else throw e;
} Prevention
- Stick to the built-in Distribution classes shipped with your DL4J version
- Pin all deeplearning4j-* modules to the same version so config JSON and runtime agree on supported types
- When adding a custom Distribution, also extend the mapping in Distributions.createDistribution
- Log dist.getClass().getName() whenever a config load fails so the missing type is obvious
When it happens
Trigger: Calling Nd4j.getDistributions() via Distributions.createDistribution(Distribution) with a Distribution instance whose concrete class is not one of the instanceof-handled types; e.g. a custom Distribution subclass, or a Distribution type added in a newer DL4J version being deserialized by an older version whose createDistribution lacks that branch.
Common situations: Implementing a custom Distribution subclass and using it in weight initialization; deserializing a network JSON/config created with a newer DL4J version (containing a distribution type the older runtime does not know) into an older DL4J dependency; typos in custom mapping code that instantiate the wrong subclass.
Related errors
- Cannot deserialize Distribution: legacy format 'normal'…
- Cannot initialize embedding layer weights: no…
- Cannot use IDENTITY init with parameters of shape
- Cannot use IDENTITY init with parameters of shape
- Cannot use IDENTITY init with parameters of shape
AI-assisted analysis of deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07).
Data as JSON: /api/errors/49cf53b65b0bbe14.
Report an issue: GitHub.
Appendix: source
Thrown at deeplearning4j/deeplearning4j-nn/src/main/java/org/deeplearning4j/nn/conf/distribution/Distributions.java:63
return Nd4j.getDistributions().createBinomial(bd.getNumberOfTrials(), bd.getProbabilityOfSuccess());
}
if (dist instanceof LogNormalDistribution) {
LogNormalDistribution lnd = (LogNormalDistribution) dist;
return Nd4j.getDistributions().createLogNormal(lnd.getMean(), lnd.getStd());
}
if (dist instanceof TruncatedNormalDistribution) {
TruncatedNormalDistribution tnd = (TruncatedNormalDistribution) dist;
return Nd4j.getDistributions().createTruncatedNormal(tnd.getMean(), tnd.getStd());
}
if (dist instanceof OrthogonalDistribution) {
OrthogonalDistribution od = (OrthogonalDistribution) dist;
return Nd4j.getDistributions().createOrthogonal(od.getGain());
}
if (dist instanceof ConstantDistribution) {
ConstantDistribution od = (ConstantDistribution) dist;
return Nd4j.getDistributions().createConstant(od.getValue());
}
throw new RuntimeException("unknown distribution type: " + dist.getClass());
}
}
View on GitHub (pinned to 4c22ac5fe4)