From 110bc98b3df50f69586091e96b0643ebfa39a628 Mon Sep 17 00:00:00 2001 From: Eli Maor Date: Sun, 12 Dec 2021 20:08:05 +0200 Subject: [PATCH 1/7] Dockerfile --- Dockerfile | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..d7999a1dd0f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,65 @@ +FROM nvidia/cuda:11.1-base-ubuntu20.04 + +# Install dependencies +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + curl \ + ca-certificates \ + dumb-init \ + htop \ + openssh-server \ + sudo \ + git \ + bzip2 \ + libx11-6 \ + locales \ + man \ + nano \ + git \ + procps \ + openssh-client \ + vim.tiny \ + lsb-release \ + python \ + python3-pip \ + python3-opencv \ + && rm -rf /var/lib/apt/lists/* + +RUN sed -i "s/# en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen \ + && locale-gen +ENV LANG=en_US.UTF-8 + +# Create project directory +RUN mkdir /projects + +# Create a non-root user +RUN adduser --disabled-password --gecos '' --shell /bin/bash coder \ + && chown -R coder:coder /projects +RUN echo "coder ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-coder + +# Install fixuid +ENV ARCH=amd64 +RUN curl -fsSL "https://github.com/boxboat/fixuid/releases/download/v0.4.1/fixuid-0.4.1-linux-$ARCH.tar.gz" | tar -C /usr/local/bin -xzf - && \ + chown root:root /usr/local/bin/fixuid && \ + chmod 4755 /usr/local/bin/fixuid && \ + mkdir -p /etc/fixuid && \ + printf "user: coder\ngroup: coder\n" > /etc/fixuid/config.yml + +# Install code-server +WORKDIR /tmp +ENV CODE_SERVER_VERSION=3.12.0 +RUN curl -fOL https://github.com/cdr/code-server/releases/download/v${CODE_SERVER_VERSION}/code-server_${CODE_SERVER_VERSION}_${ARCH}.deb +RUN dpkg -i ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb && rm ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb +COPY ./entrypoint.sh /usr/bin/entrypoint.sh + +# Install +RUN pip install notebook +RUN pip install jupyterlab +RUN pip install voila +# Switch to default user +USER coder +ENV USER=coder +ENV HOME=/home/coder +WORKDIR /projects + + +EXPOSE 8443 From 385e6ba777e1ff36b5c9db40ea665152040c3e72 Mon Sep 17 00:00:00 2001 From: Eli Maor Date: Sun, 12 Dec 2021 20:09:28 +0200 Subject: [PATCH 2/7] Update Dockerfile adding jupyterlab & notebook --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d7999a1dd0f2..f59daad10467 100644 --- a/Dockerfile +++ b/Dockerfile @@ -51,7 +51,7 @@ RUN curl -fOL https://github.com/cdr/code-server/releases/download/v${CODE_SERVE RUN dpkg -i ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb && rm ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb COPY ./entrypoint.sh /usr/bin/entrypoint.sh -# Install +# Install jupyterlab & notebook RUN pip install notebook RUN pip install jupyterlab RUN pip install voila From 396a8a1e7eb4701eb76e9a549bc731da42db46f7 Mon Sep 17 00:00:00 2001 From: Eli Maor Date: Sun, 12 Dec 2021 20:11:04 +0200 Subject: [PATCH 3/7] Update README.md --- docs/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/README.md b/docs/README.md index 0bf1002d8c7f..ef176c928e73 100644 --- a/docs/README.md +++ b/docs/README.md @@ -75,3 +75,7 @@ positions](https://coder.com/careers#openings)! Want remote development for your organization or enterprise? Visit [our website](https://coder.com) to learn more about Coder. + + +# Build Docker image +docker build -f Dockerfile -t pytorch-code-server:v$VERSION From a25df2961d51be8da5c1b277821da82e0337a955 Mon Sep 17 00:00:00 2001 From: Eli Maor Date: Sun, 12 Dec 2021 20:32:59 +0200 Subject: [PATCH 4/7] Update Dockerfile --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index f59daad10467..e2a5dcef66f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,5 +61,6 @@ ENV USER=coder ENV HOME=/home/coder WORKDIR /projects +CMD cp -r $HOME/.vscode-insiders/extensions/* $HOME/.code-server/extensions/ EXPOSE 8443 From f12100a042c9cb88adcabfb39d880fe8efa345ba Mon Sep 17 00:00:00 2001 From: Eli Maor Date: Sun, 12 Dec 2021 20:35:57 +0200 Subject: [PATCH 5/7] Update Dockerfile --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e2a5dcef66f9..a6477ba72913 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,6 +61,9 @@ ENV USER=coder ENV HOME=/home/coder WORKDIR /projects -CMD cp -r $HOME/.vscode-insiders/extensions/* $HOME/.code-server/extensions/ + +# https://coder.com/docs/code-server/latest/FAQ#how-do-i-install-an-extension + +CMD 'cp -r $HOME/.vscode-insiders/extensions/* $HOME/.code-server/extensions/' EXPOSE 8443 From dc067638b7fc70bbd18253a38b71eb3903fe6d0e Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 12 Dec 2021 20:42:19 +0200 Subject: [PATCH 6/7] add Docker folder snd files --- Dockerfile => Docker/Dockerfile | 7 +- Docker/LICENSE | 21 ++ Docker/README.md | 35 +++ Docker/entrypoint.sh | 20 ++ Docker/example-project/.gitignore | 241 ++++++++++++++++++ .../example-project/.vscode/extensions.json | 7 + Docker/example-project/.vscode/launch.json | 11 + Docker/example-project/.vscode/settings.json | 35 +++ Docker/example-project/data/placeholder | 1 + Docker/example-project/docker-compose.yaml | 39 +++ Docker/example-project/install.sh | 2 + Docker/example-project/main.py | 145 +++++++++++ Docker/example-project/requirements.txt | 5 + 13 files changed, 564 insertions(+), 5 deletions(-) rename Dockerfile => Docker/Dockerfile (89%) create mode 100644 Docker/LICENSE create mode 100644 Docker/README.md create mode 100755 Docker/entrypoint.sh create mode 100644 Docker/example-project/.gitignore create mode 100644 Docker/example-project/.vscode/extensions.json create mode 100644 Docker/example-project/.vscode/launch.json create mode 100644 Docker/example-project/.vscode/settings.json create mode 100644 Docker/example-project/data/placeholder create mode 100644 Docker/example-project/docker-compose.yaml create mode 100755 Docker/example-project/install.sh create mode 100644 Docker/example-project/main.py create mode 100644 Docker/example-project/requirements.txt diff --git a/Dockerfile b/Docker/Dockerfile similarity index 89% rename from Dockerfile rename to Docker/Dockerfile index a6477ba72913..dabbbf4c3f3d 100644 --- a/Dockerfile +++ b/Docker/Dockerfile @@ -51,7 +51,7 @@ RUN curl -fOL https://github.com/cdr/code-server/releases/download/v${CODE_SERVE RUN dpkg -i ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb && rm ./code-server_${CODE_SERVER_VERSION}_${ARCH}.deb COPY ./entrypoint.sh /usr/bin/entrypoint.sh -# Install jupyterlab & notebook +# Install RUN pip install notebook RUN pip install jupyterlab RUN pip install voila @@ -62,8 +62,5 @@ ENV HOME=/home/coder WORKDIR /projects -# https://coder.com/docs/code-server/latest/FAQ#how-do-i-install-an-extension - -CMD 'cp -r $HOME/.vscode-insiders/extensions/* $HOME/.code-server/extensions/' - EXPOSE 8443 +ENTRYPOINT ["/usr/bin/entrypoint.sh", "--bind-addr", "0.0.0.0:8443", "--cert", "--disable-telemetry", "."] diff --git a/Docker/LICENSE b/Docker/LICENSE new file mode 100644 index 000000000000..b2190978fdfa --- /dev/null +++ b/Docker/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Works on my machine + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Docker/README.md b/Docker/README.md new file mode 100644 index 000000000000..4dddd8352c74 --- /dev/null +++ b/Docker/README.md @@ -0,0 +1,35 @@ +# PyTorch Code Server with CUDA +Code Server Docker image for PyTorch with python development on the browser. Contains: +- CUDA 11.1 +- Python 3.8.3 +- PyTorch 1.81.1 +- Code Server 3.10.0 (VSCode 1.56.0) + +## Requirements +- CUDA device with compute capability 3.5 or higher +- [NVIDIA Docker Toolkit](https://github.com/ghokun/nvidia-docker-host) + + +## Quickstart +``` +$ docker run --privileged --rm -it --init \ + --gpus=all \ + --ipc=host \ + --user="$(id -u):$(id -g)" \ + --volume="$PWD:/projects" \ + -p 8443:8443 \ + ghcr.io/works-on-my-machine/pytorch-code-server:1.9.1 +``` +After running above command open `localhost:8443` in your browser. Find your password under `~/.config/code-server/config.yaml` +```bash +$ docker exec -it /bin/bash +$ cat ~/.config/code-server/config.yaml +``` +Login with your password. For a working example look at example project folder. Contains recommended extensions and settings. Example project also contains noVNC support. Checkout `docker-compose.yml` file for more information. +## Notes +- Due to a possible [bug](https://github.com/cdr/code-server/issues/2514) in `ms-python.python` extension. After installing it revert it to a previous version by selecting "Install Another Version". 2020.10.332292344 worked for me. + +## TODO +- [ ] Better documentation +- [x] NO-VNC support for visualization +- [x] Docker compose support diff --git a/Docker/entrypoint.sh b/Docker/entrypoint.sh new file mode 100755 index 000000000000..48a17a312851 --- /dev/null +++ b/Docker/entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu + +# We do this first to ensure sudo works below when renaming the user. +# Otherwise the current container UID may not exist in the passwd database. +eval "$(fixuid -q)" + +if [ "${DOCKER_USER-}" ] && [ "$DOCKER_USER" != "$USER" ]; then + echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers.d/nopasswd > /dev/null + # Unfortunately we cannot change $HOME as we cannot move any bind mounts + # nor can we bind mount $HOME into a new home as that requires a privileged container. + sudo usermod --login "$DOCKER_USER" coder + sudo groupmod -n "$DOCKER_USER" coder + + USER="$DOCKER_USER" + + sudo sed -i "/coder/d" /etc/sudoers.d/nopasswd +fi + +dumb-init /usr/bin/code-server "$@" diff --git a/Docker/example-project/.gitignore b/Docker/example-project/.gitignore new file mode 100644 index 000000000000..a46451028576 --- /dev/null +++ b/Docker/example-project/.gitignore @@ -0,0 +1,241 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,vscode,visualstudiocode,macos,linux,windows +# Edit at https://www.toptal.com/developers/gitignore?templates=python,jupyternotebooks,vscode,visualstudiocode,macos,linux,windows + +### JupyterNotebooks ### +# gitignore template for Jupyter Notebooks +# website: http://jupyter.org/ + +.ipynb_checkpoints +*/.ipynb_checkpoints/* + +# IPython +profile_default/ +ipython_config.py + +# Remove previous ipynb_checkpoints +# git rm -r .ipynb_checkpoints/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +pytestdebug.log + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ +doc/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook + +# IPython + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ +pythonenv* + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# profiling data +.prof + +### VisualStudioCode ### +.vscode/* +!.vscode/tasks.json +!.vscode/launch.json +*.code-workspace + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### vscode ### +!.vscode/settings.json +!.vscode/extensions.json + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/python,jupyternotebooks,vscode,visualstudiocode,macos,linux,windows diff --git a/Docker/example-project/.vscode/extensions.json b/Docker/example-project/.vscode/extensions.json new file mode 100644 index 000000000000..06620eb077d6 --- /dev/null +++ b/Docker/example-project/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "ms-python.python", + "github.github-vscode-theme", + "gaulomatic.vscode-icontheme-nomo-dark-macos" + ] +} \ No newline at end of file diff --git a/Docker/example-project/.vscode/launch.json b/Docker/example-project/.vscode/launch.json new file mode 100644 index 000000000000..949eadbb1081 --- /dev/null +++ b/Docker/example-project/.vscode/launch.json @@ -0,0 +1,11 @@ +{ + "configurations": [ + { + "name": "Python: Run Main", + "type": "python", + "request": "launch", + "program": "main.py", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/Docker/example-project/.vscode/settings.json b/Docker/example-project/.vscode/settings.json new file mode 100644 index 000000000000..68a94359df74 --- /dev/null +++ b/Docker/example-project/.vscode/settings.json @@ -0,0 +1,35 @@ +{ + "debug.console.fontSize": 12, + "diffEditor.ignoreTrimWhitespace": true, + "diffEditor.renderSideBySide": false, + "editor.fontSize": 12, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.minimap.enabled": false, + "editor.renderControlCharacters": true, + "editor.renderWhitespace": "all", + "editor.rulers": [ + { + "column": 80 + } + ], + "editor.suggestSelection": "first", + "editor.tabSize": 2, + "explorer.confirmDragAndDrop": false, + "files.autoSave": "afterDelay", + "python.linting.enabled": true, + "python.linting.pylintArgs": [ + "--generated-members=numpy.* ,torch.*" + ], + "python.linting.pylintEnabled": true, + "python.pythonPath": "/usr/bin/python3", + "terminal.integrated.cursorBlinking": true, + "terminal.integrated.cursorStyle": "underline", + "terminal.integrated.fontSize": 12, + "terminal.integrated.fontWeight": "500", + "terminal.integrated.inheritEnv": false, + "terminal.integrated.shell.linux": "/bin/bash", + "workbench.colorTheme": "GitHub Light", + "workbench.iconTheme": "vscode-icontheme-nomo-dark-macos", + "workbench.sideBar.location": "left" +} \ No newline at end of file diff --git a/Docker/example-project/data/placeholder b/Docker/example-project/data/placeholder new file mode 100644 index 000000000000..1520e2fe34de --- /dev/null +++ b/Docker/example-project/data/placeholder @@ -0,0 +1 @@ +# Data will be downloaded to this folder. \ No newline at end of file diff --git a/Docker/example-project/docker-compose.yaml b/Docker/example-project/docker-compose.yaml new file mode 100644 index 000000000000..efbb1621d48a --- /dev/null +++ b/Docker/example-project/docker-compose.yaml @@ -0,0 +1,39 @@ +version: '3.9' + +services: + pytorch-cs: + container_name: pytorch-cs + image: ghcr.io/works-on-my-machine/pytorch-code-server:1.6.0 + environment: + - "DISPLAY=pytorch-novnc:0.0" + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: 1 + capabilities: [gpu, utility] + networks: + - pytorch-network + ports: + - 8443:8443 + restart: unless-stopped + user: "${UID}:${GID}" + volumes: + - "${CS_PROJECTS_VOLUME}:/projects" + pytorch-novnc: + container_name: pytorch-novnc + image: "theasp/novnc:latest" + environment: + - "DISPLAY_WIDTH=${NOVNC_WIDTH}" + - "DISPLAY_HEIGHT=${NOVNC_HEIGHT}" + - RUN_XTERM=no + - RUN_FLUXBOX=yes + networks: + - pytorch-network + restart: unless-stopped + ports: + - 6060:8080 + +networks: + pytorch-network: \ No newline at end of file diff --git a/Docker/example-project/install.sh b/Docker/example-project/install.sh new file mode 100755 index 000000000000..09138aeb83f7 --- /dev/null +++ b/Docker/example-project/install.sh @@ -0,0 +1,2 @@ +#!/bin/bash +pip3 install -r requirements.txt -f https://download.pytorch.org/whl/torch_stable.html \ No newline at end of file diff --git a/Docker/example-project/main.py b/Docker/example-project/main.py new file mode 100644 index 000000000000..86a38090acf7 --- /dev/null +++ b/Docker/example-project/main.py @@ -0,0 +1,145 @@ +from __future__ import print_function +import argparse +import torch +import torch.nn as nn +import torch.nn.functional as F +import torch.optim as optim +from torchvision import datasets, transforms +from torch.optim.lr_scheduler import StepLR + + +class Net(nn.Module): + def __init__(self): + super(Net, self).__init__() + self.conv1 = nn.Conv2d(1, 32, 3, 1) + self.conv2 = nn.Conv2d(32, 64, 3, 1) + self.dropout1 = nn.Dropout(0.25) + self.dropout2 = nn.Dropout(0.5) + self.fc1 = nn.Linear(9216, 128) + self.fc2 = nn.Linear(128, 10) + + def forward(self, x): + x = self.conv1(x) + x = F.relu(x) + x = self.conv2(x) + x = F.relu(x) + x = F.max_pool2d(x, 2) + x = self.dropout1(x) + x = torch.flatten(x, 1) + x = self.fc1(x) + x = F.relu(x) + x = self.dropout2(x) + x = self.fc2(x) + output = F.log_softmax(x, dim=1) + return output + + +def train(args, model, device, train_loader, optimizer, epoch): + model.train() + for batch_idx, (data, target) in enumerate(train_loader): + data, target = data.to(device), target.to(device) + optimizer.zero_grad() + output = model(data) + loss = F.nll_loss(output, target) + loss.backward() + optimizer.step() + if batch_idx % args.log_interval == 0: + print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format( + epoch, batch_idx * len(data), len(train_loader.dataset), + 100. * batch_idx / len(train_loader), loss.item())) + if args.dry_run: + break + +def test(model, device, test_loader): + model.eval() + test_loss = 0 + correct = 0 + with torch.no_grad(): + for data, target in test_loader: + data, target = data.to(device), target.to(device) + output = model(data) + test_loss += F.nll_loss(output, target, reduction='sum').item() # sum up batch loss + pred = output.argmax(dim=1, keepdim=True) # get the index of the max log-probability + correct += pred.eq(target.view_as(pred)).sum().item() + + test_loss /= len(test_loader.dataset) + + print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format( + test_loss, correct, len(test_loader.dataset), + 100. * correct / len(test_loader.dataset))) + + +def main(): + # Training settings + parser = argparse.ArgumentParser(description='PyTorch MNIST Example') + parser.add_argument('--batch-size', type=int, default=64, metavar='N', + help='input batch size for training (default: 64)') + parser.add_argument('--test-batch-size', type=int, default=1000, metavar='N', + help='input batch size for testing (default: 1000)') + parser.add_argument('--epochs', type=int, default=14, metavar='N', + help='number of epochs to train (default: 14)') + parser.add_argument('--lr', type=float, default=1.0, metavar='LR', + help='learning rate (default: 1.0)') + parser.add_argument('--gamma', type=float, default=0.7, metavar='M', + help='Learning rate step gamma (default: 0.7)') + parser.add_argument('--no-cuda', action='store_true', default=False, + help='disables CUDA training') + parser.add_argument('--dry-run', action='store_true', default=False, + help='quickly check a single pass') + parser.add_argument('--seed', type=int, default=1, metavar='S', + help='random seed (default: 1)') + parser.add_argument('--log-interval', type=int, default=10, metavar='N', + help='how many batches to wait before logging training status') + parser.add_argument('--save-model', action='store_true', default=False, + help='For Saving the current Model') + args = parser.parse_args() + use_cuda = not args.no_cuda and torch.cuda.is_available() + + torch.manual_seed(args.seed) + + device = torch.device("cuda" if use_cuda else "cpu") + print('Using device:', device) + print() + + #Additional Info when using cuda + if device.type == 'cuda': + print(torch.cuda.get_device_name(0)) + print('Memory Usage:') + print('Allocated:', round(torch.cuda.memory_allocated(0)/1024**3,1), 'GB') + print('Cached: ', round(torch.cuda.memory_reserved(0)/1024**3,1), 'GB') + + train_kwargs = {'batch_size': args.batch_size} + test_kwargs = {'batch_size': args.test_batch_size} + if use_cuda: + cuda_kwargs = {'num_workers': 1, + 'pin_memory': True, + 'shuffle': True} + train_kwargs.update(cuda_kwargs) + test_kwargs.update(cuda_kwargs) + + transform=transforms.Compose([ + transforms.ToTensor(), + transforms.Normalize((0.1307,), (0.3081,)) + ]) + dataset1 = datasets.MNIST('data', train=True, download=True, + transform=transform) + dataset2 = datasets.MNIST('data', train=False, + transform=transform) + train_loader = torch.utils.data.DataLoader(dataset1,**train_kwargs) + test_loader = torch.utils.data.DataLoader(dataset2, **test_kwargs) + + model = Net().to(device) + optimizer = optim.Adadelta(model.parameters(), lr=args.lr) + + scheduler = StepLR(optimizer, step_size=1, gamma=args.gamma) + for epoch in range(1, args.epochs + 1): + train(args, model, device, train_loader, optimizer, epoch) + test(model, device, test_loader) + scheduler.step() + + if args.save_model: + torch.save(model.state_dict(), "mnist_cnn.pt") + + +if __name__ == '__main__': + main() diff --git a/Docker/example-project/requirements.txt b/Docker/example-project/requirements.txt new file mode 100644 index 000000000000..d9ead1ac0d3d --- /dev/null +++ b/Docker/example-project/requirements.txt @@ -0,0 +1,5 @@ +torch==1.8.1+cu111 +torchvision==0.9.1+cu111 +torchaudio==0.8.1 +opencv-python==4.5.1.48 +nlopt==2.7.0 \ No newline at end of file From 35d86db203fc4252f772eac395f356ce620f69c2 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sun, 12 Dec 2021 20:45:48 +0200 Subject: [PATCH 7/7] add Docker folder and files --- Docker/README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Docker/README.md b/Docker/README.md index 4dddd8352c74..0859ef1b39c0 100644 --- a/Docker/README.md +++ b/Docker/README.md @@ -3,7 +3,7 @@ Code Server Docker image for PyTorch with python development on the browser. Con - CUDA 11.1 - Python 3.8.3 - PyTorch 1.81.1 -- Code Server 3.10.0 (VSCode 1.56.0) +- Code Server 3.10.0 (VSCode 1.63.0) ## Requirements - CUDA device with compute capability 3.5 or higher @@ -27,9 +27,7 @@ $ cat ~/.config/code-server/config.yaml ``` Login with your password. For a working example look at example project folder. Contains recommended extensions and settings. Example project also contains noVNC support. Checkout `docker-compose.yml` file for more information. ## Notes -- Due to a possible [bug](https://github.com/cdr/code-server/issues/2514) in `ms-python.python` extension. After installing it revert it to a previous version by selecting "Install Another Version". 2020.10.332292344 worked for me. + ## TODO -- [ ] Better documentation -- [x] NO-VNC support for visualization -- [x] Docker compose support +