Is there a way to globally set the default device with libtorch?
I know there exists device guard implemented here:

  
      github.com
  
  
    pytorch/pytorch/blob/8482efb2036475072f26c07e4d7d91e14e5e2c20/c10/core/DeviceGuard.h 2
#pragma once

#include <c10/core/impl/InlineDeviceGuard.h>

namespace c10 {

/// RAII guard that sets a certain default device in its constructor, and
/// changes it back to the device that was originally active upon destruction.
///
/// The device is always reset to the one that was active at the time of
/// construction of the guard. Even if you `set_device` after construction, the
/// destructor will still reset the device to the one that was active at
/// construction time.
///
/// This device guard does NOT have an uninitialized state; it is guaranteed
/// to reset a device on exit.  If you are in a situation where you *might*
/// want to setup a guard (i.e., are looking for the moral equivalent
/// of optional<DeviceGuard>), see OptionalDeviceGuard.
class DeviceGuard {
public:


  This file has been truncated. show original

  
  
    
    
  
  


But it won’t set it globally and it’s harder to program with when the user can dynamically decide to set it or not.
I wonder if there’s something equivalent to  torch::autograd::GradMode::set_enabled(enabled) that we can use to set the grad mode globally.