torch::NoGradGuard guard; is an RAII guard while torch::autograd::GradMode::set_enabled(false); is not. Consider an example:
auto t = torch::randn({2, 2});

{
  torch::NoGradGuard guard;  // This only takes effect within the scope
  t.add_(1);  // Does not accumulate gradient
}
t.add_(1);  // Accumulates gradient

{
  torch::autograd::GradMode::set_enabled(false);  // This is a global setting
  t.add_(1);  // Does not accumulate gradient
}
t.add_(1);  // Still doesn't accumulate gradient