Hi,
I noticed a small thing while looking through the training code and wanted to ask for your opinion. There are a few places where multiple context managers seem to be combined with and, for example:
with torch.cuda.amp.autocast() and torch.no_grad():
My understanding is that Python does not treat this as entering both context managers. Instead, it evaluates A() and B() first, so the with statement only receives one context manager, usually the second one if the first object is "true". So this may effectively behave like:
rather than:
with torch.cuda.amp.autocast(), torch.no_grad():
It does not seem like a huge issue, but it may mean that autocast() is not actually active in those blocks. In the opposite order, for example:
with torch.no_grad() and torch.cuda.amp.autocast():
it may mean that no_grad() is not active.
I may be missing something, so I wanted to check with you: do you think replacing these with comma-separated context managers would be the intended behavior?
Thanks!
Hi,
I noticed a small thing while looking through the training code and wanted to ask for your opinion. There are a few places where multiple context managers seem to be combined with and, for example:
My understanding is that Python does not treat this as entering both context managers. Instead, it evaluates A() and B() first, so the with statement only receives one context manager, usually the second one if the first object is "true". So this may effectively behave like:
rather than:
It does not seem like a huge issue, but it may mean that autocast() is not actually active in those blocks. In the opposite order, for example:
it may mean that no_grad() is not active.
I may be missing something, so I wanted to check with you: do you think replacing these with comma-separated context managers would be the intended behavior?
Thanks!