Skip to content

Instantly share code, notes, and snippets.

@changx03
Last active July 21, 2023 14:14
Show Gist options
  • Save changx03/1944820f27ee0d37ed5499cf426812cc to your computer and use it in GitHub Desktop.
Save changx03/1944820f27ee0d37ed5499cf426812cc to your computer and use it in GitHub Desktop.
Instruction for executing Python code with a specific GPU and save console outputs and error to a log file
# Use `nvtop` or `nvidia-smi` to check avalible GPUs. Only allows the Python code to access a specific GPU:
# CUDA_VISIBLE_DEVICES=<GPU_INDEX>
# Redirect standard output to `main.log` and then redirect standard error to standard output:
# > main.log 2>&1
# Allows code to run in the bakcgounrd:
# &
CUDA_VISIBLE_DEVICES=0 python main.py > main.log 2>&1 &
# Check CPU usage:
top
# Check GPU usage:
nvtop
# Kill program:
kill <UID>
# To read the end of log file
tail -f main.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment