trax
trax copied to clipboard
Failed to sample from the Reformer model
Description
Failed to sample from the Reformer model after training on my local machine. No codes changed.
Environment information
OS: Ubuntu 16.04 LTS
$ pip freeze | grep tensor
mesh-tensorflow==0.1.9
tensor2tensor==1.14.1
tensorboard==1.15.0
tensorboardcolab==0.0.22
tensorflow-datasets==2.0.0
tensorflow-estimator==1.15.1
tensorflow-gan==2.0.0
tensorflow-gpu==1.15.0
tensorflow-hub==0.7.0
tensorflow-metadata==0.21.1
tensorflow-privacy==0.2.2
tensorflow-probability==0.7.0
tensorflow-serving-api-gpu==1.13.0
tensorflow-tensorboard==0.4.0
$ pip freeze | grep jax
jax==0.1.57
jaxlib==0.1.37
$ python -V
Python 3.6.9 :: Anaconda, Inc.
For bugs: reproduction and error logs
# Steps to reproduce:
run Text Generation on the local machine
https://colab.research.google.com/github/google/trax/blob/master/trax/models/reformer/text_generation.ipynb#scrollTo=favRDt3U4CJY
# Error logs:
...
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/trax/layers/base.py in _forward_internal(self, x, weights, state, rng)
452 outputs, s = self.forward_with_state(
--> 453 x, weights=weights, state=state, rng=rng)
454 else:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/trax/layers/combinators.py in forward_with_state(self, xs, weights, state, **kwargs)
59 self._validate_forward_inputs(xs)
---> 60 rngs = _pop_rng_and_split(kwargs, self._n_layers)
61 if not self.sublayers: # No-op: leave args unchanged.
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/trax/layers/combinators.py in _pop_rng_and_split(args_dict, n_copies)
688 return (None,) * n_copies
--> 689 return math.random.split(rng, n_copies)
690
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/trax/math/backend.py in split(self, prng, num)
122 def split(self, prng, num=2):
--> 123 return backend()['random_split'](prng, num)
124
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/random.py in split(key, num)
243 """
--> 244 return _split(key, num)
245
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/api.py in f_jitted(*args, **kwargs)
148 flat_fun, out_tree = flatten_fun(f, in_tree)
--> 149 out = xla.xla_call(flat_fun, *args_flat, device=device, backend=backend)
150 return tree_unflatten(out_tree(), out)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
604 tracers = map(top_trace.full_raise, args)
--> 605 outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
606 return apply_todos(env_trace_todo(), outs)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/partial_eval.py in process_call(self, call_primitive, f, tracers, params)
125 fun, aux = partial_eval(f, self, in_pvs)
--> 126 out_flat = call_primitive.bind(fun, *in_consts, **params)
127 out_pvs, jaxpr, env = aux()
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
601 with new_sublevel():
--> 602 outs = primitive.impl(f, *args, **params)
603 else:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_call_impl(fun, *args, **params)
441 backend = params['backend']
--> 442 compiled_fun = _xla_callable(fun, device, backend, *map(arg_spec, args))
443 try:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in memoized_fun(fun, *args)
222 else:
--> 223 ans = call(fun, *args)
224 cache[key] = (ans, fun.stores)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_callable(fun, device, backend, *arg_specs)
458 with core.new_master(pe.StagingJaxprTrace, True) as master:
--> 459 jaxpr, (pvals, consts, env) = pe.trace_to_subjaxpr(fun, master, False).call_wrapped(pvals)
460 assert not env # no subtraces here
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in call_wrapped(self, *args, **kwargs)
151
--> 152 ans = self.f(*args, **dict(self.params, **kwargs))
153 del args
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/random.py in _split(key, num)
248 counts = lax.tie_in(key, lax.iota(onp.uint32, num * 2))
--> 249 return lax.reshape(threefry_2x32(key, counts), (num, 2))
250
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/api.py in f_jitted(*args, **kwargs)
148 flat_fun, out_tree = flatten_fun(f, in_tree)
--> 149 out = xla.xla_call(flat_fun, *args_flat, device=device, backend=backend)
150 return tree_unflatten(out_tree(), out)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
604 tracers = map(top_trace.full_raise, args)
--> 605 outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
606 return apply_todos(env_trace_todo(), outs)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/partial_eval.py in process_call(self, call_primitive, f, tracers, params)
125 fun, aux = partial_eval(f, self, in_pvs)
--> 126 out_flat = call_primitive.bind(fun, *in_consts, **params)
127 out_pvs, jaxpr, env = aux()
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
604 tracers = map(top_trace.full_raise, args)
--> 605 outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
606 return apply_todos(env_trace_todo(), outs)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/partial_eval.py in process_call(self, call_primitive, f, tracers, params)
125 fun, aux = partial_eval(f, self, in_pvs)
--> 126 out_flat = call_primitive.bind(fun, *in_consts, **params)
127 out_pvs, jaxpr, env = aux()
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
601 with new_sublevel():
--> 602 outs = primitive.impl(f, *args, **params)
603 else:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_call_impl(fun, *args, **params)
441 backend = params['backend']
--> 442 compiled_fun = _xla_callable(fun, device, backend, *map(arg_spec, args))
443 try:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in memoized_fun(fun, *args)
222 else:
--> 223 ans = call(fun, *args)
224 cache[key] = (ans, fun.stores)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_callable(fun, device, backend, *arg_specs)
458 with core.new_master(pe.StagingJaxprTrace, True) as master:
--> 459 jaxpr, (pvals, consts, env) = pe.trace_to_subjaxpr(fun, master, False).call_wrapped(pvals)
460 assert not env # no subtraces here
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in call_wrapped(self, *args, **kwargs)
151
--> 152 ans = self.f(*args, **dict(self.params, **kwargs))
153 del args
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/random.py in threefry_2x32(keypair, count)
215 """
--> 216 key1, key2 = keypair
217 if not lax.dtype(key1) == lax.dtype(key2) == lax.dtype(count) == onp.uint32:
ValueError: not enough values to unpack (expected 2, got 1)
During handling of the above exception, another exception occurred:
LayerError Traceback (most recent call last)
<ipython-input-30-58abfd2a9337> in <module>
1 # Sample from the Reformer language model, given a prefix.
----> 2 samples = sample(length=128, prompt="There was a time when")
3 for ids in samples:
4 print(TOKENIZER.DecodeIds(ids.tolist()))
<ipython-input-29-f9fee3fa3424> in sample(length, prompt)
19 model_weights,
20 cur_state,
---> 21 rngs)
22
23 if prompt is not None and iteration < prompt.shape[1]:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/api.py in f_jitted(*args, **kwargs)
147 _check_args(args_flat)
148 flat_fun, out_tree = flatten_fun(f, in_tree)
--> 149 out = xla.xla_call(flat_fun, *args_flat, device=device, backend=backend)
150 return tree_unflatten(out_tree(), out)
151
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/core.py in call_bind(primitive, f, *args, **params)
600 if top_trace is None:
601 with new_sublevel():
--> 602 outs = primitive.impl(f, *args, **params)
603 else:
604 tracers = map(top_trace.full_raise, args)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_call_impl(fun, *args, **params)
440 device = params['device']
441 backend = params['backend']
--> 442 compiled_fun = _xla_callable(fun, device, backend, *map(arg_spec, args))
443 try:
444 return compiled_fun(*args)
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in memoized_fun(fun, *args)
221 fun.populate_stores(stores)
222 else:
--> 223 ans = call(fun, *args)
224 cache[key] = (ans, fun.stores)
225 return ans
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/interpreters/xla.py in _xla_callable(fun, device, backend, *arg_specs)
457 pvals = [pe.PartialVal((aval, core.unit)) for aval in abstract_args]
458 with core.new_master(pe.StagingJaxprTrace, True) as master:
--> 459 jaxpr, (pvals, consts, env) = pe.trace_to_subjaxpr(fun, master, False).call_wrapped(pvals)
460 assert not env # no subtraces here
461 del master, env
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/jax/linear_util.py in call_wrapped(self, *args, **kwargs)
150 gen = None
151
--> 152 ans = self.f(*args, **dict(self.params, **kwargs))
153 del args
154 while stack:
~/anaconda3/envs/mindlogic/lib/python3.6/site-packages/trax/layers/base.py in _forward_internal(self, x, weights, state, rng)
460 name, trace = self.__class__.__name__, _short_traceback()
461 raise LayerError(name, '_forward_internal',
--> 462 self._caller, signature(x), trace)
463
464 def _forward_abstract(self, input_signature):
LayerError: Exception passing through layer Serial (in _forward_internal):
layer created in file [...]/models/reformer/reformer.py, line 612
layer input shapes: ShapeDtype{shape:(1, 1, 1), dtype:int32}
File [...]/trax/layers/combinators.py, line 60, in forward_with_state
rngs = _pop_rng_and_split(kwargs, self._n_layers)
File [...]/trax/layers/combinators.py, line 689, in _pop_rng_and_split
return math.random.split(rng, n_copies)
File [...]/trax/math/backend.py, line 123, in split
return backend()['random_split'](prng, num)
File [...]/site-packages/jax/random.py, line 244, in split
return _split(key, num)
File [...]/site-packages/jax/api.py, line 149, in f_jitted
out = xla.xla_call(flat_fun, *args_flat, device=device, backend=backend)
File [...]/site-packages/jax/core.py, line 605, in call_bind
outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
File [...]/jax/interpreters/partial_eval.py, line 126, in process_call
out_flat = call_primitive.bind(fun, *in_consts, **params)
File [...]/site-packages/jax/core.py, line 602, in call_bind
outs = primitive.impl(f, *args, **params)
File [...]/jax/interpreters/xla.py, line 442, in _xla_call_impl
compiled_fun = _xla_callable(fun, device, backend, *map(arg_spec, args))
File [...]/site-packages/jax/linear_util.py, line 223, in memoized_fun
ans = call(fun, *args)
File [...]/jax/interpreters/xla.py, line 459, in _xla_callable
jaxpr, (pvals, consts, env) = pe.trace_to_subjaxpr(fun, master, False).call_wrapped(pvals)
File [...]/site-packages/jax/linear_util.py, line 152, in call_wrapped
ans = self.f(*args, **dict(self.params, **kwargs))
File [...]/site-packages/jax/random.py, line 249, in _split
return lax.reshape(threefry_2x32(key, counts), (num, 2))
File [...]/site-packages/jax/api.py, line 149, in f_jitted
out = xla.xla_call(flat_fun, *args_flat, device=device, backend=backend)
File [...]/site-packages/jax/core.py, line 605, in call_bind
outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
File [...]/jax/interpreters/partial_eval.py, line 126, in process_call
out_flat = call_primitive.bind(fun, *in_consts, **params)
File [...]/site-packages/jax/core.py, line 605, in call_bind
outs = map(full_lower, top_trace.process_call(primitive, f, tracers, params))
File [...]/jax/interpreters/partial_eval.py, line 126, in process_call
out_flat = call_primitive.bind(fun, *in_consts, **params)
File [...]/site-packages/jax/core.py, line 602, in call_bind
outs = primitive.impl(f, *args, **params)
File [...]/jax/interpreters/xla.py, line 442, in _xla_call_impl
compiled_fun = _xla_callable(fun, device, backend, *map(arg_spec, args))
File [...]/site-packages/jax/linear_util.py, line 223, in memoized_fun
ans = call(fun, *args)
File [...]/jax/interpreters/xla.py, line 459, in _xla_callable
jaxpr, (pvals, consts, env) = pe.trace_to_subjaxpr(fun, master, False).call_wrapped(pvals)
File [...]/site-packages/jax/linear_util.py, line 152, in call_wrapped
ans = self.f(*args, **dict(self.params, **kwargs))
File [...]/site-packages/jax/random.py, line 216, in threefry_2x32
key1, key2 = keypair
ValueError: not enough values to unpack (expected 2, got 1)
got the same issue here
Same issue here too!
Environment information
$ pip freeze | grep tensor
mesh-tensorflow==0.1.9
tensor2tensor==1.15.4
tensorboard==2.0.2
tensorflow-datasets==2.0.0
tensorflow-estimator==2.0.1
tensorflow-gan==2.0.0
tensorflow-hub==0.7.0
tensorflow-metadata==0.21.1
tensorflow-probability==0.7.0
$ pip freeze | grep jax
jax==0.1.59
jaxlib==0.1.39
$ python -V
Python 3.7.4
Changes
From
# Prepare a jitted copy of the model.
jit_model_infer = trax.layers.base._accelerate(
model_infer._forward_internal, trax.math.device_count())
# Set up the initial state for sampling.
infer_state = model_infer.new_weights_and_state(
trax.supervised.trainer_lib.ShapeDtype((1,1), dtype=np.int32))[1]
infer_state = trainer._for_n_devices(infer_state)
To
# Prepare a jitted copy of the model.
jit_model_infer = trax.layers.base._accelerate(
model_infer.pure_fn, trax.math.device_count())
# Set up the initial state for sampling.
infer_state = model_infer.new_weights_and_state(
trax.supervised.trainer_lib.ShapeDtype((1,1), dtype=np.int32))[1]
infer_state = trainer._for_n_devices(infer_state)
Changing the below line in the Sample function fixed the issue
From
rngs = trax.math.random.split(trax.math.random.get_prng(0), trax.math.device_count())
To
rngs = trax.math.random.get_prng(0)
Thanks for letting us know! Should be corrected at head now.