Question regarding which statements to enclose in the with block and why

I have a doubt on the statements which are to be entered in the with block of gradient tape and those outside of it, the given example was simple one but for complicated cases?

Which assignment is this?

Hello Bashrat_Saigal,

Just a suggestion, whenever in doubt about a particular section of course, please mention the following for better response from others

  1. Select/mention the proper main course specialisation name, example TensorFlow-Advanced Technique.
  2. Select/mention the proper subset course for the specialisation you are doing, example Custom and Distributed Training with TF
  3. Select/mention the proper week under the subset course you are currently doing or have a question/doubt to be asked. Example Course 1 of week 1 or 2
  4. Select/mention the assignment name you have a doubt/question you want others to answer or clarify, example assignment Generative Hands with GAN assignment(which is a part of Course 4 week 4 assignment)
  5. Lastly, select/mention the question as simple as possible with screenshot of the question or doubt without mentioning any of your codes as it is against the community guidelines. Extra tip (for me adding a screenshot of the error(without my written code) of an issue always helped to get a prompt response from the mentors/leaders).
  6. If you are aware of any mentor/leader name you are looking for them to answer your doubt/question, mention there name with @(Mentor_name). Example @Deepti_Prasad

Hope it helps!!!

Regards
DP

Hi @Basharat_Saigal,
I am not clear with your question but you can follow this link on gradient tape. It might help you.

Regards
Arif