Solved by wanchaol in post #2 
              
              
                Hi thanks for posting the question. We do have a method do know if it’s in tracing state or not using torch._C._get_tracing_state(), it will return true if you are in tracing otherwise false. But note that this is a internal API and it might break in the future (also unlikely).