Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import_meta_graph: ValueError: At least two variables have the same name: Variable_1 #4603

Closed
snbuchholz opened this issue Sep 27, 2016 · 2 comments

Comments

@snbuchholz
Copy link

snbuchholz commented Sep 27, 2016

What related GitHub issues or StackOverflow threads have you found by searching the web for your problem?

None

Environment info

Operating System: Ubuntu 16.04.1 LTS
Installed version of CUDA and cuDNN: none
pip package: https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
$ python -c "import tensorflow; print(tensorflow.version)"
0.10.0

If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)

Using commands from https://www.tensorflow.org/versions/r0.9/get_started/index.html to create a model:

import tensorflow as tf
import numpy as np
x_data = np.random.rand(100).astype(np.float32)
y_data = x_data * 0.1 + 0.3
W = tf.Variable(tf.random_uniform([1], -1.0, 1.0))
b = tf.Variable(tf.zeros([1]))
y = W * x_data + b
loss = tf.reduce_mean(tf.square(y - y_data))
optimizer = tf.train.GradientDescentOptimizer(0.5)
train = optimizer.minimize(loss)
init = tf.initialize_all_variables()
sess = tf.Session()
sess.run(init)
sess.run(train)

Then this works:

saver = tf.train.Saver()
saver.save(sess, 'my-model')
sess = tf.Session()
new_saver = tf.train.import_meta_graph('my-model.meta')

But this doesn't:

tf.train.export_meta_graph(filename='my-model.meta')
new_saver = tf.train.import_meta_graph('my-model.meta')

Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1458, in import_meta_graph
return _import_meta_graph_def(read_meta_graph_file(meta_graph_or_file))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1386, in _import_meta_graph_def
return Saver()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 861, in init
restore_sequentially=restore_sequentially)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 502, in build
vars_to_save = self._ValidateAndSliceInputs(names_to_variables)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 399, in _ValidateAndSliceInputs
names_to_variables = self._VarListToDict(names_to_variables)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 377, in _VarListToDict
name)
ValueError: At least two variables have the same name: Variable_1

What I actually want to use is this, which also does not work (same error):

meta_graph_def = tf.train.export_meta_graph()
saver = tf.train.import_meta_graph(meta_graph_def)

I need a solution that does not rely on the file system.
Am I doing something wrong?

What other attempted solutions have you tried?

I tried to look at the files to see where these duplicated names occur but did not find any.

@concretevitamin
Copy link
Contributor

You should call tf.train.import_meta_graph() with a cleared Graph. Example:

    # Create a clean graph and import the MetaGraphDef nodes.
    new_graph = tf.Graph()
    with tf.Session(graph=new_graph) as sess:
      # Import the previously export meta graph.
      saver = tf.train.import_meta_graph(meta_graph_def)

Please feel free to reopen if this doesn't solve the issue.

@snbuchholz
Copy link
Author

Thanks! This information was missing from https://www.tensorflow.org/versions/r0.9/how_tos/meta_graph/index.html

copybara-service bot pushed a commit that referenced this issue Jul 31, 2023
Imported from GitHub PR openxla/xla#4603

there are few build errors in ROCm side

1. tsl//tsl/platform:random duplicate in bazel build
2. we haven't fully enable triton_softmax_fusion (ROCm triton backend is WIP)
3. some include errors between hipblas-lt and gpu.graph PR

This PR has fixed all the above on ROCm side.

Thanks in advance @akuegel  @ddunl
Copybara import of the project:

--
4693e3db33ea8c87c17d4f9de7f7a1fea53013b0 by Chao Chen <cchen104@amd.com>:

fixed rocm build error

Merging this change closes #4603

PiperOrigin-RevId: 552428986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants