{"record":{"id":"8141c334666e48d9","repo":"keras-team/keras","slug":"sequence-stride-must-be-a-positive-integer-rece","errorCode":null,"errorMessage":"`sequence_stride` must be a positive integer. Received: sequence_stride={sequence_stride}","messagePattern":"`sequence_stride` must be a positive integer\\. Received: sequence_stride=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/ops/math.py","lineNumber":990,"sourceCode":"            centered at time `t * sequence_stride`. Otherwise, the t-th sequence\n            begins at time `t * sequence_stride`. Defaults to `True`.\n\n    Returns:\n        A tuple containing two tensors - the real and imaginary parts of the\n        STFT output.\n\n    Example:\n\n    >>> x = keras.ops.convert_to_tensor([0.0, 1.0, 2.0, 3.0, 4.0])\n    >>> stft(x, 3, 2, 3)\n    (array([[0.75, -0.375],\n       [3.75, -1.875],\n       [5.25, -2.625]]), array([[0.0, 0.64951905],\n       [0.0, 0.64951905],\n       [0.0, -0.64951905]]))\n    \"\"\"\n    if not isinstance(sequence_stride, int) or sequence_stride <= 0:\n        raise ValueError(\n            \"`sequence_stride` must be a positive integer. \"\n            f\"Received: sequence_stride={sequence_stride}\"\n        )\n    if any_symbolic_tensors((x,)):\n        return STFT(\n            sequence_length=sequence_length,\n            sequence_stride=sequence_stride,\n            fft_length=fft_length,\n            window=window,\n            center=center,\n        ).symbolic_call(x)\n    return backend.math.stft(\n        x,\n        sequence_length=sequence_length,\n        sequence_stride=sequence_stride,\n        fft_length=fft_length,\n        window=window,\n        center=center,","sourceCodeStart":972,"sourceCodeEnd":1008,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/ops/math.py#L972-L1008","documentation":"keras.ops.stft validates sequence_stride eagerly: it must be a Python int and strictly positive. Non-int types (numpy integer, float, tensor, None) or values <= 0 raise immediately, before any backend call.","triggerScenarios":"keras.ops.stft(x, 256, np.int64(128)); passing stride as float 128.0, a tensor, 0, or a negative hop; stride derived from a config or CLI arg without casting.","commonSituations":"Config values parsed as strings/floats (argparse type=float), numpy scalars from array ops, hop size computed as float (n_fft*0.5) instead of int().","solutions":["Cast explicitly: int(sequence_stride), and ensure it is > 0","Use argparse type=int for hop/stride CLI args","If stride is computed (e.g. n_fft // 4), keep integer arithmetic","Add a guard: assert isinstance(sequence_stride, int) and sequence_stride > 0"],"exampleFix":"# before\nhop = np.int64(128)\nz = keras.ops.stft(x, 256, hop, 256)\n# after\nhop = int(hop)\nz = keras.ops.stft(x, 256, hop, 256)","handlingStrategy":"validation","validationCode":"assert isinstance(sequence_stride, int) and sequence_stride > 0, 'stride must be positive int'","typeGuard":"def valid_stride(s):\n    return isinstance(s, int) and not isinstance(s, bool) and s > 0","tryCatchPattern":null,"preventionTips":["int() all stride/hop values from configs and numpy","Use integer arithmetic for derived hop sizes","argparse type=int for CLI strides"],"tags":["keras","stft","input-validation","type-error"],"backgroundTag":"invalid-function-arguments","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}