How to run on CPU?
Hi everyone,I’m currently trying to modify thetoken classification script. The machine where I’m running the script has a GPU that is currently fully utilized by another process, so I’d like to run my classification script on the CPU (I’m just editing things, not actually running the training) and only switch to the GPU when I’m done editing. I’ve noticed that other scripts in examples have the--no_cudaparameter, but this one doesn’t. How can I make this script run in my CPU?Thanks!Irene
2022-04-01T09:32:45Z
You’ll have to force theacceleratorto run on CPU.github.comhuggingface/transformers/blob/9de70f213eb234522095cc9af7b2fac53afc2d87/examples/pytorch/token-classification/run_ner_no_trainer.py#L230if args.push_to_hub:assert args.output_dir is not None, "Need an `output_dir` to create a repo when `--push_to_hub` is passed."return argsdef main():args = parse_args()# Initialize the accelerator. We will let the accelerator handle device placement for us in this example.accelerator = Accelerator()# Make one log on every process with the configuration for debugging.logging.basicConfig(format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",datefmt="%m/%d/%Y %H:%M:%S",level=logging.INFO,)logger.info(accelerator.state)# Setup logging, we only want one process per machine to log things on the screen.# accelerator.is_local_main_process is only True for one process per machine.accelerator = Accelerator(cpu=True)should do the trick.