keras-team/keras · error · ValueError
Number of groups ( ) must be a multiple of the number of…
Error message
Number of groups ({self.groups}) must be a multiple of the number of channels ({dim}). What it means
Raised in GroupNormalization.build() when dim % self.groups != 0: the channels on the normalization axis cannot be partitioned into equal groups. GroupNormalization splits the axis into exactly self.groups equal slices, so the channel count must be divisible by groups.
Solutions
- Choose a groups value that evenly divides the channel count (e.g. channels=64 works with groups 1, 2, 4, 8, 16, 32, 64)
- Set groups=-1 so the layer uses one group per channel (equivalent to LayerNormalization)
- Change the channel count of the preceding layer (e.g. filters/units) to a multiple of the desired groups
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/normalization/group_normalization.py:123 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/f4bf442f39cc87be.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/normalization/group_normalization.py:123
if dim is None:
raise ValueError(
f"Axis {self.axis} of input tensor should have a defined "
"dimension but the layer received an input with shape "
f"{input_shape}."
)
if self.groups == -1:
self.groups = dim
if dim < self.groups:
raise ValueError(
f"Number of groups ({self.groups}) cannot be more than the "
f"number of channels ({dim})."
)
if dim % self.groups != 0:
raise ValueError(
f"Number of groups ({self.groups}) must be a multiple "
f"of the number of channels ({dim})."
)
self.input_spec = InputSpec(
ndim=len(input_shape), axes={self.axis: dim}
)
if self.scale:
self.gamma = self.add_weight(
shape=(dim,),
name="gamma",
initializer=self.gamma_initializer,
regularizer=self.gamma_regularizer,
constraint=self.gamma_constraint,
autocast=False,
)
else:View on GitHub (pinned to 7a34a03db6)