code: def set_requires_grad(requires_grad, *models):
      """
      Sets requires_grad true or false for all parameters within the
      models passed.
      """
      for model in models:
          if isinstance(model, torch.nn.Module):
              for param in model.parameters():
                  param.requires_grad = requires_grad
          elif isinstance(model, (torch.nn.Parameter, torch.Tensor)):
              model.requires_grad = requires_grad
          else:
              assert False, "unknown type %r" % type(model)
  
imports: import contextlib
  import copy
  import inspect
  from collections import OrderedDict
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: set_requires_grad(requires_grad) without return types