code: def environ_config(kwargs):
      if "spmd_nodes" not in kwargs:
          kwargs["spmd_nodes"] = kwargs["total_nodes"]
      if "device_type" not in kwargs:
          kwargs["device_type"] = os.environ.get("DEVICE", "cuda")
      if "run_mode" not in kwargs:
          kwargs["run_mode"] = os.environ.get("MODE", "train")
      assert (
          kwargs["total_nodes"] % kwargs["spmd_nodes"] == 0
      ), "`total_nodes` must be exactly divided by `spmd_nodes`."
      return kwargs
  
imports: import os, sys, json, re
  import tempfile
  import copy
  import inspect
  import logging
  import importlib
  from .None import solver
  from .None import patterns
label_desc: Use image node_id 4 for calling a global function with example usage: environ_config(kwargs) and returns: kwargs