All tests passed in browser (Jupyter), but not local

Hi guys,

So, in the hw “Optimization_methods” of " Exercise 4 - update_parameters_with_momentum". There are 4 lines of code I need to do, my solutions are below, and next block shows me “All tests passed.”. But when I copied the same code to my desktop with pycharm, it says "2 tests passed, 1 tests failed. "

my code:

        v["dW" + str(l)] =  beta*v["dW" + str(l)] + (1-beta)*grads['dW' + str(l)]
        v["db" + str(l)] =  beta*v["db" + str(l)] + (1-beta)*grads['db' + str(l)]
      
        parameters["W" + str(l)] = parameters["W" + str(l)] - learning_rate * v["dW" + str(l)]
        parameters["b" + str(l)] = parameters["b" + str(l)] - learning_rate * v["db" + str(l)]

Question, the code above is truly correct or wrong ? If no, could you give me some hint? thank you

1 Like

There must be something different about your environment. Note that the course was last updated in April of 2021, so the versions of all the python packages that it uses are out of date. It’s possible that the definition of some API changed. You’ll have to debug it, if you want to know the cause. The first step would be to examine the test case code and understand in more detail what the failure message is telling you. Then work from there …

@paulinpaloalto thanks, Paul, you are here again. May I ask you, could you confirm my 4 lines code are correct or not ? If yes, I will just leave it to my local code, and I will have the confidence to continue to the rest of the exercises, Thank you!!!

Btw, the output of hw is below, could you check it as well? Do I get correct values ?

Hey @sunson29,
Your code seems to be passing the test cases. Can you please describe as to what you want us to check here?

Cheers,
Elemento

@Elemento ,
if you check my 1st post here, you will see, my local code says 1 test failed. but here in the browser jupter, it says all passed. So, I am not sure which one is truly correct…

could you double-check my 4 lines of the code?

1 Like

Yes @sunson29,
Your code is correct. As Paul Sir pointed it out, your system will most probably be running the latest versions of the packages, and in that, some change might have happened, resulting in failure of one of the test cases. Can you share the error that you are getting in your local system, like the test case that is failing in your local system.

Cheers,
Elemento

I have a question here, when you say “latest versions of the packages”. how and where do I update or check those packages? Sorry, I am not a CS guy, I know this question is very low level. lol Btw, Paul says the package here is out of date, but my local is too new. thank you

Hey @sunson29,
I assume the error statements in your screenshot are your personal print statements? If so, can you please remove them. Also, can you please confirm if the values that you are obtaining in your local machine for the different variables are same as the ones that you receive in Coursera labs (like manually checking), and let us know which of the variables is not matching.

For dealing with the packages, you can check out the docs here. As to not being a CS guy, no worries at all. I myself am not a CS guy, my major is in Electronics and Communication. I hope this helps.

Cheers,
Elemento

So, I copied the same code from here (which all tests pass) to my local (which has 2 pass 1 failed). When you said, manually checking the values, are you referring to the w, b and v values that I showed in the pic of 3rd reply to this thread? If yes, they are the same. My local values and values from here (browsers or jupter) are the same.

I checked the docs, packages like np, got it. thank you!

The point is that the API that may have changed might be something that the grader routines or the test case logic depend on, not something to do with the actual values you are generating.

There are no official instructions for how to duplicate all the versions. It’s pretty complicated, but here is a thread that will point you down one path for doing this. If you are going to do things locally, you need to grow your own skills for dealing with this kind of thing. Please realize that the mentors here are volunteers: we do not get paid to do this. So it’s not reasonable to expect us to be your own personal IT support staff for whatever you want to do outside the scope of these courses. It’s fine to ask questions like this and maybe you’ll find other community members who like to help with this kind of thing (like the person who created that thread I linked above), but please realize that this is a “community service” model and not a kind of support that you can demand or expect from the mentors.

Hey @sunson29,

In that case, as Paul Sir pointed it out, the API is changed, and you will have to check which all the functions have been used in the test cases, and how they have changed over the versions. I hope this helps.

Cheers,
Elemento

thank you, my friend.

thanks for the help!

@sunson29 If you want to debug this, you can find the source for the test cases and the utility functions they use in the file public_tests.py. Have a look and go from there if you want to understand in more detail what is happening.

you guys are very kind. thank you. I will check by myself.