microsoft / CodeBERT

CodeBERT
MIT License
2.15k stars 442 forks source link

GraphCodeBert/ CodeSearch, Possibly a bug in run.py, How do I proceed? #265

Open mmaashraf opened 1 year ago

mmaashraf commented 1 year ago

Hi,

I am on an M1 Mac Pro, I am trying to run the step "Fine-Tune" by executing the script run.py mentioned in https://github.com/microsoft/CodeBERT/tree/master/GraphCodeBERT/codesearch .

As per apple, the device has 10-core CPU and 16-core GPU.

However, I am getting an error

 warnings.warn(
05/31/2023 21:06:30 - INFO - __main__ -   ***** Running training *****
05/31/2023 21:06:30 - INFO - __main__ -     Num examples = 24927
05/31/2023 21:06:30 - INFO - __main__ -     Num Epochs = 10
Traceback (most recent call last):
  File "/Users/ashraf/Documents/spring23/seminar/artifact/CodeBERT/GraphCodeBERT/codesearch/run.py", line 509, in <module>
    main()
  File "/Users/ashraf/Documents/spring23/seminar/artifact/CodeBERT/GraphCodeBERT/codesearch/run.py", line 481, in main
    train(args, model, tokenizer, pool)
  File "/Users/ashraf/Documents/spring23/seminar/artifact/CodeBERT/GraphCodeBERT/codesearch/run.py", line 264, in train
    logger.info("  Instantaneous batch size per GPU = %d", args.train_batch_size//args.n_gpu)"

What could be the fix?

Thanks!

guoday commented 1 year ago

It seems that the script can't detect your GPU so that args.n_gpu = 0. Please check whether your GPU works.

mmaashraf commented 1 year ago

GPU is active. Also, does it refer to the GPU cores? or the GPU itself? Can it be hard-coded in the script? or what is the workaround?

guoday commented 1 year ago

No, it cannot be hard-coded. You can try using the Python code torch.cuda.is_available() to check if your torch library supports GPU. If it doesn't, you will need to investigate the issues and find solutions.

mmaashraf commented 1 year ago

Is possible to run using just CPU? this torch.cuda.is_available() returns False. any of the 4 downstream tasks? related to GraphCodeBERT

guoday commented 1 year ago

If you want to use CPU, you can change args.n_gpu =1 in https://github.com/microsoft/CodeBERT/blob/03631d3d718fd816aeee49f7de9340f773807fa1/GraphCodeBERT/codesearch/run.py#L464

Other downstream tasks are the same.