Course 3 week 1 exercise 6

I get the following error and i cant figure out the reason. Can you help.

---------------------------------------------------------------------------
LayerError                                Traceback (most recent call last)
<ipython-input-80-9216004d763d> in <module>
      2 # Take a look on how the eval_task is inside square brackets and
      3 # take that into account for you train_model implementation
----> 4 training_loop = train_model(model, train_task, [eval_task], 100, output_dir_expand)

<ipython-input-79-f5a1eb0b2c7f> in train_model(classifier, train_task, eval_task, n_steps, output_dir)
     20                                 eval_tasks=eval_task[0], # The evaluation task
     21                                 output_dir=output_dir, # The output directory
---> 22                                 random_seed=31 # Do not modify this random seed in order to ensure reproducibility and for grading purposes.
     23     ) 
     24 

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in __init__(self, model, tasks, eval_model, eval_tasks, output_dir, checkpoint_at, checkpoint_low_metric, checkpoint_high_metric, permanent_checkpoint_at, eval_at, which_task, n_devices, random_seed, loss_chunk_size, use_memory_efficient_trainer, adasum, callbacks)
    278 
    279     # Create the optimizer for the training loss function.
--> 280     self._trainer_per_task = tuple(self._init_trainer(task) for task in tasks)
    281 
    282     # Sync layers weights/state in memory effcient trainer layers.

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in <genexpr>(.0)
    278 
    279     # Create the optimizer for the training loss function.
--> 280     self._trainer_per_task = tuple(self._init_trainer(task) for task in tasks)
    281 
    282     # Sync layers weights/state in memory effcient trainer layers.

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in _init_trainer(self, task)
    339           self._model,
    340           [task.loss_layer],
--> 341           shapes.signature(task.sample_batch)
    342       )
    343       if base.N_WEIGHTS_SHARDS > 1:

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in _model_with_ends(model, end_layers, batch_signature)
   1028   # TODO(jonni): Redo this function as part of an initialization refactor?
   1029   metrics_layer = tl.Branch(*end_layers)
-> 1030   metrics_input_signature = model.output_signature(batch_signature)
   1031   _, _ = metrics_layer.init(metrics_input_signature)
   1032 

/opt/conda/lib/python3.7/site-packages/trax/layers/base.py in output_signature(self, input_signature)
    608   def output_signature(self, input_signature):
    609     """Returns output signature this layer would give for `input_signature`."""
--> 610     return self._forward_abstract(input_signature)[0]  # output only, not state
    611 
    612   def _forward_abstract(self, input_signature):

/opt/conda/lib/python3.7/site-packages/trax/layers/base.py in _forward_abstract(self, input_signature)
    640       name, trace = self._name, _short_traceback(skip=7)
    641       raise LayerError(name, '_forward_abstract', self._caller, input_signature,
--> 642                        trace) from None
    643 
    644   # pylint: disable=protected-access

LayerError: Exception passing through layer Serial (in _forward_abstract):
  layer created in file [...]/<ipython-input-34-1421af8c6f34>, line 30
  layer input shapes: (ShapeDtype{shape:(16, 15), dtype:int32}, ShapeDtype{shape:(16,), dtype:int32}, ShapeDtype{shape:(16,), dtype:float32})

  File [...]/jax/interpreters/partial_eval.py, line 411, in abstract_eval_fun
    lu.wrap_init(fun, params), avals, debug_info)

  File [...]/jax/interpreters/partial_eval.py, line 1252, in trace_to_jaxpr_dynamic
    jaxpr, out_avals, consts = trace_to_subjaxpr_dynamic(fun, main, in_avals)

  File [...]/jax/interpreters/partial_eval.py, line 1262, in trace_to_subjaxpr_dynamic
    ans = fun.call_wrapped(*in_tracers)

  File [...]/site-packages/jax/linear_util.py, line 166, in call_wrapped
    ans = self.f(*args, **dict(self.params, **kwargs))

  File [...]/site-packages/jax/linear_util.py, line 166, in call_wrapped
    ans = self.f(*args, **dict(self.params, **kwargs))

