code: def write_user_code(path: pathlib.Path, on_cluster: bool) -> None:
      code_path = path.joinpath("code")
  
      # When restarting from checkpoint, it is possible that the code path is already present
      # in the checkpoint directory. This happens for EstimatorTrial because we overwrite the
      # estimator model directory with the checkpoint folder at the start of training.
      if code_path.exists():
          rmtree_nfs_safe(str(code_path))
  
      # Most models can only be restored from a checkpoint if the original code is present. However,
      # since it is rather common that users mount large, non-model files into their working directory
      # (like data or their entire HOME directory), when we are training on-cluster we use a
      # specially-prepared clean copy of the model rather than the working directory.
      #
      # When running locally, we filter out the files using detignore.
      if on_cluster:
          model_dir = constants.MANAGED_TRAINING_MODEL_COPY
          ignore_func = None
      else:
          model_dir = "."
          ignore_func = detignore.make_shutil_ignore(
              pathlib.Path(model_dir)
          )
  
      shutil.copytree(model_dir, code_path, ignore=ignore_func)
      os.chmod(code_path, 0o755)
  
imports: import collections
  import contextlib
  import copy
  import datetime
  import enum
  import errno
  import inspect
  import json
  import logging
  import math
  import numbers
  import os
  import pathlib
  import random
  import re
  import shutil
  import signal
  import socket
  import stat
  import subprocess
  import time
  import uuid
  from typing import Any, Callable, Dict, Iterator, List, Optional, Set, SupportsFloat, Tuple, Union, cast
  import psutil
  import determined
  from determined import constants
  from determined.common import check, detignore, util
label_desc: Use image node_id 12 for calling a global function with example usage: write_user_code(path, on_cluster) without return types