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

**URL:** <https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692>\
**Category:** Custom and Distributed Training with TF\
**Tags:** week-module-1\
**Created:** [June 3, 2023, 4:50pm UTC](https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692 "2023-06-03T16:50:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Basharat\_Saigal](https://avatars.discourse-cdn.com/v4/letter/b/bbe5ce/32.png) [@Basharat\_Saigal](https://community.deeplearning.ai/u/Basharat_Saigal)\
**Post date:** [June 3, 2023, 4:50pm UTC](https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692/1 "2023-06-03T16:50:21Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [June 5, 2023, 7:29am UTC](https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692/2 "2023-06-05T07:29:50Z")

</div>

Which assignment is this?

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [July 24, 2023, 4:27am UTC](https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692/3 "2023-07-24T04:27:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arif\_Hassan](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/arif_hassan/32/139942_2.png) [@Arif\_Hassan](https://community.deeplearning.ai/u/Arif_Hassan)\
**Post date:** [August 4, 2023, 3:12pm UTC](https://community.deeplearning.ai/t/question-regarding-which-statements-to-enclose-in-the-with-block-and-why/349692/4 "2023-08-04T15:12:26Z")

</div>

Hi @Basharat_Saigal,  
I am not clear with your question but you can follow this link on [gradient tape](https://www.tensorflow.org/api_docs/python/tf/GradientTape). It might help you.

Regards  
Arif
