Skip to content

BUG: populating the identity cache is not thread safe #27386

@jakevdp

Description

@jakevdp

Describe the issue:

Using np.finfo and np.iinfo with Python 3.13/numpy 2.1 free-threading can lead to errors like the following:

  >     return ml_dtypes.finfo(dtype).min < 0
  E     RuntimeError: Identity cache already includes an item with this key.

(source: https://github.com/jax-ml/ml_dtypes/actions/runs/10840175629/job/30081990075?pr=188)
ml_dtypes.finfo inherits from numpy.finfo, and this error is coming from the NumPy implementation; looks to be a race condition when multiple threads hit the Identity cache at once.

Python and NumPy Versions:

Python 3.13; numpy 2.1

Metadata

Metadata

Assignees

Labels

00 - Bug39 - free-threadingPRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions