{"record":{"id":"c4ef16179d17c47d","repo":"jax-ml/jax","slug":"cannot-specify-scope-to-a-non-uniform-debug-print","errorCode":null,"errorMessage":"Cannot specify scope to a non-uniform debug_print.","messagePattern":"Cannot specify scope to a non-uniform debug_print\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/utils.py","lineNumber":186,"sourceCode":"    if ir.IntegerType(arg.type).width < 64:\n      arg = arith.extui(ir.IntegerType.get_signless(64), arg)\n    return \"%llu\", arg\n  if isinstance(arg.type, ir.F32Type):\n    return \"%f\", arg\n  if isinstance(arg.type, ir.Float8E8M0FNUType):\n    return \"%u\", arith.extui(\n        ir.IntegerType.get_signless(32),\n        arith.bitcast(ir.IntegerType.get_signless(8), arg),\n    )\n  if isinstance(arg.type, (ir.BF16Type, ir.F16Type)):\n    arg = arith.extf(ir.F32Type.get(), arg)\n    return \"%f\", arg\n  raise NotImplementedError(f\"Can't print the type {arg.type}\")\n\n\ndef debug_print(fmt, *args, uniform=True, scope=None):\n  if not uniform and scope is not None:\n    raise ValueError(\"Cannot specify scope to a non-uniform debug_print.\")\n  if scope is None:\n    scope = ThreadSubset.WARPGROUP\n  type_formats = []\n  new_args = []\n  for arg in args:\n    if isinstance(arg.type, ir.VectorType):\n      vec_ty = ir.VectorType(arg.type)\n      if len(vec_ty.shape) > 1:\n        raise NotImplementedError(\n            f\"2D+ vectors are not supported in debug_print: {vec_ty}\"\n        )\n      vec_args = [\n          vector.extract(\n              arg,\n              dynamic_position=[],\n              static_position=ir.DenseI64ArrayAttr.get([i]),\n          )\n          for i in range(vec_ty.shape[0])","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/utils.py#L168-L204","documentation":"Raised by debug_print when the caller passes scope=... together with uniform=False. A 'non-uniform' debug print executes in every thread independently, so a single-threaded scope restriction only makes sense for uniform prints; mixing them is contradictory and rejected.","triggerScenarios":"Calling utils.debug_print(fmt, *args, uniform=False, scope=ThreadSubset.WARP) — any combination where uniform is False and scope is not None.","commonSituations":"Copy-pasting a uniform debug_print call and flipping uniform=False to see per-thread output while leaving the scope kwarg in place; refactoring shared debug macros that always pass scope.","solutions":["Drop the scope argument when using uniform=False","Or keep scope and use uniform=True (default) if you only want one thread per scope to print"],"exampleFix":"# before\ndebug_print('v={}', v, uniform=False, scope=ThreadSubset.WARPGROUP)\n# after\ndebug_print('v={}', v, uniform=False)","handlingStrategy":"validation","validationCode":"if not uniform and scope is not None:\n    scope = None  # scope only applies to uniform prints\ndebug_print(fmt, *args, uniform=uniform, scope=scope)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass scope only with uniform=True (the default)","Build small wrapper macros that encode the uniform/scope policy once"],"tags":["gpu","mosaic","debug-print","argument-validation"],"backgroundTag":"invalid-argument-combination","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}