{"record":{"id":"54d27b0f9c2ba988","repo":"keras-team/keras","slug":"argument-size-should-be-a-positive-integer-rece","errorCode":null,"errorMessage":"Argument `size` should be a positive integer. Received: size={size}","messagePattern":"Argument `size` should be a positive integer\\. Received: size=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/reshaping/up_sampling1d.py","lineNumber":50,"sourceCode":"\n    Args:\n        size: Integer. Upsampling factor.\n\n    Input shape:\n        3D tensor with shape: `(batch_size, steps, features)`.\n\n    Output shape:\n        3D tensor with shape: `(batch_size, upsampled_steps, features)`.\n    \"\"\"\n\n    def __init__(self, size=2, **kwargs):\n        super().__init__(**kwargs)\n        if not isinstance(size, int) or isinstance(size, bool):\n            raise TypeError(\n                f\"Expected an integer value for `size`, got {type(size)}.\"\n            )\n        if size <= 0:\n            raise ValueError(\n                \"Argument `size` should be a positive integer. \"\n                f\"Received: size={size}\"\n            )\n        self.size = size\n        self.input_spec = InputSpec(ndim=3)\n\n    def compute_output_shape(self, input_shape):\n        size = (\n            self.size * input_shape[1] if input_shape[1] is not None else None\n        )\n        return [input_shape[0], size, input_shape[2]]\n\n    def call(self, inputs):\n        return ops.repeat(x=inputs, repeats=self.size, axis=1)\n\n    def get_config(self):\n        config = {\"size\": self.size}\n        base_config = super().get_config()","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/reshaping/up_sampling1d.py#L32-L68","documentation":"UpSampling1D.__init__ rejects size <= 0: upsampling by a zero or negative factor is meaningless and would produce an empty or invalid sequence length, so Keras fails at construction time.","triggerScenarios":"UpSampling1D(size=0) or UpSampling1D(size=-1), typically from a computed or config-supplied factor.","commonSituations":"Hyperparameter sweeps proposing 0 or negatives; size derived from a ratio that rounds or truncates to 0 (e.g. int(target/len) with small len); stale config defaults.","solutions":["Clamp and validate the factor to >= 1 before constructing the layer","Trace the upstream expression producing 0 — often integer division or a ratio < 1 truncated by int()","Skip the upsampling layer entirely when the factor is 1 (identity) or 0 means 'no upsample' in your config semantics"],"exampleFix":"# before\nfactor = int(target_len // input_len)  # can be 0\nlayer = UpSampling1D(size=factor)\n\n# after\nfactor = max(int(target_len // input_len), 1)\nlayer = UpSampling1D(size=factor)","handlingStrategy":"validation","validationCode":"def validated_size(size):\n    if not (isinstance(size, int) and not isinstance(size, bool)):\n        raise TypeError('size must be int')\n    if size <= 0:\n        raise ValueError(f'size must be >= 1, got {size}')\n    return size","typeGuard":"def is_positive_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool) and v > 0","tryCatchPattern":null,"preventionTips":["Skip the upsample layer when the computed factor is 1 (identity case)","Audit integer divisions producing factors for small inputs","Assert factor >= 1 in dataset-specific scripts before building the graph"],"tags":["keras","upsampling1d","argument-validation","value-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}