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

uniform_unit_scaling_initializer full_shape #6

Open
adelra opened this issue Apr 8, 2018 · 19 comments
Open

uniform_unit_scaling_initializer full_shape #6

adelra opened this issue Apr 8, 2018 · 19 comments

Comments

@adelra
Copy link

adelra commented Apr 8, 2018

Hi, I'm trying to run the code on Google Colab but I'm facing the following error:

/usr/local/lib/python3.6/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
WARNING:tensorflow:From /content/drive/app/lm-master/model_utils.py:18: UniformUnitScaling.__init__ (from tensorflow.python.ops.init_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.initializers.variance_scaling instead with distribution=uniform to get equivalent behavior.
Traceback (most recent call last):
  File "drive/app/lm-master/single_lm_train.py", line 38, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "drive/app/lm-master/single_lm_train.py", line 27, in main
    run_train(dataset, hps, FLAGS.logdir + "/train", ps_device="/gpu:0")
  File "/content/drive/app/lm-master/run_utils.py", line 14, in run_train
    model = LM(hps, "train", ps_device)
  File "/content/drive/app/lm-master/language_model.py", line 24, in __init__
    loss = self._forward(i, xs[i], ys[i], ws[i])
  File "/content/drive/app/lm-master/language_model.py", line 62, in _forward
    emb_vars = sharded_variable("emb", [hps.vocab_size, hps.emb_size], hps.num_shards)
  File "/content/drive/app/lm-master/model_utils.py", line 18, in sharded_variable
    initializer = tf.uniform_unit_scaling_initializer(dtype=dtype, full_shape=shape)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 250, in new_func
    return func(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'full_shape'

I see that in the new version of tf the full_shape is no longer an argument of uniform_unit_scaling_initializer.
I tried removing the shape argument to test, but I faced another error:


/usr/local/lib/python3.6/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
WARNING:tensorflow:From /content/drive/app/lm-master/model_utils.py:18: UniformUnitScaling.__init__ (from tensorflow.python.ops.init_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.initializers.variance_scaling instead with distribution=uniform to get equivalent behavior.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 510, in _apply_op_helper
    preferred_dtype=default_dtype)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 1036, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py", line 879, in _TensorTensorConversionFunction
    (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype float32: 'Tensor("model/model/dropout/mul:0", shape=(512,), dtype=float32, device=/gpu:0)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "drive/app/lm-master/single_lm_train.py", line 38, in <module>
    tf.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 126, in run
    _sys.exit(main(argv))
  File "drive/app/lm-master/single_lm_train.py", line 27, in main
    run_train(dataset, hps, FLAGS.logdir + "/train", ps_device="/gpu:0")
  File "/content/drive/app/lm-master/run_utils.py", line 14, in run_train
    model = LM(hps, "train", ps_device)
  File "/content/drive/app/lm-master/language_model.py", line 24, in __init__
    loss = self._forward(i, xs[i], ys[i], ws[i])
  File "/content/drive/app/lm-master/language_model.py", line 68, in _forward
    inputs = [tf.squeeze(v, [1]) for v in tf.split(1, hps.num_steps, x)]
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 1366, in split
    axis=axis, num_split=num_or_size_splits, value=value, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 5069, in _split
    "Split", split_dim=axis, value=value, num_split=num_split, name=name)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 533, in _apply_op_helper
    (prefix, dtypes.as_dtype(input_arg.type).name))
TypeError: Input 'split_dim' of 'Split' Op has type float32 that does not match expected type of int32.

Then I tried to convert num_steps into int32 which was unsuccessful.

Basically above is my unsuccessful attempt in fixing this error. What should I do about it and how can I handle shape argument in uniform_unit_scaling_initializer

@nellymin
Copy link

@adelra Any solution you might have found?

@ciprian-chelba
Copy link

ciprian-chelba commented Aug 15, 2018 via email

@okoub
Copy link

okoub commented Oct 10, 2018

@nellymin @adelra @ciprian-chelba @rafaljozefowicz Any success fixing this issues? I tried to change inputs = [tf.squeeze(v, [1]) for v in tf.split(1, hps.num_steps, x)]

to inputs = [ tf.squeeze(v, [1]) for v in tf.split(value=x, num_or_size_splits=hps.num_steps, axis=1) ]

But I still get this error

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 10, 2018 via email

@okoub
Copy link

okoub commented Oct 13, 2018

@ciprian-chelba Yes the error is

File "/content/drive/app/lm-master/model_utils.py", line 18, in sharded_variable
    initializer = tf.uniform_unit_scaling_initializer(dtype=dtype,
full_shape=shape)

Sorry but I didn't understand what you are proposing or what are the links you sent? I need to enter username + password to see it

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 13, 2018 via email

@okoub
Copy link

okoub commented Oct 13, 2018

@ciprian-chelba Can you please put the code? I can't go into these links

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 13, 2018 via email

@okoub
Copy link

okoub commented Oct 14, 2018

@ciprian-chelba So can you please share the code or write what I need to do?

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 15, 2018 via email

@shocho3858
Copy link

OK, Here is the implementation for sharded_variable I am using: def sharded_variable(name, shape, num_shards, init_factor=1.0, initializer=None, dtype=tf.float32): """Sharded version of get_variable. Args: name: variable name. shape: variable shape. num_shards: number of desired shards. init_factor: to be used by tf.uniform_unit_scaling_initializer. initializer: if initializer is None then use tf.uniform_unit_scaling_initializer o/w use the one specified. Set to something other than None only for unit tests. dtype: data type. Returns: list of variables with name suffixed by '' + shard_number. """ # The final size of the sharded variable may be larger than requested. # This should be fine for embeddings. shard_size = int((shape[0] + num_shards - 1) / num_shards) # The full_shape argument is no longer available in v0.12 of TensorFlow. # We guess at this using the number of shards. if initializer is None: init = tf https://cs.corp.google.com/piper///depot/google3/third_party/py/lm_lstm_1Bwds/model_utils.py?l=4&ct=xref_jump_to_def&gsn=tf&rcl=216954548.uniform_unit_scaling_initializer( factor=init_factor * num_shards, dtype=dtype) else: init = initializer return [ tf.get_variable( name + '%d' % i https://cs.corp.google.com/piper///depot/google3/third_party/py/lm_lstm_1Bwds/model_utils.py?l=49&ct=xref_jump_to_def&gsn=i&rcl=216954548, [shard_size, shape[1]], initializer=init, dtype=dtype) for i in range(num_shards) ]

On Sun, Oct 14, 2018 at 12:21 AM okoub @.***> wrote: @ciprian-chelba https://github.com/ciprian-chelba So can you please share the code or write what I need to do? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#6 (comment)>, or mute the thread https://github.com/notifications/unsubscribe-auth/AK_u-_WMUvTwD9ArbP8UuSOI8QwiCXroks5ukuXygaJpZM4TLY8n .
-- -Ciprian

I have the same error as @adelra . Would u please post the code in a good format? The one before is not even readable.

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 16, 2018 via email

@okoub
Copy link

okoub commented Oct 22, 2018

@ciprian-chelba When using your code I get the error:

lm/run_utils.py", line 14, in run_train
    model = LM(hps, "train", ps_device)
  File "lm/language_model.py", line 24, in __init__
    loss = self._forward(i, xs[i], ys[i], ws[i])
  File "lm/language_model.py", line 72, in _forward
    for v in tf.split(value=x, num_or_size_splits=hps.num_steps, axis=1)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1326, in split
    axis=axis, num_split=num_or_size_splits, value=value, name=name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7897, in split
    "Split", split_dim=axis, value=value, num_split=num_split, name=name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
    return func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3272, in create_op
    op_def=op_def)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1790, in __init__
    control_input_ops)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1629, in _create_c_op
    raise ValueError(str(e))
ValueError: Dimension size, given by scalar input 1 must be in range [-1, 1) for 'model/model/split' (op: 'Split') with input shapes: [], [512] and with computed input tensors: input[0] = <1>.

Any idea?

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 22, 2018 via email

@okoub
Copy link

okoub commented Oct 24, 2018

@ciprian-chelba I use 1-billion-word-language-modeling-benchmark.
I run it like that:
python3 single_lm_run.py --datadir ./1-billion-word-language-modeling-benchmark/ --logdir a.txt

@ciprian-chelba
Copy link

ciprian-chelba commented Oct 24, 2018 via email

@yhifny
Copy link

yhifny commented Dec 20, 2018

Any one solved this error? if yes, can you please share the required modification.

@nellymin
Copy link

nellymin commented Jan 7, 2019

@yhifny This branch from @lopuhin is fitted for newer version of tensorflow but contains some extra files you might want to remove

@gptshubham595
Copy link

gptshubham595 commented Mar 4, 2019

just go to cmd and write pip install tflearn==0.3.1
and install old version of tflearn

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

7 participants