C5 W4 A1: Can't compile student's code (old thread, please don't add new replies)


I’m doing the final assignment of course 5 week 4 and getting recurring errors, despite the fact that it says “All assignments passed” when I submit. I know that this is possible in certain cases. But for me, it seems to be happening in ALL cases (I complete a function, get “All assignments passed”, submit and then get a different reason for “can’t compile student’s code”) In the picture, you can see a history of some of the errors. The most recent one happened after my attempt to get rid of it by refreshing the workspace - first I tried refreshing, and copy-pasting some code from my old functions and it gave me “can’t compile student’s code”. After that, I refreshed the workspace again and submitted an unmodified version of the lab. Still “can’t compile student’s code”.

Long story short: I seem to get this error no matter which functions I complete before submitting, or even if I don’t modify the original code at all.

What should I try? I think I’m going to be charged again for this soon.


Hi BennyG,

You have posted your question in the General Discussions section of the discourse. General discussion is not meant for course related questions, refer: the description.

Can you post this question to the course 5 week 4 section of the relevant course so that it has the correct visibility to the course’s mentors and it get’s addressed promptly. (If there’s no week 4 subsection then post it under course 5)

E.g. if this query was for GANs specialization, then post it in the relevant section, like:


Did you rename your Notebook file? That can cause this sort of problem with submitting your work.
The grader always uses the default notebook file name. You can’t really use a renamed notebook.

I followed the instructions outlined below to refresh the workspace. After refreshing the workspace, I had two files: a backup version of my old work and the clean version (freshly downloaded notebook). Then I copy-pasted functions from the backup version into the clean version. I’ve tried this twice, just to make sure. Nothing has changed.

H​ow to Refresh your Workspace

T​his reading item has instructions on how to refresh your workspace. This will come in handy whenever you’d need to fetch the (latest) assignment and/or other files. And in cases of opening the assignment runs into a 404 error .

H​ow to Refresh your Workspace:

O​ption 1 - Using Lab Help

  1. O​pen the assignment.
  2. After the assignment opens up, c​lick " File" (top left) and then " Open…"
  3. W​hen your workspace opens, select the check box before your assignment file. After it is selected, press " Shutdown" .
  4. U​sing the same procedure mentioned above, " Rename" your file. For instance you can change it from assignment_name.ipynb to assignment_name_v2.ipynb . By doing this you’ll be able to save your current progress on the assignment after the latest assignment file is fetched.
  5. Using the same procedure, " Delete" any other file, if any, that you want to get a fresh copy of.
  6. After renaming your file, click on the " Help" button on the top right of the page. From the panel that opens, click " Get latest version" button, and then " Update lab" .
  7. A​fter the page reloads go to File → Open… , as described in (2)
  8. Now you’ll see two notebook files. The one you renamed (as done in step 4) will have your previous progress, and the latest version. (Depending on how many previous versions you have kept saved, you could have more than two assignment files in the worksapce)

Well, it seems like this is pretty convincing evidence that there is something wrong with your code. It sounds like you are perhaps using the “Validate” button to check your functions. I recommend doing the following:

  1. Kernel → Restart and Clear Output
  2. Cell → Run All
  3. Now carefully scroll through the notebook and check the output of all cells, not just the graded ones. Do you see any errors getting thrown by any of the cells?

At the risk of stating the obvious, it’s key to realize that the grader environment is different than the notebook environment. We don’t really know what it is and have no direct way to run experiments: we can only submit and then try to read the tea leaves. We have seen other cases in which things work in the notebook, but fail in grader (e.g. adding a space before the “def” statement for a graded function). Of course the obvious way in which the grader is different is that it probably uses different test inputs. One common syndrome is that things work in the notebook, but you’ve somehow hard-coded something to match the dimensions of the particular input data in the notebook and then things explode and catch fire when the grader uses a test case with different dimensions. Your case seems to be triggering a very specific error from the grader about not returning a numpy array where one is expected.

One other question: are you sure that you didn’t modify any of the accompanying python source files that are in the same folder as the assignment? If so, you can also get fresh copies of them by deleting them and then doing the “Get Fresh Copy” procedure. You don’t need to rename your notebook in that case: the “fresh copy” procedure only replaces missing files and it sounds like you’ve already done the fresh copy procedure enough times on the notebook itself to know that replacing it again won’t help.

Hi BennyG,

This can be caused by the addition of a cell to the notebook that is not expected by the grader. To check whether that is the case, you can have a look if you did not forget to delete cells you added to the notebook.


It seems like pretty convincing evidence that there ISN’T a problem with the code, surely? I get the same errors whether I submit the completely refreshed (original and unmodified) version. (“Cell #3. Can’t compile the student’s code. Error: AssertionError(‘You must return a numpy ndarray’)”).

As for finding errors with hard-coding: I can’t say for sure that I haven’t done something like this. But I have tried submitting just one function at a time to make sure it’s not a problem with my code. No success. And when I submit all functions, I get zero as a score. In the past I would get, say, 25/100 instead of 0/100, because some of the functions are working.

I tried your steps 1-3 above. No errors found.

As for modifying accompanying python files: since I have no idea how to do that, it would have to have been done by accident, which seems highly unlikely since all I really do with these assignments is modify code, press ctrl+enter, and press “Submit”.


But I have no idea how to add cells to a notebook so this is also unlikely. Furthermore, I have refreshed the file to its original version so I don’t see how this could be possible.

Hi BennyG,

Could you send me your notebook by means of a private message? Then I can have a look if I can get it to pass from here or if there might be something else going on.

It turns out this type of error can be caused by submitting the notebook when not all required exercises are implemented. This results in the grader reporting a cell which relies upon an implemented exercise with an indication that it can’t compile the student’s code.

Thanks to reinoudbosch for pointing out the problem. I just hadn’t completed all of the exercises. In previous exercises, I have submitted partial solutions and been graded on the parts that were submitted, so the thought that this might be the problem never really crossed my mind! Appreciated.

Hi @reinoudbosch , I have got the same type of error for the Course 5 Week 4 “C5_W4_A1_Transformer_Subclass_v1-Copy1” assignment. I have finished all the exercises for this assignment and all functions passed the units test in the notebook. The notebook shows “All tests passed” for all of the graded functions. However, when I submit the assignment, the grade is zero with the output as “Cell #16. Can’t compile the student’s code. Error: AssertionError(‘Wrong values when training=True’)”. I don’t think I have added any new cells to the notebook. I didn’t change the notebook name as well. Restart the notebook and resubmit didn’t solve the problem. Could someone help with this assignment please! Thanks!

Hi alexj,

This looks like there is a problem with your code that is not captured by the unit tests. Could you send me your notebook with a private message so I can have a look?

1 Like

Can you help me, if I share my code?
Send your email

Discourse has a “direct message” feature. Just click on anyone’s name or avatar and then use the “Message” button to communicate privately.

Hi @paulinpaloalto This is my code and I have updated based on these comments but I am also getting errors for the UNQ_C3 even thou all tests passed, could you let me know where I am going wrong?

Hi, Kailash.

I’m sorry, but I have not actually gotten to this exercise in Course 5 yet, so I am not able to help with the code. My previous comments on this thread were just general things about how the grader works. One of the Course 5 mentors would be better able to help you here.

Your code for applying the mask to the scaled_attention_logits is not correct.
Please read the instructions carefully, you’ve left something out.