{"record":{"id":"6fe71ab7af1e96d0","repo":"Comfy-Org/ComfyUI","slug":"len-args-should-be-0-1-or-2-but-got-len-args","errorCode":null,"errorMessage":"len(args) should be 0, 1 or 2, but got {len(args)}","messagePattern":"len\\(args\\) should be 0, 1 or 2, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy/ldm/hydit/posemb_layers.py","lineNumber":51,"sourceCode":"\ndef get_meshgrid(start, *args):\n    if len(args) == 0:\n        # start is grid_size\n        num = _to_tuple(start)\n        start = (0, 0)\n        stop = num\n    elif len(args) == 1:\n        # start is start, args[0] is stop, step is 1\n        start = _to_tuple(start)\n        stop = _to_tuple(args[0])\n        num = (stop[0] - start[0], stop[1] - start[1])\n    elif len(args) == 2:\n        # start is start, args[0] is stop, args[1] is num\n        start = _to_tuple(start)\n        stop = _to_tuple(args[0])\n        num = _to_tuple(args[1])\n    else:\n        raise ValueError(f\"len(args) should be 0, 1 or 2, but got {len(args)}\")\n\n    grid_h = np.linspace(start[0], stop[0], num[0], endpoint=False, dtype=np.float32)\n    grid_w = np.linspace(start[1], stop[1], num[1], endpoint=False, dtype=np.float32)\n    grid = np.meshgrid(grid_w, grid_h)  # here w goes first\n    grid = np.stack(grid, axis=0)   # [2, W, H]\n    return grid\n\n#################################################################################\n#                   Sine/Cosine Positional Embedding Functions                  #\n#################################################################################\n# https://github.com/facebookresearch/mae/blob/main/util/pos_embed.py\n\ndef get_2d_sincos_pos_embed(embed_dim, start, *args, cls_token=False, extra_tokens=0):\n    \"\"\"\n    grid_size: int of the grid height and width\n    return:\n    pos_embed: [grid_size*grid_size, embed_dim] or [1+grid_size*grid_size, embed_dim] (w/ or w/o cls_token)\n    \"\"\"","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy/ldm/hydit/posemb_layers.py#L33-L69","documentation":"Raised by the HyDiT _to_tuple_range helper used to build 2D positional-embedding grids: it accepts 0, 1, or 2 positional range arguments (start-only, start+stop, start+stop+num) and rejects anything else. It guards internal grid math, not user input.","triggerScenarios":"Internal callers pass the wrong arity when computing get_fill_resize_and_crop sub_args for 'base' rope_img modes; externally reachable only through patched/misused code paths calling the helper directly with 3+ args.","commonSituations":"Monkey-patching or reusing posemb helpers with signatures from a different upstream version, or hand-rolling rope calls with extra arguments.","solutions":["Call the helper with at most (stop) or (stop, num) positional args alongside start","Prefer the public calc_sizes/init_image_posemb wrappers instead of the low-level grid function","Check the function signature of the vendored posemb_layers version you are calling"],"exampleFix":"# before\ngrid = get_2d_rotary_pos_embed(dim, (start, stop, num))  # 3 args -> ValueError\n# after\ngrid = get_2d_rotary_pos_embed(dim, stop, num)","handlingStrategy":"type-guard","validationCode":"assert len(args) <= 2, f\"too many range args: {args}\"","typeGuard":"def valid_posemb_args(start, args) -> bool:\n    return len(args) in (0, 1, 2)","tryCatchPattern":null,"preventionTips":["Use the high-level init_image_posemb/calc_sizes wrappers","Pin to the vendored posemb_layers signature when patching"],"tags":["hydit","rope","positional-embedding","arity"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}