jax-ml/jax · error · XlaRuntimeError

Malformed pickled GetAttrKey, expected 1-tuple

Error message

Malformed pickled GetAttrKey, expected 1-tuple

What it means

GetAttrKey.__setstate__ requires a 1-tuple state containing the attribute name string. Any other length is malformed.

Source

Thrown at jaxlib/pytree.cc:1977

    }
    new (&key) DictKey(nb::cast<nb::object>(state[0]));
  });

  nb::class_<GetAttrKey> get_attr_key(
      pytree, "GetAttrKey", nb::sig("class GetAttrKey(typing.Hashable)"));
  get_attr_key.def(nb::init<nb::str>(), nb::arg("name"));
  get_attr_key.def("__str__", &GetAttrKey::ToString);
  get_attr_key.def("__repr__", &GetAttrKey::ToReprString);
  get_attr_key.def("__eq__", &GetAttrKey::Equals);
  get_attr_key.def("__hash__",
                   [](const GetAttrKey& key) { return nb::hash(key.name()); });
  get_attr_key.def_prop_ro("name", &GetAttrKey::name);
  get_attr_key.def_prop_ro_static("__match_args__", &GetAttrKey::MatchArgs);
  get_attr_key.def("__getstate__",
                   [](GetAttrKey& key) { return nb::make_tuple(key.name()); });
  get_attr_key.def("__setstate__", [](GetAttrKey& key, const nb::tuple& state) {
    if (state.size() != 1) {
      throw xla::XlaRuntimeError(
          "Malformed pickled GetAttrKey, expected 1-tuple");
    }
    new (&key) GetAttrKey(nb::str(state[0]));
  });

  nb::class_<FlattenedIndexKey> flattened_index_key(
      pytree, "FlattenedIndexKey",
      nb::sig("class FlattenedIndexKey(typing.Hashable)"));
  flattened_index_key.def(nb::init<int>(), nb::arg("key"));
  flattened_index_key.def("__str__", &FlattenedIndexKey::ToString);
  flattened_index_key.def("__repr__", &FlattenedIndexKey::ToReprString);
  flattened_index_key.def("__eq__", &FlattenedIndexKey::Equals);
  flattened_index_key.def("__hash__", [](const FlattenedIndexKey& key) {
    return key.key() + kFlattenedIndexKeyHashSalt;
  });
  flattened_index_key.def_prop_ro("key", &FlattenedIndexKey::key);
  flattened_index_key.def_prop_ro_static("__match_args__",
                                         &FlattenedIndexKey::MatchArgs);

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Re-create pickles with matching jaxlib versions
  2. Do not modify pickle state tuples
Defensive patterns

Strategy: validation

Validate before calling

def valid_getattr_key_state(s) -> bool:
    return isinstance(s, tuple) and len(s) == 1 and isinstance(s[0], str)

Prevention

When it happens

Trigger: Unpickling a jaxlib.pytree.GetAttrKey with a state tuple of length != 1.

Common situations: Incompatible jaxlib versions between pickle producer and consumer; hand-crafted state.

Understand the failure class

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/3e8b0afebaafb1f1. Report an issue: GitHub.