code: def build_loss(config):
      """Builds a ClassyLoss from a config.
  
      This assumes a 'name' key in the config which is used to determine what
      model class to instantiate. For instance, a config `{"name": "my_loss",
      "foo": "bar"}` will find a class that was registered as "my_loss"
      (see :func:`register_loss`) and call .from_config on it.
  
      In addition to losses registered with :func:`register_loss`, we also
      support instantiating losses available in the `torch.nn.modules.loss <https:
      //pytorch.org/docs/stable/nn.html#loss-functions>`_
      module. Any keys in the config will get expanded to parameters of the loss
      constructor. For instance, the following call will instantiate a
      `torch.nn.modules.CrossEntropyLoss <https://pytorch.org/docs/stable/
      nn.html#torch.nn.CrossEntropyLoss>`_:
  
      .. code-block:: python
  
       build_loss({"name": "CrossEntropyLoss", "reduction": "sum"})
      """
  
      assert "name" in config, f"name not provided for loss: {config}"
      name = config["name"]
      args = copy.deepcopy(config)
      del args["name"]
      if "weight" in args and args["weight"] is not None:
          # if we are passing weights, we need to change the weights from a list
          # to a tensor
          args["weight"] = torch.tensor(
              args["weight"], dtype=torch.float
          )
      if name in LOSS_REGISTRY:
          loss = LOSS_REGISTRY[name].from_config(config)
      else:
          # the name should be available in torch.nn.modules.loss
          assert hasattr(torch_losses, name), (
              f"{name} isn't a registered loss"
              ", nor is it available in torch.nn.modules.loss"
          )
          loss = getattr(torch_losses, name)(**args)
      log_class_usage("Loss", loss.__class__)
      return loss
  
file_path: ClassyVision/classy_vision/losses/__init__.py
imports: import copy
  import traceback
  from pathlib import Path
  import torch
  import torch.nn.modules.loss
  from classy_vision.generic.registry_utils import import_all_modules
  from classy_vision.generic.util import log_class_usage
  from .classy_loss import ClassyLoss
  from .barron_loss import BarronLoss
  from .label_smoothing_loss import LabelSmoothingCrossEntropyLoss
  from .multi_output_sum_loss import MultiOutputSumLoss
  from .soft_target_cross_entropy_loss import SoftTargetCrossEntropyLoss
  from .sum_arbitrary_loss import SumArbitraryLoss
label_desc: Use image node_id 1 for calling a global function with example usage: build_loss(config) and returns: loss