0

What I want to do

I am working on a multi-GPU server, and would like to open a Jupyter notebook that only runs on some currently unused GPU (which may change from session to session).

In other words, at the beginning of each session, I want to export CUDA_VISIBLE_DEVICES=i, replacing i with the index of a currently unused GPU. Then I want to open a Jupyter notebook that actually sees this environment variable.

Crucially, I want to open the Jupyter notebook in VS Code (i.e., my local VS Code with the remote development extension).

Both my local machine and the server run on Linux.

I am aware that:

  • I could open the notebook in my local browser instead
  • or I could set the environment variable inside the notebook.

These are not the answers I am looking for. VS Code has a nicer user experience, and I don't want to edit the first cell of my notebook every time I open it.

What I tried

Ideally I would like to do (inside the VS Code remote development terminal):

export MYVAR=todayschoice
code test.ipynb

where a minimal test.ipynb could just contain a single cell %env. Unfortunately, the output currently does not contain MYVAR. Using code with the options -r or -n does not change anything.

On my local machine, I would work around the issue by typing the commands in my system's terminal instead of VS Code's terminal. (I tried it and it worked.) This is not possible in the remote case because the server doesn't have VS Code.

3
  • they'd be separate processes with separate environments. I don't see how this would work unless you went and built it custom using some form of interprocess communication, if that's really what you're after. or you could launch the notebook from that terminal, but it would just be a snapshot of the "inherited" environment. Commented Feb 18 at 6:49
  • @starball Building it custom sounds like too much work... I suppose by "launching the notebook from that terminal" you mean using jupyter notebook instead of code? This would open the notebook in my browser (the first alternative I mentioned in my question). But why can't I "open a snapshot of the "inherited" environment" in VS Code instead? -- Anyway, right now I'm setting the variable inside the notebook (in VS Code, the second alternative I mentioned), and it works okay, but I'd still be interested in other solutions. Commented Feb 19 at 16:06
  • run the command to open the notebook from vscode's integrated terminal Commented Feb 19 at 17:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.