tensorflow/tensorboard

NumPy v2 Compatibility

daskol opened this issue ยท 3 comments

Missing compatibility with the major NumPy v2 release in the latest tensorboard==2.17.0 version.

    self._output.emit_scalar(
  File "/usr/lib/python3.12/dist-packages/tensorboard/summary/_output.py", line 109, in emit_scalar
    tensor_proto = tensor_util.make_tensor_proto(data)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/dist-packages/tensorboard/util/tensor_util.py", line 405, in make_tensor_proto
    numpy_dtype = dtypes.as_dtype(nparray.dtype)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/dist-packages/tensorboard/compat/tensorflow_stub/dtypes.py", line 677, in as_dtype
    if type_value.type == np.string_ or type_value.type == np.unicode_:
                          ^^^^^^^^^^
  File "/usr/lib/python3.12/dist-packages/numpy/__init__.py", line 397, in __getattr__
    raise AttributeError(
AttributeError: `np.string_` was removed in the NumPy 2.0 release. Use `np.bytes_` instead.. Did you mean: 'strings'?

@yatbear Hot-fix is here.

--- a/tensorboard/compat/tensorflow_stub/dtypes.py	2024-06-30 15:59:21.290476559 +0300
+++ b/tensorboard/compat/tensorflow_stub/dtypes.py	2024-06-30 15:59:29.377199428 +0300
@@ -674,7 +674,7 @@
         # dtype with a single constant (np.string does not exist) to decide
         # dtype is a "string" type. We need to compare the dtype.type to be
         # sure it's a string type.
-        if type_value.type == np.string_ or type_value.type == np.unicode_:
+        if type_value.type == np.bytes_ or type_value.type == np.str_:
             return string
 
     if isinstance(type_value, (type, np.dtype)):
--- a/tensorboard/util/tensor_util.py	2024-06-30 15:58:32.200133798 +0300
+++ b/tensorboard/util/tensor_util.py	2024-06-30 15:58:50.533595467 +0300
@@ -137,7 +137,7 @@
     # dtype with a single constant (np.string does not exist) to decide
     # dtype is a "string" type. We need to compare the dtype.type to be
     # sure it's a string type.
-    if dtype.type == np.string_ or dtype.type == np.unicode_:
+    if dtype.type == np.bytes_ or dtype.type == np.str_:
         return SlowAppendObjectArrayToTensorProto
     return GetFromNumpyDTypeDict(_NP_TO_APPEND_FN, dtype)
 

@daskol Thanks! The fix was merged at #6871 and it should be included in the latest tensorboard nightly.

Great! I've search for similar existing issue but found nothing.