LayerError: Exception passing through layer Serial (in pure_fn):
  layer created in file [...]/<ipython-input-34-1421af8c6f34>, line 30
  layer input shapes: (ShapeDtype{shape:(16, 15), dtype:int32}, ShapeDtype{shape:(16,), dtype:int32}, ShapeDtype{shape:(16,), dtype:float32})

  File [...]/trax/layers/combinators.py, line 88, in forward
    outputs, s = layer.pure_fn(inputs, w, s, rng, use_cache=True)

LayerError: Exception passing through layer Mean (in pure_fn):
  layer created in file [...]/<ipython-input-34-1421af8c6f34>, line 15
  layer input shapes: ShapeDtype{shape:(16, 15, 256), dtype:float32}

  File [...]/trax/layers/base.py, line 743, in forward
    raw_output = self._forward_fn(inputs)

  File [...]/trax/layers/base.py, line 784, in _forward
    return f(*xs)

  File [...]/trax/layers/core.py, line 704, in <lambda>
    return Fn('Mean', lambda x: jnp.mean(x, axis=axis, keepdims=keepdims))

  File [...]/_src/numpy/lax_numpy.py, line 2154, in mean
    normalizer = _axis_size(a, axis)

  File [...]/_src/numpy/lax_numpy.py, line 2139, in _axis_size
    size *= maybe_named_axis(a, lambda i: a_shape[i], lambda name: lax.psum(1, name))

  File [...]/jax/_src/util.py, line 391, in maybe_named_axis
    return if_named(axis) if named else if_pos(pos)

  File [...]/_src/numpy/lax_numpy.py, line 2139, in <lambda>
    size *= maybe_named_axis(a, lambda i: a_shape[i], lambda name: lax.psum(1, name))

  File [...]/_src/lax/parallel.py, line 86, in psum
    axis_index_groups=axis_index_groups)

  File [...]/_src/lax/parallel.py, line 723, in psum_bind
    size = prod([core.axis_frame(name).size for name in named_axes])  # type: ignore

  File [...]/_src/lax/parallel.py, line 723, in <listcomp>
    size = prod([core.axis_frame(name).size for name in named_axes])  # type: ignore

  File [...]/site-packages/jax/core.py, line 1681, in axis_frame
    f'unbound axis name: {axis_name}. The following axis names (e.g. defined '

NameError: unbound axis name: Embedding_9088_256. The following axis names (e.g. defined by pmap) are available to collective operations: []

Can someone @Mubsi please help with this?

Thanks
Raja

Hi @rajatheshankar,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.

I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.

Thanks,
Mubsi

@Mubsi

I am also having same problem. My lab Id is btwmxihi. Can you have a look at it.

@Mubsi @rajatheshankar ,

For me, have to ensure that the mean_layer in UNQ_C5 (def classifier) is the mean of columns.

Hope this helps you.

ThanQ…

6 Likes

@Shantimohan_Elchuri : This is really helpful, thank you so much ~

This also saved my day. Thank you so much too!!!

@Mubsi I am also having problems with this exercise. My errors are slightly different. My lab id is tqxhipjp

LayerError                                Traceback (most recent call last)
<ipython-input-46-9216004d763d> in <module>
      2 # Take a look on how the eval_task is inside square brackets and
      3 # take that into account for you train_model implementation
----> 4 training_loop = train_model(model, train_task, [eval_task], 100, output_dir_expand)

<ipython-input-45-21efd7179a9e> in train_model(classifier, train_task, eval_task, n_steps, output_dir)
     22                                 eval_tasks= eval_task, # The evaluation task
     23                                 output_dir=output_dir, # The output directory
---> 24                                 random_seed=31 # Do not modify this random seed in order to ensure reproducibility and for grading purposes.
     25     ) 
     26 

