Skip to content
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

Created YML files to run ofa and added a fix for resize_crop script #63

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,49 @@ horovodrun -np 32 -H <server1_ip>:8,<server2_ip>:8,<server3_ip>:8,<server4_ip>:8
* ImageNet Dataset
* Horovod

## Installation

The first thing to do is install [OpenMPI](http://www.open-mpi.org), see the [OpenMPI installation guide](https://edu.itp.phys.ethz.ch/hs12/programming_techniques/openmpi.pdf).

We need to install NCC as well:

We also may need to set the following environment variables to fit your CUDA environment:

```bash
export CUDA=/usr/local/cuda
export HOROVOD_CUDA_HOME=/usr/local/cuda
export CUDACXX=/usr/local/cuda/bin/nvcc
export CUDA_INCLUDE_DIRS=/usr/local/cuda
export LD_LIBRARY_PATH=$CUDA/lib64:$LD_LIBRARY_PATH
export PATH=$CUDA/bin:$PATH

export HOROVOD_WITH_PYTORCH=1
export HOROVOD_NCCL_INCLUDE=/usr/include
export HOROVOD_GPU=CUDA
export HOROVOD_WITHOUT_TENSORFLOW=1
export HOROVOD_WITHOUT_MXNET=1
export HOROVOD_WITHOUT_GLOO=1
export HOROVOD_GPU_OPERATIONS=NCCL
```

Next, go ahead and run:

```bash
conda env create -f conda-gpu.yml --force
```

This enables Horovod with GPU support.

Next activate the environment:

```bash
conda activate ofa-gpu
pip install .
```

You can now run ofa with GPU support.


## Related work on automated and efficient deep learning:
[ProxylessNAS: Direct Neural Architecture Search on Target Task and Hardware](https://arxiv.org/pdf/1812.00332.pdf) (ICLR’19)

Expand Down
20 changes: 20 additions & 0 deletions conda-cpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: ofa-cpu

channels:
- pytorch
dependencies:
- python==3.7
- pip
- matplotlib
- opencv
- pip:
- numpy
- torch==1.8.1
- torchaudio==0.8.1
- torchvision==0.9.1
- torchsummary
- filelock
- PyYaml
- tqdm
- thop
- -e .
36 changes: 36 additions & 0 deletions conda-gpu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: ofa-gpu

channels:
- pytorch
- conda-forge
- defaults
dependencies:
- python==3.7
- ccache
- cmake
- cudatoolkit=10.1
- cudnn=7.6.5
- cxx-compiler
- gcc_linux-64
- gxx_linux-64
- jupyterlab
- mpi4py # installs cuda-aware openmpi
- nccl
- nvcc_linux-64=10.1
- openmpi
- pip
- matplotlib
- opencv
- pip:
- numpy
- torch==1.8.1
- torchaudio==0.8.1
- torchvision==0.9.1
- torchsummary
- filelock
- PyYaml
- tqdm
- thop
- horovod==0.19.*
- -e .
- --no-binary=horovod
23 changes: 19 additions & 4 deletions ofa/utils/my_dataloader/my_random_resize_crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import torchvision.transforms.functional as F
import torchvision.transforms as transforms
from torchvision.transforms import InterpolationMode

__all__ = ['MyRandomResizedCrop', 'MyResizeRandomCrop', 'MyResize']

Expand Down Expand Up @@ -69,7 +70,11 @@ def sample_image_size(batch_id=None):
MyRandomResizedCrop.ACTIVE_SIZE = random.choices(candidate_sizes, weights=relative_probs)[0]

def __repr__(self):
interpolate_str = _pil_interpolation_to_str[self.interpolation]
if isinstance(self.interpolation, InterpolationMode):
interpolate_str = self.interpolation.value
else:
interpolate_str = _pil_interpolation_to_str[self.interpolation]

format_string = self.__class__.__name__ + '(size={0}'.format(MyRandomResizedCrop.IMAGE_SIZE_LIST)
if MyRandomResizedCrop.CONTINUOUS:
format_string += '@continuous'
Expand Down Expand Up @@ -113,9 +118,14 @@ def __call__(self, img):
return F.crop(img, i, j, h, w)

def __repr__(self):
if isinstance(self.interpolation, InterpolationMode):
interpolate_str = self.interpolation.value
else:
interpolate_str = _pil_interpolation_to_str[self.interpolation]

return 'MyResizeRandomCrop(size=%s%s, interpolation=%s, use_padding=%s, fill=%s)' % (
MyRandomResizedCrop.IMAGE_SIZE_LIST, '@continuous' if MyRandomResizedCrop.CONTINUOUS else '',
_pil_interpolation_to_str[self.interpolation], self.use_padding, self.fill,
interpolate_str, self.use_padding, self.fill,
)


Expand All @@ -130,7 +140,12 @@ def __call__(self, img):
return img

def __repr__(self):
if isinstance(self.interpolation, InterpolationMode):
interpolate_str = self.interpolation.value
else:
interpolate_str = _pil_interpolation_to_str[self.interpolation]

return 'MyResize(size=%s%s, interpolation=%s)' % (
MyRandomResizedCrop.IMAGE_SIZE_LIST, '@continuous' if MyRandomResizedCrop.CONTINUOUS else '',
_pil_interpolation_to_str[self.interpolation]
)
interpolate_str
)