[fix] update the condition for aliveness of TensorWrapper (#98748)
Fixes https://github.com/pytorch/pytorch/issues/95561
Fixes https://github.com/pytorch/pytorch/issues/98021
Pull Request resolved: https://github.com/pytorch/pytorch/pull/98748
Approved by: https://github.com/zou3519