/opt/conda/lib/python3.7/site-packages/trax/supervised/training.py in __init__(self, model, tasks, eval_model, eval_tasks, output_dir, checkpoint_at, checkpoint_low_metric, checkpoint_high_metric, permanent_checkpoint_at, eval_at, which_task, n_devices, random_seed, loss_chunk_size, use_memory_efficient_trainer, adasum, callbacks)
    246     if not use_memory_efficient_trainer:
    247       if _is_uninitialized(self._model):
--> 248         self._model.init(self._batch_signature)
    249       self._eval_model.rng = self.new_rng()
    250       if _is_uninitialized(self._eval_model):

/opt/conda/lib/python3.7/site-packages/trax/layers/base.py in init(self, input_signature, rng, use_cache)
    309       name, trace = self._name, _short_traceback(skip=3)
    310       raise LayerError(name, 'init', self._caller,
--> 311                        input_signature, trace) from None
    312 
    313   def init_from_file(self, file_name, weights_only=False, input_signature=None):

LayerError: Exception passing through layer Serial (in init):
  layer created in file [...]/<ipython-input-34-73a123e03b81>, line 30
  layer input shapes: (ShapeDtype{shape:(16, 15), dtype:float32}, ShapeDtype{shape:(16,), dtype:float32}, ShapeDtype{shape:(16,), dtype:float32})

  File [...]/trax/layers/combinators.py, line 106, in init_weights_and_state
    outputs, _ = sublayer._forward_abstract(inputs)

LayerError: Exception passing through layer Embedding_9088_256 (in _forward_abstract):
  layer created in file [...]/<ipython-input-34-73a123e03b81>, line 11
  layer input shapes: ShapeDtype{shape:(16, 15), dtype:float32}

  File [...]/jax/interpreters/partial_eval.py, line 411, in abstract_eval_fun
    lu.wrap_init(fun, params), avals, debug_info)

  File [...]/jax/interpreters/partial_eval.py, line 1252, in trace_to_jaxpr_dynamic
    jaxpr, out_avals, consts = trace_to_subjaxpr_dynamic(fun, main, in_avals)

  File [...]/jax/interpreters/partial_eval.py, line 1262, in trace_to_subjaxpr_dynamic
    ans = fun.call_wrapped(*in_tracers)

  File [...]/site-packages/jax/linear_util.py, line 166, in call_wrapped
    ans = self.f(*args, **dict(self.params, **kwargs))

  File [...]/site-packages/jax/linear_util.py, line 166, in call_wrapped
    ans = self.f(*args, **dict(self.params, **kwargs))

