Skip to content

Instantly share code, notes, and snippets.

@wd15
Last active August 16, 2024 17:14
Show Gist options
  • Save wd15/3864f8d10af377eede4320494ef94e73 to your computer and use it in GitHub Desktop.
Save wd15/3864f8d10af377eede4320494ef94e73 to your computer and use it in GitHub Desktop.
.ipynb_checkpoints

Play with pytorch

Running on a remote server

Running the notebook on a remote server with a GPU via another server that gives access to the GPU server. The problem is that the machine with the GPU doesn't have any ports that can be seen from the outside other than SSH. First setup port forwarding

$ ssh ruth
$ ssh -N -L ruth:8888:localhost:8888 rgpu2

rgpu2 seems to work with Nix.

Start up the notebook

$ ssh ruth
$ srun -N 1 -n 5 --pty --partition=gpu --gres=gpu:kepler:1 bash
$ cd .../pytorch-play
$ nix-shell --pure
[nix-shell]$ cd ...
[nix-shell]$ jupyter notebook --no-browser --NotebookApp.allow_remote_access=True

The allow_remote_access is required otherwise you get a 403. Copy the token and you should be able to view the notebooks from http://ruth:8888/?token=<token>.

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
let
inherit (import <nixpkgs> {}) fetchFromGitHub;
nixpkgs_download = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "5e46d5a7b59d69e7b86239195f58d26277ae0370";
sha256 = "0xynhyafvj8mazmagpnxp0k6l5wjfcg8j0syxvs4v87hf0g6n917";
};
pkgs = import nixpkgs_download {
config = {
allowUnfree = true;
cudaSupport = true;
};
};
pythonPackages = pkgs.python3Packages;
pytorchWithCuda9 = pythonPackages.pytorchWithCuda.override {
cudatoolkit=pkgs.cudatoolkit_9_0;
};
in
pkgs.stdenv.mkDerivation rec {
pname = "pytorch-play1";
version = "0.1";
nativeBuildInputs = with pythonPackages; [
scipy
numpy
matplotlib
jupyter
tkinter
toolz
pylint
flake8
black
ipywidgets
pytorchWithCuda9
pkgs.cudatoolkit_9_0
];
src = null;
##src=builtins.filterSource (path: type: type != "directory" || baseNameOf path != ".git") ./.;
shellHook = ''
jupyter nbextension install --py widgetsnbextension --user > /dev/null 2>&1
jupyter nbextension enable widgetsnbextension --user --py > /dev/null 2>&1
pip install jupyter_contrib_nbextensions --user > /dev/null 2>&1
jupyter contrib nbextension install --user > /dev/null 2>&1
jupyter nbextension enable spellchecker/main > /dev/null 2>&1
export OMPI_MCA_plm_rsh_agent=/usr/bin/ssh
SOURCE_DATE_EPOCH=$(date +%s)
export PYTHONUSERBASE=$PWD/.local
export USER_SITE=`python -c "import site; print(site.USER_SITE)"`
export PYTHONPATH=$PYTHONPATH:$USER_SITE
export PATH=$PATH:$PYTHONUSERBASE/bin
export CUDAPATH="/usr/lib/x86_64-linux-gnu"
export LD_PRELOAD=$CUDAPATH/libcuda.so.1:$CUDAPATH/libnvidia-fatbinaryloader.so.390.116:$CUDAPATH/libnvidia-ptxjitcompiler.so.1:$CUDAPATH/libnvidia-ml.so.1
# To install extra packages use
#
# $ pip install --user <package>
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment