def METHOD_NAME(self, loader_cores: Optional[List[int]] = None):
    r"""Enables CPU affinity.
    Args:
        loader_cores ([int], optional): List of CPU cores to which data
            loader workers should affinitize to.
            By default, will affinitize to cores starting at :obj:`cpu0`.
            (default: :obj:`node0_cores[:num_workers]`)
    """
    if not self.num_workers > 0:
        raise ValueError(
            f"'enable_cpu_affinity' should be used with at least one "
            f"worker (got {self.num_workers})")
    if loader_cores and len(loader_cores) != self.num_workers:
        raise ValueError(
            f"The number of loader cores (got {len(loader_cores)}) "
            f"in 'enable_cpu_affinity' should match with the number "
            f"of workers (got {self.num_workers})")
    worker_init_fn_old = WorkerInitWrapper(self.worker_init_fn)
    affinity_old = psutil.Process().cpu_affinity()
    nthreads_old = torch.get_num_threads()
    loader_cores = loader_cores[:] if loader_cores else None
    def init_fn(worker_id):
        try:
            psutil.Process().cpu_affinity([loader_cores[worker_id]])
        except IndexError:
            raise ValueError(f"Cannot use CPU affinity for worker ID "
                             f"{worker_id} on CPU {loader_cores}")
        worker_init_fn_old(worker_id)
    if loader_cores is None:
        numa_info = get_numa_nodes_cores()
        if numa_info and len(numa_info[0]) > self.num_workers:
            # Take one thread per each node 0 core:
            node0_cores = [cpus[0] for core_id, cpus in numa_info[0]]
            node0_cores.sort()
        else:
            node0_cores = list(range(psutil.cpu_count(logical=False)))
        if len(node0_cores) < self.num_workers:
            raise ValueError(
                f"More workers (got {self.num_workers}) than available "
                f"cores (got {len(node0_cores)})")
        # Set default loader core IDs:
        loader_cores = node0_cores[:self.num_workers]
    try:
        # Set CPU affinity for dataloader:
        self.worker_init_fn = init_fn
        logging.debug(f"{self.num_workers} data loader workers are "
                      f"assigned to CPUs {loader_cores}")
        yield
    finally:
        # Restore omp_num_threads and cpu affinity:
        psutil.Process().cpu_affinity(affinity_old)
        torch.set_num_threads(nthreads_old)
        self.worker_init_fn = worker_init_fn_old
        self.cpu_affinity_enabled = False