NVlabs / sionna

Sionna: An Open-Source Library for Next-Generation Physical Layer Research
https://nvlabs.github.io/sionna
Other
735 stars 211 forks source link

Demapper doesn't work with Tensorflow versions 2.16.0+ #541

Open jso8910 opened 1 month ago

jso8910 commented 1 month ago

Due to a change in Tensorflow 2.16 (Keras3 no longer has support for complex data types for layers), Demapper is non-functional, returning the following error message (with the personally identifying absolute path removed):

Traceback (most recent call last):
  File "venv/lib/python3.12/site-packages/keras/src/dtype_policies/dtype_policy.py", line 86, in _parse_name
    dtype = backend.standardize_dtype(name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/keras/src/backend/common/variables.py", line 521, in standardize_dtype
    raise ValueError(f"Invalid dtype: {dtype}")
ValueError: Invalid dtype: complex64

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ldpc_test_sionna.py", line 16, in <module>
    demapper = mapping.Demapper("app", "qam", num_bits_per_symbol=1, dtype="complex64")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/sionna/mapping.py", line 964, in __init__
    super().__init__(dtype=dtype, **kwargs)
  File "venv/lib/python3.12/site-packages/keras/src/layers/layer.py", line 249, in __init__
    Operation.__init__(self, dtype=dtype, name=name)
  File "/Users/jason/CS_EE_CODE/venv/lib/python3.12/site-packages/keras/src/ops/operation.py", line 26, in __init__
    self._dtype_policy = dtype_policies.get(dtype)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/keras/src/dtype_policies/__init__.py", line 100, in get
    return DTypePolicy(identifier)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/keras/src/dtype_policies/dtype_policy.py", line 64, in __init__
    self._compute_dtype, self._variable_dtype = self._parse_name(name)
                                                ^^^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.12/site-packages/keras/src/dtype_policies/dtype_policy.py", line 89, in _parse_name
    raise ValueError(
ValueError: Cannot convert 'complex64' to a mixed precision DTypePolicy. Valid policies include 'mixed_float16', 'mixed_bfloat16', and the name of any float dtype such as 'float32'.

Attempted (and functional) workaround:

  1. Downgrade to Python <= 3.11
  2. run "pip install tensorflow==2.15" (only 2.15 and lower work)

However this is a poor workaround. An immediately actionable fix would be to change requirements.txt to not support tensorflow 2.16 as well as removing Sionna from PyPi for Python 3.12 (which tensorflow 2.16 doesn't support).

There is already an issue on the tensorflow repo: https://github.com/tensorflow/tensorflow/issues/65306 There is also a feature request with confirmation that the maintainers of keras are working on it: https://github.com/keras-team/keras/issues/19860

jhoydis commented 1 month ago

Hi @jso8910,

Thanks for reporting this issue. We are aware of this problem and it is the reason why we restrict already the requirements to tensorflow < 2.16.0. There's unfortunately not much we can do apart from letting the Keras team know that we need this feature. I have commented on keras-team/keras#19872.

If you really need Tensorflow 2.16 or higher, you can still use it with Keras 2 by following the steps described here https://blog.tensorflow.org/2024/03/whats-new-in-tensorflow-216.html.