Torch rng threadsafety

Fix monkey patching of torch rng functions when generator is explicitly used.