C2W3 cannot submit assignment - syntax error in grader

C2 (Custom and Distributed Training) Week 3

Cannot submit assignment despite passing all tests and code seems to work well! Always get syntax error from grader. Appreciate any help!

error message:

The notebook you provided has a syntax error that prevents it from compiling.

@cool_chaoz

this syntax error message you got on submission grader right?

can you click on your submission grader with show grader output and take a screenshot!

it will be probably provide information about which section or exercise is having this syntax error.

Also check yourself if your def train grade function cell where for loop and with loop are placed in correct position, chance of syntax error could be coming from anywhere where there is incorrect spacing or use of global variables instead of local variables.

Another common grader mistake is usually with compile parameters related to loss and optimizer class type as it is expect one to use tf.keras.losses where you def the loss function and optimizer should use tf.keras.optimizer.

Regards
DP

Hi @Deepti_Prasad, here is the grader output screenshot

I did not find where the def train grade function is in the notebook. Could you please provide more detailed instructions?

I believe I used the loss functions from tf.keras.losses. Here is a screenshot.

Screenshot removed as it contained grade function codes and posting on public post is violation of code of conduct. if a mentor wants to see your code, will ask you to send by personal DM

Please let me know what are other things I should check besides the train grade function cell. Thanks for your help!

please don’t post any grade function codes on public post thread, it is against community guidelines.

Click on my name and message me screenshot of all the cell you wrote codes.

My apologies. Just sent you the screenshots @Deepti_Prasad
Please let me know how this may be unblocked. Appreciate your help!

cc. @Community-Team
Any suggestions that can help unblock this grader syntax issue would be highly appreciated!

@Community-Team could you please help escalate this to the right person who might be able to unblock this error? It’s delaying my progress in completing the course. It appears that my assignment code works well and passed all tests, but something wrong with the grader.

Issues with your codes,

  1. in the code section
    Apply pre-processing to the datasets (please complete this section

your code for train_dataser is incorrect. the instruction mentions you to shuffle the buffer_size and then batch the dataset, but in your case you skipped the buffer size. Here is a screenshot of instruction given in the assignment to follow (2nd step you have not included)

  1. next in the code section, Define the training loop
    for code lines
Using the tape and loss, compute the gradients on model variables using tape.gradient

Zip the gradients and model variables, and then apply the result on the optimizer

Instructions clearly mentions to compute grads on model variables,i.e. model.trainable_variables but you have calculated on model.trainable_weights

in the same exercise section for code line
Call the train accuracy object on ground truth and predictions

you do not need to use .update_state, just use the train_accuracy to the grouth truth and predictions.

  1. for section
    Define the ‘train’ function

Reset validation metrics before each epoch, this step doesn’t seem to be included in the copy I worked upon and in the GitHub repo of the course assignment. So i don’t know from where you added that step.

for code step, Call the model on the batches of inputs x and get the predictions
You have again used update_state to the val_accuracy which was not required.

Now coming to responding to your threads asap as per our DM conversation, as already I stated we do our personal works and when we get time, we try to respond to threads. In your case the response was delayed because you had issue in your codes and some part of the codes were not sent. you did sent me notebook, but I don’t downloaded external notebooks for my security concern and I was waiting for the screenshot of the code I wanted to review which did have a code error.

Usually looking mistakes in other is lot easier than finding issue in our work, I agree sometimes graders do encounter bug which we do relate to staff but if a mentor is not doing, that meant they have found issue in your codes and demanding to respond to your query asap really don’t go along with every mentor’s personal professional work as mentoring is a volunteer work. Now comes to your progress delay in your course, no course progress gets delayed as usually it is advised to learner to go ahead with next week if they are unable to pass an assignment grader. Learning is a process of patience and diligence and not prompt question-answering.

Hope this resolves your issue.

Regards
DP

@Deepti_Prasad , thanks for your help on the technical side. OK I fixed the three things you pointed out. That’s an oversight on my end. However, again, all the tests passed and the same grader error persists. Do you have further suggestions?

Also as you can see from earlier screenshots, the grader failure was not specific to these three areas of code, but it failed even the first map_fn function in the beginning of the code.

What’s the way to reset the notebook to a fresh start? I’m happy to refill in all the code, or whatever way you can think of that can help unblock this grader error? During the course of completing the notebook I might have experimented different things (my way of learning) and therefore unknowingly changed the notebook.

I need to see how you did the corrections.

get a fresh copy and re do the assignment, making sure only to replace the None placed between the markers ###START AND END CODE HERE###

To get a fresh copy, follow the below steps

Save a copy by renaming the assignment notebook.
Then Click File===Open===Select all files and delete.
Click :question: then click Get Latest Version, then Update lab. You should have a fresh copy.
In case point 3 doesn’t get you fresh copy, then click :question: Reboot. Then repeat the point 3 again. This should surely get you a fresh copy

Re-setting the notebook and starting from fresh worked. Thanks for the instructions on how to do that! @Deepti_Prasad

While doing this I found the reason why the grader failed previously: I had added an extra cell to print out the valid_ds information and forgotten to delete it. This does not affect in anyway how the actual model training process works or solution, yet it fails the grader…

Although we Coursera users are self-learners, we rely on these course contents and automated tools to learn. We’d like to check our work as much as possible, yet we’re not expert users like yourself, and if the step-by-step code tester says my code is returning results as expected then it’s hard for me to debug as a learner. I understand you’re working on a volunteering basis and have limited amount time, yet I would really appreciate if you could help advocate for the course and work with the team to improve things such as: (1) make the grader more tolerable to small things like an extra cell which just prints out something without influencing the solution; and (2) make the grader message more informative to pinpoint to the specific function that might have a potential issue instead of returning a “syntax error” message on all the functions written in the code.

Thanks for your help!

Tip: Never modify the setup of any of the course notebooks.

You can make a copy and modify things there all you like. But the grader does not handle the unexpected very well.

1 Like

happy to know your issue is resolved, I understand and appreciate that we as a coder we all want to resolve or debug our code errors. I am not defending anyone by stating this but the unittest have codes to only check codes you might written for the grade function you had written codes, and I suppose autograder comes with their own limitation when it comes to allowing you to pass the unittest yet failing at grader.

Me as a learner I used to always get upset because I had put so much effort and felt shocking to see the grader failed again and again. But over a period of time, I have understood the reason grader or unittest are design to make me or learner better at coding. to understand the global and local variables difference autograder helps. Now in your case the syntax error was generally thrown because you had error at multiple grade function cells, be it missing the syntax function to create the train_dataset or you adding extra code line which is general strict no for a successful submission that is understood by any beginner learner course and tf3 is an advanced course not fr learner who just know basic python coding.

This course was the most challenging one when I did as a learner but has taught me the most on working on my coding skills be it missing a colony, missing a space in loop or not saving my work after working for hours ending up failing submission. With each setback in an assignment I have only improved and I understand now unittest are limited to check the codes we write till a limited area of codes as their secondary file compilation which may or may not dependent while running the test but will be checked when the autograder would check the whole notebook each step from beginning till ending. So I can only tell as @TMosh also mentioned only write code where it is required. believe me course3 and course 4 of this specialisation assignment still fails even if our codes are correct, not because there is a issue in our coding, but there are other modules which are deprecated which is not in hands of deeplearning.ai or Coursera. But the staff works upon to update the issue as in when it happens, and we as volunteer mentor when notice the learners code is perfect we try to raise the issue.

So keep learning, coding taught me patience and self-reflection.

Best of luck!