Comments (5)
@Shuolongbj you mean changing the docs or change sonnet in order to behave the same way for both examples? The latter I'm not sure how to do, any insight is much appreciated.
from sonnet.
@tfgg any feedback on this?
from sonnet.
@vierja The reason for the discrepancy is that _enter_variable_scope vs defining submodules in _build only unifies the variable_scopes entered, meaning that the variables have the same name whichever way round you do it. However, every time you enter the variable_scope you get a new name scope which will be uniquified if necessary by adding _N. The Tensorboard graph visualises namescopes, rather than variable scopes per se, although there is obviously overlap.
In your second example, the variables (and the ops associated with them - read, assign, init etc) are inside the first time you enter name_scope, which is main_module
at the bottom. When you call _build, you reenter a name_scope with the same name and TF uniquifies it to main_module_1
, and you see the add and matmul inside the smaller block up top. If you connect the module a second time you would get another small block, main_module_2
, with again just a Matmul and Add inside. Similarly, if you connect the module a second as you have it written in the first module, you also get a second block as the name_scope is entered a second time.
I don't think it's possible to change this name_scope behaviour without some hacking of TF, and I don't think that would necessarily be desirable - when connecting modules multiple times you probably want that to show as separate name_scopes in Tensorboard. Otherwise, a module shared lots of times would end up looking extremely confusing as all the input / output connections go through one block.
I hope this explanation helps - please let me know if you have other comments or questions.
from sonnet.
Thanks for bringing this to our attention. The issue here is that _enter_variable_scope()
enters a tf.variable_scope()
, which creates a name scope. This ultimately increments the counter the tf.Graph
object uses to uniquify name scopes. The result is that if you use _enter_variable_scope()
to define variables inside __init__
, then when _build()
is called for the first time the name scope has "_1" appended to it.
This is common behavior in TensorFlow and occurs when variables are created before they are used, for example:
with tf.variable_scope("scope"):
v = tf.get_variable("v", shape=[])
with tf.variable_scope("scope", reuse=True):
# We have now entered the name_scope "scope_1"
x = v * 2
It sounds like you want to enter a variable scope without entering a name scope. I would advise against this, because it can lead to even weirder graphs (what happens if you accidentally create an Op?) and isn't possible with public TensorFlow functions. Did you have a different solution in mind?
from sonnet.
@malcolmreynolds and @fastturtle, thank you guys for your explanations and for making me understand why it wouldn't be necessarily an undesirable behavior. I can't think of a different solution and mostly it seems that this is the desired visualization. I appreciate your time.
from sonnet.
Related Issues (20)
- how to remove model from gpu memory? HOT 1
- Understanding how to use mixed precision training HOT 2
- Conv2D initialize error in tf function
- Typo HOT 1
- this portion of attention code looks incorrect
- Cannot install sonnet on mac m1 HOT 5
- Decaying learning rate HOT 1
- Can you explain the logic of updated_ema_cluster_size in VectorQuantizerEMA?
- Convert a Sonnet model to a Keras model HOT 1
- (Maybe) in-consistency between VQ-VAE paper and its implementation. HOT 2
- Regarding LearningRateSchedule for ADAM optimizer HOT 2
- Learning rate and optimizer used for the VQ-VAE-2 paper HOT 2
- I have a question about the perplexity term (in the VQ-VAE). HOT 2
- Issues using Sonnet HOT 3
- How to save the checkpoint for self-defined model?
- TensorArray Not Used on line 71 of sgd_test.py HOT 2
- Is there a stereotypical way to visualize the network strucuture when using Sonnet? HOT 1
- sonnet abstract module in tensorflow2 HOT 10
- Laplace smoothing for EMA codebook update
- Basic import fails on Colab: cannot import name 'context' from 'tensorflow.python' HOT 11
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 sonnet.