d2l-ai / d2l-en

Interactive deep learning book with multi-framework code, math, and discussions. Adopted at 500 universities from 70 countries including Stanford, MIT, Harvard, and Cambridge.
https://D2L.ai
Other
23.94k stars 4.36k forks source link

[TF] Can we make slight modifications to `#@tab all` sections of code #1755

Closed biswajitsahoo1111 closed 3 years ago

biswajitsahoo1111 commented 3 years ago

#@tab all sections of code are meant to be the same for all frameworks. But the following code chunk at the beginning of section 17.1 gives an error in TF-2.5.0.

#@tab tensorflow
%matplotlib inline
from d2l import tensorflow as d2l
import tensorflow as tf

#@tab all
X = d2l.normal(0.0, 1, (1000, 2)) 
A = d2l.tensor([[1, 2], [-0.1, 0.5]])
b = d2l.tensor([1, 2])
data = d2l.matmul(X, A) + b

However, if we modify the #@tab all section slightly, it runs without any issue.

#@tab tensorflow
%matplotlib inline
from d2l import tensorflow as d2l
import tensorflow as tf

#@tab all
X = d2l.normal(mean = 0.0, stddev = 1, shape = (1000, 2))
A = d2l.tensor([[1, 2], [-0.1, 0.5]])
b = d2l.tensor([1, 2], dtype = tf.float32)
data = d2l.matmul(X, A) + b

So without changing the essence of the code, can we modify #@tab all sections? I would be happy to know if there is any way around. I encountered this issue while trying to create a pull request for TF implementation of GAN chapter. Running TF code for the same can be found here.

astonzhang commented 3 years ago

Thanks. We'll probably modify syntax in https://github.com/d2l-ai/d2l-en/blob/master/config.ini#L106 when upgrading tf in future versions. For now tf stays at an older version due to other issues related to d2l API doc generation.