Skip to content

Commit

Permalink
Merge branch 'master' of github.com:guptaaryan16/ignite
Browse files Browse the repository at this point in the history
  • Loading branch information
guptaaryan16 committed Jan 10, 2024
2 parents d49904f + 88030fa commit eb89948
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/binaries-nightly-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
chmod +x ./conda.recipe/build_and_upload.sh
./conda.recipe/build_and_upload.sh
- name: Build and Publish PyPi binaries
- name: Build and Publish PyPI binaries
shell: bash -l {0}
run: |
# workaround to fix https://github.com/pytorch/ignite/issues/2373
Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ on:
paths:
- docker/**
- ".github/workflows/docker-build.yml"
push:
branches:
- master
paths:
- docker/**
- ".github/workflows/docker-build.yml"
release:
types: [published]
workflow_dispatch:


Expand All @@ -32,11 +28,13 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Changed Files Exporter
if: github.event_name == 'pull_request'
id: files
uses: umani/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Get a list of modified files
if: github.event_name == 'pull_request'
run: echo "modified=${{ steps.files.outputs.files_created }} ${{ steps.files.outputs.files_updated }}" >> $GITHUB_ENV
- name: Set outputs
id: set-modified
Expand All @@ -52,7 +50,7 @@ jobs:
build-hvd:
name: Build all Horovod flavoured PyTorch-Ignite images
needs: setup
if: contains(needs.setup.outputs.modified, 'hvd/') || contains(needs.setup.outputs.modified, 'docker.cfg')
if: github.event_name != 'pull_request' || (contains(needs.setup.outputs.modified, 'hvd/') || contains(needs.setup.outputs.modified, 'docker.cfg'))

# Cherry-picked from https://github.com/pytorch/test-infra/blob/main/.github/workflows/linux_job.yml
env:
Expand Down Expand Up @@ -98,7 +96,7 @@ jobs:
bash build.sh hvd hvd-nlp
- name: Publish docker images
if: ${{ (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.event_name == 'release' }}
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand All @@ -112,7 +110,7 @@ jobs:
build-hvd-apex:
name: Build all Horovod + Apex flavoured PyTorch-Ignite images
needs: setup
if: contains(needs.setup.outputs.modified, 'hvd/') || contains(needs.setup.outputs.modified, 'docker.cfg')
if: github.event_name != 'pull_request' || (contains(needs.setup.outputs.modified, 'hvd/') || contains(needs.setup.outputs.modified, 'docker.cfg'))

# Cherry-picked from https://github.com/pytorch/test-infra/blob/main/.github/workflows/linux_job.yml
env:
Expand Down Expand Up @@ -158,7 +156,7 @@ jobs:
bash build.sh hvd hvd-apex-nlp
- name: Publish docker images
if: ${{ (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.event_name == 'release' }}
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand All @@ -172,7 +170,7 @@ jobs:
build-main:
name: Build all PyTorch-Ignite images
needs: setup
if: contains(needs.setup.outputs.modified, 'main/') || contains(needs.setup.outputs.modified, 'docker.cfg')
if: github.event_name != 'pull_request' || (contains(needs.setup.outputs.modified, 'main/') || contains(needs.setup.outputs.modified, 'docker.cfg'))

# Cherry-picked from https://github.com/pytorch/test-infra/blob/main/.github/workflows/linux_job.yml
env:
Expand Down Expand Up @@ -218,7 +216,7 @@ jobs:
bash build.sh main nlp
- name: Publish docker images
if: ${{ (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.event_name == 'release' }}
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand All @@ -232,7 +230,7 @@ jobs:
build-main-apex:
name: Build all PyTorch-Ignite images with Apex
needs: setup
if: contains(needs.setup.outputs.modified, 'main/') || contains(needs.setup.outputs.modified, 'docker.cfg')
if: github.event_name != 'pull_request' || (contains(needs.setup.outputs.modified, 'main/') || contains(needs.setup.outputs.modified, 'docker.cfg'))

# Cherry-picked from https://github.com/pytorch/test-infra/blob/main/.github/workflows/linux_job.yml
env:
Expand Down Expand Up @@ -278,7 +276,7 @@ jobs:
bash build.sh main apex-nlp
- name: Publish docker images
if: ${{ (github.ref == 'refs/heads/master' && github.event_name == 'push') || github.event_name == 'release' }}
if: github.event_name == 'workflow_dispatch' || github.event_name == 'release'
env:
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}
DOCKER_USER: ${{ secrets.DOCKER_USER }}
Expand Down
135 changes: 135 additions & 0 deletions .github/workflows/mps-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Run unit tests on M1
on:
push:
branches:
- master
- "*.*.*"
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/mps-tests.yml"
pull_request:
paths:
- "ignite/**"
- "tests/ignite/**"
- "tests/run_code_style.sh"
- "examples/**.py"
- "requirements-dev.txt"
- ".github/workflows/mps-tests.yml"
workflow_dispatch:

concurrency:
# <workflow_name>-<branch_name>-<true || commit_sha (if branch is protected)>
group: mps-tests-${{ github.ref_name }}-${{ !(github.ref_protected) || github.sha }}
cancel-in-progress: true

# Cherry-picked from
# - https://github.com/pytorch/vision/blob/main/.github/workflows/tests.yml
# - https://github.com/pytorch/test-infra/blob/main/.github/workflows/macos_job.yml

jobs:
mps-tests:
strategy:
matrix:
python-version: [3.8]
pytorch-channel: ["pytorch"]
skip-distrib-tests: [1]
fail-fast: false
runs-on: ["macos-m1-12"]
timeout-minutes: 60

steps:
- name: Clean workspace
run: |
echo "::group::Cleanup debug output"
sudo rm -rfv "${GITHUB_WORKSPACE}"
mkdir -p "${GITHUB_WORKSPACE}"
echo "::endgroup::"
- name: Checkout repository (pytorch/test-infra)
uses: actions/checkout@v3
with:
# Support the use case where we need to checkout someone's fork
repository: pytorch/test-infra
path: test-infra

- name: Checkout repository (${{ github.repository }})
uses: actions/checkout@v3
with:
# Support the use case where we need to checkout someone's fork
repository: ${{ github.repository }}
ref: ${{ github.ref }}
path: ${{ github.repository }}
fetch-depth: 1

- name: Setup miniconda
uses: ./test-infra/.github/actions/setup-miniconda
with:
python-version: ${{ matrix.python-version }}

- name: Install PyTorch
if: ${{ matrix.pytorch-channel == 'pytorch' }}
shell: bash -l {0}
run: |
conda shell.bash hook
conda activate $CONDA_ENV
pip install torch torchvision
- name: Install PyTorch (nightly)
if: ${{ matrix.pytorch-channel == 'pytorch-nightly' }}
shell: bash -l {0}
run: |
conda shell.bash hook
conda activate $CONDA_ENV
pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu
- name: Install dependencies
shell: bash -l {0}
working-directory: ${{ github.repository }}
run: |
conda activate $CONDA_ENV
# TODO: We add set -xe to explicitly fail the CI if one of the commands is failing.
# Somehow the step is passing even if a subcommand failed
set -xe
pip install -r requirements-dev.txt
echo "1 returned code: $?"
pip install -e .
echo "2 returned code: $?"
pip list
echo "3 returned code: $?"
# Download MNIST: https://github.com/pytorch/ignite/issues/1737
# to "/tmp" for unit tests
- name: Download MNIST
uses: pytorch-ignite/download-mnist-github-action@master
with:
target_dir: /tmp

# Copy MNIST to "." for the examples
- name: Copy MNIST
run: |
cp -R /tmp/MNIST .
- name: Run Tests
shell: bash -l {0}
working-directory: ${{ github.repository }}
run: |
conda activate $CONDA_ENV
SKIP_DISTRIB_TESTS=${{ matrix.skip-distrib-tests }} bash tests/run_cpu_tests.sh
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ${{ github.repository }}/coverage.xml
flags: mps
fail_ci_if_error: false

- name: Run MNIST Examples
shell: bash -l {0}
working-directory: ${{ github.repository }}
run: |
conda activate $CONDA_ENV
python examples/mnist/mnist.py --epochs=1
16 changes: 4 additions & 12 deletions .github/workflows/stable-release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@ jobs:
run: |
conda install -y pytorch torchvision cpuonly -c pytorch
pip install -r requirements-dev.txt
pip install --upgrade --no-cache-dir twine
python setup.py install
- name: Build and Publish PyPI binaries
shell: bash -l {0}
run: |
# workaround to fix https://github.com/pytorch/ignite/issues/2373
pip uninstall -y twine pkginfo
pip install --upgrade --no-cache-dir twine 'pkginfo>=1.8.2'
python setup.py sdist bdist_wheel
twine --version
twine check dist/*
TWINE_USERNAME="${{ secrets.PYPI_USER }}" TWINE_PASSWORD="${{ secrets.PYPI_TOKEN }}" twine upload --verbose dist/*
# docker-build-publish:
# name: Trigger Build and Push Docker images to Docker Hub
# needs: build-publish
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-python@v4
# with:
# python-version: "3.10"
1 change: 1 addition & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ jobs:
run: |
pip install -r requirements-dev.txt
python setup.py install
pip list
- name: Check code formatting
run: |
Expand Down
2 changes: 1 addition & 1 deletion docker/push_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ echo $DOCKER_TOKEN | docker login --username=$DOCKER_USER --password-stdin
set -xeu


if [ ${folder_name} == "all" ]; then
if [ ${push_selected_image} == "all" ]; then

image_name="base"
image_tag=`docker run --rm -i pytorchignite/${image_name}:latest python -c "import torch; import ignite; print(torch.__version__ + \"-\" + ignite.__version__, end=\"\")"`
Expand Down
4 changes: 3 additions & 1 deletion docker/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def check_package(package_name, expected_version=None):
if expected_version is not None:
assert hasattr(mod, "__version__"), f"Imported package {package_name} does not have __version__ attribute"
version = mod.__version__
assert version == expected_version, f"Version mismatch for package {package_name}: got {version} but expected {expected_version}"
assert (
version == expected_version
), f"Version mismatch for package {package_name}: got {version} but expected {expected_version}"


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/super_resolution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ported from [pytorch-examples](https://github.com/pytorch/examples/tree/main/super_resolution)

This example illustrates how to use the efficient sub-pixel convolution layer described in ["Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network" - Shi et al.](https://arxiv.org/abs/1609.05158) for increasing spatial resolution within your network for tasks such as superresolution.
This example illustrates how to use the efficient sub-pixel convolution layer described in ["Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network" - Shi et al. 2016](https://arxiv.org/abs/1609.05158) for increasing spatial resolution within your network for tasks such as superresolution.

```
usage: main.py [-h] --upscale_factor UPSCALE_FACTOR [--crop_size CROPSIZE] [--batch_size BATCHSIZE]
Expand Down
4 changes: 1 addition & 3 deletions ignite/contrib/engines/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ def _setup_common_training_handlers(

if lr_scheduler is not None:
if isinstance(lr_scheduler, PyTorchLRScheduler):
trainer.add_event_handler(
Events.ITERATION_COMPLETED, lambda engine: cast(PyTorchLRScheduler, lr_scheduler).step()
)
trainer.add_event_handler(Events.ITERATION_COMPLETED, lambda engine: lr_scheduler.step())
else:
trainer.add_event_handler(Events.ITERATION_STARTED, lr_scheduler)

Expand Down
5 changes: 4 additions & 1 deletion ignite/distributed/comp_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from typing import Any, Callable, cast, List, Optional, Union

import torch
from packaging.version import Version

_torch_version_le_112 = Version(torch.__version__) > Version("1.12.0")


class ComputationModel(metaclass=ABCMeta):
Expand Down Expand Up @@ -326,7 +329,7 @@ def get_node_rank(self) -> int:
def device(self) -> torch.device:
if torch.cuda.is_available():
return torch.device("cuda")
if torch.backends.mps.is_available():
if _torch_version_le_112 and torch.backends.mps.is_available():
return torch.device("mps")
return torch.device("cpu")

Expand Down
19 changes: 15 additions & 4 deletions ignite/engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def supervised_training_step(
Added `model_transform` to transform model's output
.. versionchanged:: 0.4.13
Added `model_fn` to customize model's application on the sample
.. versionchanged:: 0.4.14
Added support for ``mps`` device
"""

if gradient_accumulation_steps <= 0:
Expand Down Expand Up @@ -391,9 +393,12 @@ def update(engine: Engine, batch: Sequence[torch.Tensor]) -> Union[Any, Tuple[to


def _check_arg(
on_tpu: bool, amp_mode: Optional[str], scaler: Optional[Union[bool, "torch.cuda.amp.GradScaler"]]
on_tpu: bool, on_mps: bool, amp_mode: Optional[str], scaler: Optional[Union[bool, "torch.cuda.amp.GradScaler"]]
) -> Tuple[Optional[str], Optional["torch.cuda.amp.GradScaler"]]:
"""Checking tpu, amp and GradScaler instance combinations."""
"""Checking tpu, mps, amp and GradScaler instance combinations."""
if on_mps and amp_mode:
raise ValueError("amp_mode cannot be used with mps device. Consider using amp_mode=None or device='cuda'.")

if on_tpu and not idist.has_xla_support:
raise RuntimeError("In order to run on TPU, please install PyTorch XLA")

Expand Down Expand Up @@ -546,11 +551,14 @@ def output_transform_fn(x, y, y_pred, loss):
Added ``model_transform`` to transform model's output
.. versionchanged:: 0.4.13
Added `model_fn` to customize model's application on the sample
.. versionchanged:: 0.4.14
Added support for ``mps`` device
"""

device_type = device.type if isinstance(device, torch.device) else device
on_tpu = "xla" in device_type if device_type is not None else False
mode, _scaler = _check_arg(on_tpu, amp_mode, scaler)
on_mps = "mps" in device_type if device_type is not None else False
mode, _scaler = _check_arg(on_tpu, on_mps, amp_mode, scaler)

if mode == "amp":
_update = supervised_training_step_amp(
Expand Down Expand Up @@ -791,10 +799,13 @@ def create_supervised_evaluator(
Added ``model_transform`` to transform model's output
.. versionchanged:: 0.4.13
Added `model_fn` to customize model's application on the sample
.. versionchanged:: 0.4.14
Added support for ``mps`` device
"""
device_type = device.type if isinstance(device, torch.device) else device
on_tpu = "xla" in device_type if device_type is not None else False
mode, _ = _check_arg(on_tpu, amp_mode, None)
on_mps = "mps" in device_type if device_type is not None else False
mode, _ = _check_arg(on_tpu, on_mps, amp_mode, None)

metrics = metrics or {}
if mode == "amp":
Expand Down
Loading

0 comments on commit eb89948

Please sign in to comment.