xai-org/x-algorithm · error · ValueError

N must be a multiple of 8 in the range 8…256

Error message

N must be a multiple of 8 in the range 8…256

What it means

make_instr_desc validates that the UMMA N dimension is between 8 and 256 inclusive and a multiple of 8 (N & 7 == 0), encoding N>>3 into the descriptor. Violating any of these raises ValueError.

Source

Thrown at phoenix/xrex/cutedsl/ranker_fa4/mma_sm100_desc.py:166

    c_type,
    M: int,
    N: int,
    a_major: Major,
    b_major: Major,
    a_neg: ScaleIn = ScaleIn.One,
    b_neg: ScaleIn = ScaleIn.One,
    c_sat: Saturate = Saturate.False_,
    is_sparse: bool = False,
    max_shift: MaxShift = MaxShift.NoShift,
) -> int:
    a_fmt = int(to_UMMA_format(a_type))
    b_fmt = int(to_UMMA_format(b_type))
    c_fmt = int(to_C_format(c_type))

    if M not in (64, 128, 256):
        raise ValueError("M must be 64, 128 or 256")
    if N < 8 or N > 256 or (N & 7):
        raise ValueError("N must be a multiple of 8 in the range 8…256")

    m_dim = M >> 4
    n_dim = N >> 3

    desc = 0
    desc |= (0 & 0x3) << 0
    desc |= (int(is_sparse) & 0x1) << 2
    desc |= (int(c_sat) & 0x1) << 3
    desc |= (c_fmt & 0x3) << 4
    desc |= (a_fmt & 0x7) << 7
    desc |= (b_fmt & 0x7) << 10
    desc |= (int(a_neg) & 0x1) << 13
    desc |= (int(b_neg) & 0x1) << 14
    desc |= (int(a_major) & 0x1) << 15
    desc |= (int(b_major) & 0x1) << 16
    desc |= (n_dim & 0x3F) << 17
    desc |= (m_dim & 0x1F) << 24
    desc |= (int(max_shift) & 0x3) << 30

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Round N up/down to the nearest multiple of 8 within [8, 256] (e.g. 100 -> 104) and pad the tensor accordingly
  2. Clamp N to 256 and split wider dimensions into multiple MMA calls
  3. Validate head_dim-based N before building the op and raise a clearer config error at setup time

Example fix

# before
desc = make_instr_desc(a, b, c, M=128, N=100)
# after
N = (100 + 7) & ~7  # 104
assert 8 <= N <= 256
desc = make_instr_desc(a, b, c, M=128, N=N)
Defensive patterns

Strategy: validation

Validate before calling

if not (8 <= N <= 256 and N % 8 == 0):
    raise ValueError(f'N={N} illegal; need multiple of 8 in [8, 256]')

Type guard

def is_legal_umma_n(n: int) -> bool:
    return 8 <= n <= 256 and (n & 7) == 0

Prevention

When it happens

Trigger: Calling make_instr_desc / mma_op_to_idesc with N such as 96 (not a multiple of 8), 264 (>256), or 4 (<8), often N derived from head_dim or a heuristic tile size.

Common situations: Using unusual head dimensions (e.g. 96 is fine, 100 is not), porting tile configs from another arch, or computing N from a runtime value that can drift outside the legal range.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/66c067a2a38f7bb9. Report an issue: GitHub.