Comments (3)
@tonyherschel Could you try to consider explicitly clearing the cache every period.
You could also try to control the caching behavior with the jit_compile option within @tf.function by setting jit_compile to False as follows;
@tf.function(jit_compile=False)
def model(x):
Thank you!
from tensorflow.
Hi, @sushreebarsa, thanks for your reply! I tried setting jit_compile to False in the @tf.function, but the results do not seem to have changed.
import os
import random
import numpy as np
import tensorflow as tf
# set seeds
SEED = 0
random.seed(SEED)
np.random.seed(SEED)
tf.random.set_seed(SEED)
os.environ['PYTHONHASHSEED'] = str(SEED)
tf.keras.utils.set_random_seed(SEED)
tf.config.experimental.enable_op_determinism()
@tf.function(jit_compile=False)
def model(x):
err = tf.random.uniform(shape=(1,))
loss = x + err
return err, loss
optimizer = tf.keras.optimizers.Adam(learning_rate=1e-3)
training_periods = 10
# initialize x
x = tf.Variable(tf.random.uniform(shape=(1,)), trainable=True)
for tt in range(training_periods):
if tt % 2 == 0:
with tf.GradientTape() as tape:
err, loss = model(x)
gradients = tape.gradient(loss, [x]) # suppose x need to be optimized
optimizer.apply_gradients(zip(gradients, [x])) # update x
print(f"Period: {tt}, err (trained): {err.numpy()}")
else:
err, loss = model(x)
print(f"Period: {tt}, err (not trained): {err.numpy()}")
log outputs
Period: 0, err (trained): [0.01975703]
Period: 1, err (not trained): [0.01975703]
Period: 2, err (trained): [0.5400312]
Period: 3, err (not trained): [0.5400312]
Period: 4, err (trained): [0.51667833]
Period: 5, err (not trained): [0.51667833]
Period: 6, err (trained): [0.4683528]
Period: 7, err (not trained): [0.4683528]
Period: 8, err (trained): [0.14856052]
Period: 9, err (not trained): [0.14856052]
from tensorflow.
@SuryanarayanaY I was able to replicate the issue reported here. Thank you!
from tensorflow.
Related Issues (20)
- Silent exception when using TFLiteConverter
- When should I include tensorflow-lite-gpu-delegate-plugin dependency in my android project? HOT 3
- Urgent: Report of Spam and Scam Activity on Your Website HOT 4
- `SIGSEGV ` (Address boundary error) in `tf.io.gfile` with `TF_USE_MODULAR_FILESYSTEM=1` HOT 1
- error: enumeration value 'dnnl_data_type_undef' not handled in switch HOT 5
- `tf.data.Dataset.load()` cannot load from a folder with bracket in the name HOT 4
- ValueError: Only instances of `keras.Layer` can be added to a Sequential model. Received: <tensorflow_probability.python.layers.dense_variational_v2.DenseVariational object at 0x000001C67AF5B4D0> (of type <class 'tensorflow_probability.python.layers.dense_variational_v2.DenseVariational'>) HOT 1
- Failure loading saved model (with tf2onnx)
- TF 2.17.0-rc0 compilation fails due to flag: `-mavx512fp16’; did you mean ‘-mavx512bf16’? HOT 6
- Unable to build TFLite GPU Delegate for Android on MacOS
- Training time for models HOT 2
- TFJS basic operations are extremely slow in comparison to Native JS HOT 2
- LINK error with dbg flag HOT 1
- whenever I try fitting a sequential model it doesn't work
- Can't load my model.h5 HOT 6
- รายงานปัญหาระหว่างการแปลงโมเดลเป็น TFLite HOT 1
- AttributeError: module 'keras.src.backend' has no attribute 'convert_to_numpy' HOT 2
- CUDA 11.4 Build error HOT 4
- Loading model error 'No such file or directory: 'model.weights.h5' HOT 9
- Building tensorflow 2.2.0 from source HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tensorflow.