Hi,
This sounds like a completely valid use case for empty_cache() !
For the env variable, you can set it temporarily for a single command by doing:
CUDA_VISIBLE_DEVICES=2 python your_command.py
This way, only this python command will have the env variable defined.