{"record":{"id":"9b2e4520bcc627fc","repo":"jax-ml/jax","slug":"got-invalid-memory-kind-s-valid-memory-kinds-ar","errorCode":null,"errorMessage":"Got invalid memory kind: %s. Valid memory kinds are: %s","messagePattern":"Got invalid memory kind: (.+?)\\. Valid memory kinds are: (.+?)","errorType":"validation","errorClass":"nb::value_error","httpStatus":null,"severity":"error","filePath":"jaxlib/sharding.cc","lineNumber":156,"sourceCode":"      mesh_(std::move(mesh)),\n      spec_(std::move(spec)),\n      memory_kind_(std::move(memory_kind)),\n      logical_device_ids_(std::move(logical_device_ids)) {\n  nb::object idl = nb::object(mesh_.attr(\"_internal_device_list\"));\n  if (idl.is_none()) {\n    internal_device_list_ = std::nullopt;\n  } else {\n    internal_device_list_ = nb::cast<nb_class_ptr<PyDeviceList>>(idl);\n  }\n  if (internal_device_list_) {\n    memory_kind_ =\n        CheckAndCanonicalizeMemoryKind(memory_kind_, *internal_device_list_);\n  } else {\n    if (!memory_kind_.is_none() &&\n        (std::find(valid_memory_kinds.begin(), valid_memory_kinds.end(),\n                   nb::cast<std::string_view>(memory_kind_)) ==\n         valid_memory_kinds.end())) {\n      throw nb::value_error(\n          absl::StrCat(\"Got invalid memory kind: \",\n                       nb::cast<std::string_view>(memory_kind_),\n                       \". Valid memory kinds are: \",\n                       absl::StrJoin(valid_memory_kinds, \", \"))\n              .c_str());\n    }\n  }\n\n  // TODO(phawkins): this leaks a reference to the check_pspec function.\n  // A better way to fix this would be to move PartitionSpec and this check into\n  // C++.\n  static xla::SafeStatic<nb::object> check_pspec_init;\n  nb::object& check_pspec = check_pspec_init.Get([]() {\n    nb::module_ si = nb::module_::import_(\"jax._src.named_sharding\");\n    return std::make_unique<nb::object>(si.attr(\"check_pspec\"));\n  });\n  check_pspec(mesh_, spec_);\n}","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/sharding.cc#L138-L174","documentation":"NamedSharding's constructor validates an explicitly passed memory_kind against the list of valid memory kinds ('device', 'pinned_host_memory', 'unpinned_host_memory', and backend-specific kinds). An unknown string raises this value error listing the valid options.","triggerScenarios":"Constructing jax.sharding.NamedSharding(device, memory_kind='...') with a string not in the valid set — most commonly the literal 'hbm', which is not a valid kind (the HBM kind is named 'device').","commonSituations":"Assuming 'hbm' is a valid memory kind; copy-pasting device memory names from hardware docs into memory_kind; backend-specific kinds used on a different backend.","solutions":["Use 'device' instead of 'hbm' for device/accelerator memory","Omit memory_kind to use the default device memory","Pick from the valid list in the message: typically 'device', 'pinned_host_memory', 'unpinned_host_memory'"],"exampleFix":"# before\nNamedSharding(dev, memory_kind='hbm')\n\n# after\nNamedSharding(dev, memory_kind='device')","handlingStrategy":"type-guard","validationCode":"VALID = {'device', 'pinned_host_memory', 'unpinned_host_memory'}\nif memory_kind is not None and memory_kind not in VALID:\n    raise ValueError(f'use one of {VALID}')","typeGuard":"def is_valid_memory_kind(kind: str | None) -> bool:\n    return kind is None or kind in {'device', 'pinned_host_memory', 'unpinned_host_memory'}","tryCatchPattern":"try:\n    sh = jax.sharding.NamedSharding(dev, memory_kind=kind)\nexcept ValueError:\n    sh = jax.sharding.NamedSharding(dev, memory_kind='device')","preventionTips":["Use 'device', not 'hbm'","Centralize memory-kind strings in one constant"],"tags":["jax","sharding","memory-kind"],"backgroundTag":"invalid-device-memory-kind","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}