-
Notifications
You must be signed in to change notification settings - Fork 32
✨ Docker settings, BatchEnsemble utilities rework + minor fixes #141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 67 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
a6d0e97
:whale: Add Dockerfile
tonyzamyatin 8b416c0
:whale: Fix flit build errors
tonyzamyatin 3ef9132
:whale: Install OpenSSH and start server when container starts
tonyzamyatin 4ffeb34
:whale: Fix SSH key not being recognized and add shell prompt customi…
tonyzamyatin ed04e00
:whale: Reformat Dockerfile
tonyzamyatin 5d731cd
:whale: Install OpenGL and run SSH setup for GitHub-Auth
tonyzamyatin 025f84d
:whale: Ensure setup only runs once when container is started for the…
tonyzamyatin 4106501
:whale: Optimize setup steps and make custom prompt optional via env …
tonyzamyatin c8cd50b
:whale: Optimize build time and run shell prompt in initial setup
tonyzamyatin a49bd3e
:books: Add documentation for using Docker image
tonyzamyatin bb79e0b
:whale: Install dependencies in editable mode
tonyzamyatin eaa09d6
:bug: Fix pip install in editable mode
tonyzamyatin 2522a31
:bug: Fix MNIST test dataloader for shifted data
tonyzamyatin ae0405a
:hammer: Fix and format container start script and move it to entrypo…
tonyzamyatin 5d1d27f
:bug: Fix `RandomRescale`
alafage 9624b2c
:shirt: Add scaler exception
o-laurent 748f698
:shirt: Move Docker in the installation section
o-laurent 3b6c7c6
:bug: Fast track config fixes
o-laurent 11801da
:fire: Remove shift-severity in MNISTC
o-laurent 16cfb44
:book: Update test dataloaders docstring
o-laurent 9d761f1
:hammer: use datamodule's shift-severity
o-laurent 3a186b8
:white_check_mark: Fix coverage
o-laurent d4d09f5
:fire: Remove documentation for removed argument
o-laurent 6df0914
:bug: Add missing learning rate scheduler class paths to lenet configs
tonyzamyatin 56ab652
:sparkles: Add BatchEnsemble wrapper
tonyzamyatin 156aa91
:bug: Merge pull request #135 from tonyzamyatin/bugfix_mnist
o-laurent 918de33
:books: Update documentation regarding (batch) ensemble usage
tonyzamyatin c5b62d8
:sparkles: Add LeNet BatchEnsemble and Deep Ensemble
tonyzamyatin 940f721
:book: State support of Python 3.13
o-laurent 0a6e32f
:bug: Make sklearn optional. Fix #136
o-laurent b3c1687
:shirt: Refine dependencies and import error messages
o-laurent 1b0ce53
:zap: Update ruff and lint
o-laurent 017d040
:fire: Remove torchaudio from workflows
o-laurent a92385e
:shirt: Lint
o-laurent eda886b
:whale: Update Dockerfile
o-laurent ca73b4b
:shirt: Also format
o-laurent 5976919
:white_check_mark: Add test for BatchEnsemble wrapper and LeNet imple…
tonyzamyatin 96e3eed
:bug: Fix `extended_out_features` computation in `PackedLinear`
alafage c001ea6
:white_check_mark: Update PackedLinear tests
alafage 2242805
:whale: Install pre-commit hooks on container start
tonyzamyatin 145181a
:art: Format PackedLinear
alafage a622910
:shirt: Lint
o-laurent 0f2dca0
🐳 Merge pull request #134 from tonyzamyatin/add-dockerfile
o-laurent 18dacb3
:heavy_check_mark: Add test for BatchEnsemble wrapper and fix bug in …
tonyzamyatin 79b567d
:ok_hand: Comply with PEP 257
o-laurent dbf4df9
:books: Add note that BatchEnsemble wrapper expects model to use Batc…
tonyzamyatin 16a235b
:hammer: Refactor BatchEnsemble test case to use framework's test format
tonyzamyatin 698ba1a
:heavy_plus_sign: / :heavy_minus_sign: Replace wand by kornia
o-laurent 89b26f2
:hammer: Use kornia's motion blur & remove useless covignores
o-laurent 839444e
:book: Improve the clarity of the OOD detection behavior #139
o-laurent 85bbe59
Merge branch 'dev' of github.com:ENSTA-U2IS-AI/torch-uncertainty into…
o-laurent 4887f78
:white_check_mark: Fix cov
o-laurent 12a7423
:shirt: Fix typo in corruption.py
o-laurent cf038e0
:hammer: Merge pull request #140 from ENSTA-U2IS-AI/motion_blur
o-laurent 6e2596d
:hammer: Use `einops.repeat` instead of `torch.repeat` in `RepeatTarget`
alafage 16c7705
:hammer: Refine BatchEnsemble layers and add conversion methods
alafage 9d4b4a4
:hammer: `BatchEnsemble` wrapper overhaul
alafage 8b29026
:books: Add BatchEnsemble wrapper utilities in the API Reference
alafage f2ae628
:book: `BatchEnsemble` docstring update
alafage c737d07
:book: `BatchEnsemble` docstring update
alafage 819f7e0
Merge pull request #137 from tonyzamyatin/lenet_batchensemble
alafage 0292306
:wrench: Bump version
alafage 8b81c13
:wrench: Add doc trigger when ready for review
o-laurent d3fa198
:bug: Fix triggers
o-laurent a7127d4
:bug: Fix pytest triggers
o-laurent 30c0f84
:shirt: Update according PR comments
alafage 7572ca0
:ok_hand: Comply with cosmetic comments
o-laurent 618f7db
:white_check_mark: Finish coverage
o-laurent 1c5c7d8
:wrench: rework optional dependency groups
o-laurent f4ffbf7
:fire: Remove sklearn and np in AUSE
o-laurent 42a8c83
:fire: Remove overriding of cst types
o-laurent 1f4db81
:bug: Fix NaN handling in AUSE & add test
o-laurent 1a07f0d
:racehorse: Don't download MNISTC in tests
o-laurent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FROM pytorch/pytorch:2.6.0-cuda12.6-cudnn9-runtime | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive \ | ||
PYTHONUNBUFFERED=1 \ | ||
LC_ALL=C.UTF-8 \ | ||
LANG=C.UTF-8 | ||
|
||
# Install Git, OpenSSH Server, and OpenGL (PyTorch's base image already includes Conda and Pip) | ||
RUN apt-get update && apt-get install -y \ | ||
git \ | ||
openssh-server \ | ||
libgl1 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /workspace | ||
|
||
# Create an empty README.md file and an empty torch_uncertainty module to satisfy flit | ||
RUN touch README.md && mkdir -p torch_uncertainty && touch torch_uncertainty/__init__.py | ||
|
||
# Copy dependency file | ||
COPY pyproject.toml /workspace/ | ||
|
||
# Install dependencies all dependencies | ||
RUN pip install --no-cache-dir -e ".[all]" | ||
|
||
# Always activate Conda when opening a new terminal | ||
RUN echo "source /opt/conda/bin/activate" >> /root/.bashrc | ||
|
||
# Configure SSH server | ||
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config && \ | ||
echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \ | ||
echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config | ||
|
||
# Expose port 8888 for TensorBoard and Jupyter Notebook and port 22 for SSH | ||
EXPOSE 8888 22 | ||
|
||
# Entrypoint script (runs every time the container starts) | ||
COPY docker/entrypoint.sh /usr/local/bin/ | ||
RUN chmod +x /usr/local/bin/entrypoint.sh | ||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] | ||
|
||
# Note that if /workspace/ is a mounted volume, any files copied to /workspace/ during the build will be overwritten by the mounted volume | ||
# This is why we copy the entrypoint script to /usr/local/bin/ instead of /workspace/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# :whale: Docker image for contributors | ||
|
||
### Pre-built Docker image | ||
1. To pull the pre-built image from Docker Hub, simply run: | ||
```bash | ||
docker pull docker.io/tonyzamyatin/torch-uncertainty:latest | ||
``` | ||
|
||
This image includes: | ||
- PyTorch with CUDA support | ||
- OpenGL (for visualization tasks) | ||
- Git, OpenSSH, and all Python dependencies | ||
|
||
Checkout the [registry on Docker Hub](https://hub.docker.com/repository/docker/tonyzamyatin/torch-uncertainty/general) for all available images. | ||
|
||
2. To start a container using this image, set up the necessary environment variables and run: | ||
```bash | ||
docker run --rm -it --gpus all -p 8888:8888 -p 22:22 \ | ||
-e VM_SSH_PUBLIC_KEY="your-public-key" \ | ||
-e GITHUB_SSH_PRIVATE_KEY="your-github-key" \ | ||
-e GITHUB_USER="your-github-username" \ | ||
-e GIT_USER_EMAIL="your-git-email" \ | ||
-e GIT_USER_NAME="your-git-name" \ | ||
docker.io/tonyzamyatin/torch-uncertainty | ||
``` | ||
|
||
Optionally, you can also set `-e USER_COMPACT_SHELL_PROMPT="true"` | ||
to make the VM's shell prompts compact and colorized. | ||
|
||
**Note:** Some cloud providers offer templates, in which you can preconfigure | ||
in advance which Docker image to pull and which environment variables to set. | ||
In this case, the provider will pull the image, set all environment variables, | ||
and start the container for you. | ||
|
||
3. Once your cloud provider has deployed the VM, it will display the host address and SSH port. | ||
You can connect to the container via SSH using: | ||
```bash | ||
ssh -i /path/to/private_key root@<VM_HOST> -p <VM_PORT> | ||
``` | ||
|
||
Replace `<VM_HOST>` and `<VM_PORT>` with the values provided by your cloud provider, | ||
and `/path/to/private_key` with the private key that corresponds to `VM_SSH_PUBLIC_KEY`. | ||
|
||
4. The container exposes port `8888` in case you want to run Jupyter Notebooks or TensorBoard. | ||
|
||
**Note:** The `/workspace` directory is mounted from your local machine or cloud storage, | ||
so changes persist across container restarts. | ||
If using a cloud provider, ensure your network volume is correctly attached to avoid losing data. | ||
|
||
### Modifying and publishing custom Docker image | ||
|
||
If you want to make changes to the Dockerfile, follow these steps: | ||
1. Edit the Dockerfile to fit your needs. | ||
|
||
2. Build the modified image: | ||
``` | ||
docker build -t my-custom-image . | ||
``` | ||
|
||
3. Push to a Docker registry (if you want to use it on another VM): | ||
``` | ||
docker tag my-custom-image mydockerhubuser/my-custom-image:tag | ||
docker push mydockerhubuser/my-custom-image:tag | ||
``` | ||
|
||
4. Pull the custom image onto your VM: | ||
``` | ||
docker pull mydockerhubuser/my-custom-image | ||
``` | ||
|
||
5. Run the container using the same docker run command with the new image name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#!/bin/bash | ||
set -e # Exit immediately if a command fails | ||
|
||
echo "🚀 Starting container..." | ||
|
||
# Ensure SSH directory exists and has correct permissions | ||
if [ ! -d /root/.ssh ]; then | ||
echo "📂 Creating SSH directory..." | ||
mkdir -p /root/.ssh && chmod 700 /root/.ssh | ||
fi | ||
|
||
# Ensure the VM's public SSH key is added for authentication | ||
if [ -z "$VM_SSH_PUBLIC_KEY" ]; then | ||
echo "❌ Error: Please set the VM_SSH_PUBLIC_KEY environment variable." | ||
exit 1 | ||
fi | ||
if [ ! -f /root/.ssh/authorized_keys ] || ! grep -q "$VM_SSH_PUBLIC_KEY" /root/.ssh/authorized_keys; then | ||
echo "🔑 Adding VM SSH public key..." | ||
echo "$VM_SSH_PUBLIC_KEY" > /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys | ||
fi | ||
|
||
# Ensure GitHub SSH private key is set up for authentication | ||
if [ -z "$GITHUB_SSH_PRIVATE_KEY" ]; then | ||
echo "❌ Error: Please set the GITHUB_SSH_PRIVATE_KEY environment variable." | ||
exit 1 | ||
fi | ||
if [ ! -f /root/.ssh/github_rsa ]; then | ||
echo "🔐 Adding GitHub SSH private key..." | ||
echo "$GITHUB_SSH_PRIVATE_KEY" > /root/.ssh/github_rsa && chmod 600 /root/.ssh/github_rsa | ||
fi | ||
|
||
# Configure SSH client for GitHub authentication | ||
if [ ! -f /root/.ssh/config ] || ! grep -q 'Host github.com' /root/.ssh/config; then | ||
echo "⚙️ Configuring SSH client for GitHub authentication..." | ||
cat <<EOF > /root/.ssh/config | ||
Host github.com | ||
User git | ||
IdentityFile /root/.ssh/github_rsa | ||
EOF | ||
chmod 600 /root/.ssh/config | ||
fi | ||
|
||
# Add GitHub to known hosts (to avoid SSH verification prompts) | ||
echo "📌 Ensuring GitHub is a known host..." | ||
ssh-keygen -F github.com > /dev/null 2>&1 || ssh-keyscan github.com >> /root/.ssh/known_hosts | ||
|
||
# Start SSH agent and add GitHub private key (if not already added) | ||
if ! pgrep -x "ssh-agent" > /dev/null; then | ||
echo "🕵️ Starting SSH agent..." | ||
eval "$(ssh-agent -s)" | ||
fi | ||
if ssh-add -l | grep -q github_rsa; then | ||
echo "✅ GitHub SSH key already added." | ||
else | ||
echo "🔑 Adding GitHub SSH key to agent..." | ||
ssh-add /root/.ssh/github_rsa | ||
fi | ||
|
||
# Set Git user name and email (if provided) | ||
if [ -n "$GIT_USER_NAME" ]; then | ||
echo "👤 Setting Git username: $GIT_USER_NAME" | ||
git config --global user.name "$GIT_USER_NAME" | ||
fi | ||
if [ -n "$GIT_USER_EMAIL" ]; then | ||
echo "📧 Setting Git email: $GIT_USER_EMAIL" | ||
git config --global user.email "$GIT_USER_EMAIL" | ||
fi | ||
|
||
# Ensure first-time setup runs only once | ||
if [ ! -f /workspace/.setup_done ]; then | ||
echo "🛠️ Running first-time setup..." | ||
|
||
# Ensure GitHub username is set | ||
if [ -z "$GITHUB_USER" ]; then | ||
echo "❌ Error: Please set the GITHUB_USER environment variable." | ||
exit 1 | ||
fi | ||
|
||
# Clone GitHub repo if not already cloned | ||
if [ ! -d "/workspace/.git" ]; then | ||
echo "📦 Cloning repository: $GITHUB_USER/torch-uncertainty..." | ||
git clone git@github.com:$GITHUB_USER/torch-uncertainty.git /workspace | ||
fi | ||
|
||
# Mark setup as completed | ||
touch /workspace/.setup_done | ||
echo "✅ First-time setup complete!" | ||
else | ||
echo "⏩ Skipping first-time setup (already done)." | ||
fi | ||
|
||
# Apply compact shell prompt customization (if enabled) | ||
if [ -n "$USE_COMPACT_SHELL_PROMPT" ]; then | ||
echo "🎨 Applying compact shell prompt customization..." | ||
echo 'force_color_prompt=yes' >> /root/.bashrc | ||
echo 'PS1="\[\033[01;34m\]\W\[\033[00m\]\$ "' >> /root/.bashrc | ||
echo 'if [ -x /usr/bin/dircolors ]; then' >> /root/.bashrc | ||
echo ' test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"' >> /root/.bashrc | ||
echo ' alias ls="ls --color=auto"' >> /root/.bashrc | ||
echo ' alias grep="grep --color=auto"' >> /root/.bashrc | ||
echo ' alias fgrep="fgrep --color=auto"' >> /root/.bashrc | ||
echo ' alias egrep="egrep --color=auto"' >> /root/.bashrc | ||
echo 'fi' >> /root/.bashrc | ||
fi | ||
|
||
# Ensure /workspace is in PYTHONPATH | ||
if ! echo "$PYTHONPATH" | grep -q "/workspace"; then | ||
echo "📌 Adding /workspace to PYTHONPATH" | ||
export PYTHONPATH="/workspace:$PYTHONPATH" | ||
else | ||
echo "✅ PYTHONPATH is already correctly set." | ||
fi | ||
|
||
# Check if torch_uncertainty is installed in editable mode | ||
if pip show torch_uncertainty | grep -q "Editable project location: /workspace"; then | ||
echo "✅ torch_uncertainty is already installed in editable mode. 🎉" | ||
else | ||
echo "🔄 Reinstalling torch_uncertainty in editable mode..." | ||
pip uninstall -y torch-uncertainty | ||
pip install -e /workspace | ||
echo "✅ torch_uncertainty is now installed in editable mode! 🚀" | ||
fi | ||
|
||
# Activate pre-commit hooks (if enabled) | ||
echo "🔗 Activating pre-commit hooks..." | ||
pre-commit install | ||
|
||
# Ensure SSH server is started | ||
echo "🔑 Starting SSH server..." | ||
mkdir -p /run/sshd && chmod 755 /run/sshd | ||
/usr/sbin/sshd -D |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.