3

I am trying to execute BERT's run_clasifier.py script using terminal as below:

python run_classifier.py --task_name=cola --do_predict=true --data_dir=<data-dir> --vocab_file=$BERT_BASE_DIR/vocab.txt --bert_config_file=$BERT_BASE_DIR/bert_config.json --init_checkpoint=<output_dir>/model.ckpt-1603 --max_seq_length=512 --output_dir=<output_dir>

This by default executes on GPU. Instead, I want to execute it on the CPU. Is there a way to do it for only a single trial of execution than for all the subsequent trials.?

Ashwin Geet D'Sa
  • 6,346
  • 2
  • 31
  • 59
  • You can try `CUDA_VISIBLE_DEVICES=""` https://stackoverflow.com/a/37663502/165753 – dimid Jun 17 '19 at 08:49
  • Let me clarify a little more: I have multiple trials of execution and want to do it only for one in between, and in parallel for two programs, such that one runs on CPU and other on GPU. `CUDA_VISIBLE_DEVICES=""` would set environ variable, and may have equal impact on all the execution trials. – Ashwin Geet D'Sa Jun 17 '19 at 09:12
  • 1
    I understand, this won't affect other commands. In order to set an env var you need to `export` it. E.g. `export CUDA_VISIBLE_DEVICES=""` (in bash). – dimid Jun 17 '19 at 09:25
  • I will give a try. Thank you. – Ashwin Geet D'Sa Jun 17 '19 at 09:27
  • It did not work. – Ashwin Geet D'Sa Jun 17 '19 at 09:36
  • you can put a line in the beginning of your classifier code, such as `os.environ['CUDA_VISIBLE_DEVICES'] = ''`, just make sure the line of code is executed before you `import tensorflow`. You can also do this programmatically too. Another pointer is at [here](https://www.tensorflow.org/guide/gpu), which may help you control model placement on gpu/cpu in a fine-grained way. – Arron Cao Dec 13 '19 at 02:10
  • @ArronCao, please have a look at the comments, I have multiple trials of executions. I want to do it for specific trials. Your solution does work, but its for all the trials. I need more fine grained control to toggle between the two during multiple execution. – Ashwin Geet D'Sa Dec 13 '19 at 09:17

1 Answers1

1

Try use: os.environ['CUDA_VISIBLE_DEVICES'] = '-1'

walker
  • 11
  • 1