LayerError: Exception passing through layer Embedding_9088_256 (in pure_fn):
  layer created in file [...]/<ipython-input-34-73a123e03b81>, line 11
  layer input shapes: ShapeDtype{shape:(16, 15), dtype:float32}

  File [...]/trax/layers/assert_shape.py, line 122, in forward_wrapper
    y = forward(self, x, *args, **kwargs)

  File [...]/trax/layers/core.py, line 182, in forward
    embedded = jnp.take(self.weights, x, axis=0, mode='clip')

  File [...]/_src/numpy/lax_numpy.py, line 4736, in take
    slice_sizes=tuple(slice_sizes))

  File [...]/_src/lax/lax.py, line 988, in gather
    indices_are_sorted=bool(indices_are_sorted))

  File [...]/site-packages/jax/core.py, line 264, in bind
    out = top_trace.process_primitive(self, tracers, params)

  File [...]/jax/interpreters/partial_eval.py, line 1059, in process_primitive
    out_avals = primitive.abstract_eval(*avals, **params)

  File [...]/_src/lax/lax.py, line 2125, in standard_abstract_eval
    return ShapedArray(shape_rule(*avals, **kwargs), dtype_rule(*avals, **kwargs),

  File [...]/_src/lax/lax.py, line 4354, in _gather_dtype_rule
    raise ValueError("start_indices must have an integer type")

ValueError: start_indices must have an integer type

Hi @drew_Frances,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.
I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.

Thanks, Mubsi

Hi @Mubsi:

My lab id is tqxhipjp
In other exercises, I am not able to get all the unit tests to pass.

Thanks!
Drew

Am I reading this correctly, that you are asking for help debugging exercise 6, which relies on components built earlier in the notebook, but your implementations of those components didn’t pass their unit tests? Maybe I read this wrong.

Exercise 2 gets 10 tests correct, 1 wrong. Exercise 4 gets 8 tests correct, wrong. I am stumped on getting those to totally pass. Hence a request for someone to look at the lab.Maybe getting those exercises to successfully pass may get rid of the error in exercise 6.

Thanks,
Drew

Hi @drew_Frances,

I believe you made a copy/paste error. In Ex 2 where it says:

# get the tweet as neg_index
            tweet =

you are using positive set of tweets to do the calculations.

Even if you change the it to negative set of tweets, unfortunately you pass the tests (I’ll have this sorted out), this is your output:

You are getting float values, when you should be getting int.

This is because, your variables are pad_l, target_pos, target_neg and example_weights are incorrect. For the first 4 variables, you are using the .tolist() function, which you shouldn’t. For example_weights, you are not using the right numpy function.

In Ex 4, you have introduced a new variable called tmp_key. As per instructions given on the top of the assignment, under Important Note on Submission to the AutoGrader, it has been clearly mentioned to not do that as introducing more variables causes problem.

In the same exercise, your dense in incorrect. It is a very simple implementation of dot product between the parameter x and the weights of the class.

Your Ex 6 is correct. When you’ll fix your issues in these two exercises, you’ll see your Ex 6 will run as expected.

Hope this helps,
Mubsi

Hi @Mubsi:

Thanks for pointing out the problems. I am making the corrections. I used tolist() because the comment explicitly mentioned a list.

reading the instructions “and the weight for each target (ex: this allows us to can treat some examples as more important to get right than others, but commonly this will all be 1.0” I used:

example_weights = np.ones(batch_size)

what is wrong with this?

Hi @Mubsi:

I see my mistakes and made most of the corrections. Again, thanks! Most of my tests pass but one:

Step 1: Total number of trainable weights: 2327042
Step 1: Ran 1 train steps in 1.49 secs
Step 1: train CrossEntropyLoss | 0.70368373
Step 1: eval CrossEntropyLoss | 0.69825441
Step 1: eval Accuracy | 0.56250000

Step 10: Ran 9 train steps in 5.91 secs
Step 10: train CrossEntropyLoss | 0.65071505
Step 10: eval CrossEntropyLoss | 0.68158495
Step 10: eval Accuracy | 0.50000000
Wrong loss function. WeightedCategoryCrossEntropy_in3 was expected. Got CrossEntropyLoss_in3.
Wrong metrics in evaluations task. Expected [‘WeightedCategoryCrossEntropy’, ‘WeightedCategoryAccuracy’]. Got [‘CrossEntropyLoss’, ‘Accuracy’].
4 Tests passed
2 Tests failed

Blockquote

Your Ex 6 is correct. When you’ll fix your issues in these two exercises, you’ll see your Ex 6 will run as expected.

Hi @Mubsi

I believe I’ve made all the corrections. I have looked over the code. I’m still stuck.

Thanks,
Drew

Hi @drew_Frances,

My apologise for replying late, I’m stuck with some other work.

I shall look at all of this later today.

Thanks,
Mubsi

I apprecate the help!

Cheers,
Drew

Hi @drew_Frances,

Yes, let me take a look.

Can you share your lab ID again, and in which exercise are you having an issue ?

Thanks,
Mubsi

Hi @Mubsi

My exercise 4 gets 4/2. I’ll assume this is making my exercise 8 fail. My id is tqxhipjp

Thanks,
Drew