# Dreamer V3 - Rllib, TensorFlow Error

**URL:** <https://discuss.ray.io/t/dreamer-v3-rllib-tensorflow-error/15127>\
**Category:** Uncategorized\
**Created:** [July 3, 2024, 9:30pm UTC](https://discuss.ray.io/t/dreamer-v3-rllib-tensorflow-error/15127 "2024-07-03T21:30:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ogulcan\_Kertmen](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ogulcan_kertmen/32/6281_2.png) [@Ogulcan\_Kertmen](https://discuss.ray.io/u/Ogulcan_Kertmen)\
**Post date:** [July 3, 2024, 9:30pm UTC](https://discuss.ray.io/t/dreamer-v3-rllib-tensorflow-error/15127/1 "2024-07-03T21:30:11Z")

</div>

Hello,

I am trying implemant Dreamer V3 to cartpole. My code suppose to work, but i got this error;

“ValueError: One of the parameters (\<KerasVariable shape=(4, 256), dtype=float32, path=dreamer\_model/vector\_encoder/dense/kernel\>) in the registered optimizer is not a tf.Variable!”

I think that is related DreamerV3Config. The error is caused by the relationship between DreamerV3Config and TensorFlow. But this seems very strange. DreamerV3Config is provided by rllib, so this should not contain errors.

Do you have any ideas how I can solve this problem?

Here is my code;

from ray.rllib.algorithms.dreamerv3.dreamerv3 import DreamerV3Config  
from ray.tune.logger import pretty\_print

config = (  
DreamerV3Config()  
.environment(“CartPole-v1”)  
.training(  
model\_size=“XS”,  
training\_ratio=1024,  
)  
)

algo = [config.build](http://config.build/)()

for i in range(10):  
result = algo.train()  
print(pretty\_print(result))

if i % 5 == 0:  
checkpoint\_dir = [algo.save](http://algo.save/)().checkpoint.path  
print(f"Checkpoint saved in directory {checkpoint\_dir}")

---

<div class="post-metadata">

**Author:** ![riccardo.paolini](https://avatars.discourse-cdn.com/v4/letter/r/4bbf92/32.png) [@riccardo.paolini](https://discuss.ray.io/u/riccardo.paolini)\
**Post date:** [August 12, 2024, 11:18am UTC](https://discuss.ray.io/t/dreamer-v3-rllib-tensorflow-error/15127/3 "2024-08-12T11:18:25Z")

</div>

Since tf 2.16 if you want to use keras 2 you have to set the environment variable `TF_USE_LEGACY_KERAS=1` or you can add the following lines of code:

import os  
os.environ[“TF\_USE\_LEGACY\_KERAS”]=”1”

Important: you have to set this variable before any import of tensorflow, otherwise it will not work.
