{"record":{"id":"c11d3fbdc9a99a3d","repo":"jax-ml/jax","slug":"finalize-is-not-implemented","errorCode":null,"errorMessage":"Finalize is not implemented","messagePattern":"Finalize is not implemented","errorType":"exception","errorClass":"std::runtime_error","httpStatus":null,"severity":"error","filePath":"jaxlib/jax.cc","lineNumber":380,"sourceCode":"                 nb::bytes(serialized->data(), serialized->size()));\n           })\n      .def(\"__setstate__\", [](xla::PjRtLayout* self, nb::tuple t) {\n        nb::bytes serialized = nb::cast<nb::bytes>(t[0]);\n        absl::StatusOr<std::shared_ptr<const xla::PjRtLayout>> layout =\n            xla::PjRtLayout::Deserialize(\n                std::string_view(serialized.c_str(), serialized.size()));\n        xla::ThrowIfError(layout.status());\n        new (self) xla::PjRtLayout((*layout)->xla_layout());\n      });\n\n  nb::class_<xla::cpu::CpuCollectives> cpu_collectives(m, \"CpuCollectives\");\n  cpu_collectives\n      .def(\"Init\",\n           [](xla::cpu::CpuCollectives*) {\n             throw std::runtime_error(\"Init is not implemented\");\n           })\n      .def(\"Finalize\", [](xla::cpu::CpuCollectives*) {\n        throw std::runtime_error(\"Finalize is not implemented\");\n      });\n\n  m.def(\n      \"make_gloo_tcp_collectives\",\n      [](std::shared_ptr<xla::DistributedRuntimeClient> distributed_client,\n\n         std::optional<std::string> hostname,\n         std::optional<std::string> interface)\n          -> std::shared_ptr<xla::cpu::CpuCollectives> {\n#if defined(__linux__)\n        std::shared_ptr<xla::KeyValueStoreInterface> kv_store = nullptr;\n        if (distributed_client != nullptr) {\n          kv_store = GetDistributedKeyValueStore(distributed_client,\n                                                 /*key_prefix=*/\"cpu:\");\n        }\n        auto gloo_kv_store =\n            std::make_unique<xla::cpu::GlooKeyValueStore>(kv_store);\n        auto tcp_attrs = gloo::transport::tcp::attr();","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jaxlib/jax.cc#L362-L398","documentation":"CpuCollectives.Finalize() is a deliberate stub; teardown is handled by the C++ destructor / garbage collection of the collectives object, not by an explicit Python call.","triggerScenarios":"Calling CpuCollectives.Finalize() explicitly at shutdown in Python.","commonSituations":"Distributed scripts adding symmetric init/finalize cleanup calls borrowed from MPI-style APIs.","solutions":["Delete the Finalize() call; rely on object deallocation","For deterministic teardown, del the collectives reference and force gc.collect()"],"exampleFix":"# before\ntry:\n    coll.Finalize()\nfinally:\n    pass\n# after\n# no explicit finalize needed","handlingStrategy":"validation","validationCode":"pass  # do not call Finalize(); GC handles teardown","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Drop references to collectives for cleanup; avoid MPI-style finalize patterns"],"tags":["jax","collectives","cpu","api-misuse"],"backgroundTag":"unsupported-api-call","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}