diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 334536a1d1..0000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,283 +0,0 @@ -version: 2.1 - -commands: - - pip_install: - description: "Install dependencies via pip" - parameters: - args: - type: string - default: "" - steps: - - run: - name: "Install dependencies via pip" - command: ./scripts/install_via_pip.sh << parameters.args >> - - conda_install: - description: "Install dependencies via conda" - parameters: - args: - type: string - default: "" - steps: - - run: - name: "Install dependencies via conda" - command: ./scripts/install_via_conda.sh << parameters.args >> - - lint_flake8: - description: "Lint with flake8" - steps: - - run: - name: "Lint with flake8" - command: flake8 - - ufmt_check: - description: "Check formatting with ufmt" - steps: - - run: - name: "Check formatting with ufmt" - command: ufmt check . - - mypy_check: - description: "Static type checking with mypy" - steps: - - run: - name: "Mypy checks" - command: ./scripts/run_mypy.sh - - unit_tests: - description: "Run unit tests" - steps: - - run: - name: "Run unit tests" - command: python -m pytest -ra --cov=. --cov-report term-missing - - sphinx: - description: "Run sphinx" - steps: - - run: - name: "Run sphinx" - command: sphinx-build -WT --keep-going sphinx/source sphinx/build - - configure_github_bot: - description: "Configure Docusaurus GitHub bot" - steps: - - run: - name: "Configure Docusaurus GitHub bot" - # Do not do this if we don't have the right org (pytorch), or if this is just a PR - command: | - if [[ $CIRCLE_PROJECT_USERNAME == "pytorch" && -z $CI_PULL_REQUEST && -z $CIRCLE_PR_USERNAME ]]; then - git config --global user.email "docusaurus-bot@users.noreply.github.com" - git config --global user.name "Captum website deployment script" - echo "machine github.com login docusaurus-bot password $DOCUSAURUS_GITHUB_TOKEN" > ~/.netrc - fi - - deploy_site: - description: "Deploy website to GitHub Pages" - steps: - - run: - name: "Deploy website to GitHub Pages" - # TODO: make the installation above conditional on there being relevant changes (no need to install if there are none) - command: | - if ! git diff --name-only HEAD^ | grep -E "(^captum\/.*)|(^\.circleci\/.*)|(^docs\/.*)|(^website\/.*)|(^scripts\/.*)|(^sphinx\/.*)|(^tutorials\/.*)"; then - echo "Skipping deploy. No relevant website files have changed" - elif [[ $CIRCLE_PROJECT_USERNAME == "pytorch" && -z $CI_PULL_REQUEST && -z $CIRCLE_PR_USERNAME ]]; then - mkdir -p website/static/.circleci && cp -a .circleci/. website/static/.circleci/. - ./scripts/build_docs.sh -b - cd website - GIT_USER=docusaurus-bot yarn run publish-gh-pages - else - echo "Skipping deploy." - fi - - simple_pip_install: - description: "Simple install of Captum via pip. Does not include extra dependencies such as yarn and nodejs needed for building insights." - steps: - - run: - name: "Simple PIP install" - command: | - python -m pip install --upgrade pip - python -m pip install -e .[dev] - - build_package: - description: "Build the source and wheel packages" - steps: - - run: - name: "Build captum" - command: | - python -m pip install build - python -m build - - py_3_7_setup: - description: "Set python version to 3.7 and install pip and pytest" - steps: - - run: - name: "Switch to Python v3.7" - command: | - pyenv versions - pyenv install 3.7.0 - pyenv global 3.7.0 - - install_cuda: - description: "Install CUDA for GPU Machine" - steps: - - run: - name: "Install CUDA" - command: | - sudo dpkg --configure -a - wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin - sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 - wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda-repo-ubuntu2004-11-4-local_11.4.2-470.57.02-1_amd64.deb - sudo dpkg -i cuda-repo-ubuntu2004-11-4-local_11.4.2-470.57.02-1_amd64.deb - sudo apt-key add /var/cuda-repo-ubuntu2004-11-4-local/7fa2af80.pub - sudo apt-get update - sudo apt-get --yes --force-yes install cuda - -jobs: - - lint_py36: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install - - ufmt_check - - lint_flake8 - - sphinx - - test_py36_pip: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install: - args: "-n" - - mypy_check - - unit_tests - - test_py36_pip_release: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install - - mypy_check - - unit_tests - - test_py36_pip_torch_1_6: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install: - args: "-v 1.6" - - unit_tests - - test_py36_pip_torch_1_7: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install: - args: "-v 1.7" - - unit_tests - - test_py36_pip_torch_1_8: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install: - args: "-v 1.8" - - unit_tests - - test_py36_pip_torch_1_9: - docker: - - image: cimg/python:3.6 - steps: - - checkout - - pip_install: - args: "-v 1.9" - - unit_tests - - - test_py37_conda: - docker: - - image: continuumio/miniconda3 - steps: - - checkout - - conda_install: - args: "-n" - - unit_tests - - - test_cuda_multi_gpu: - machine: - image: ubuntu-2004:202201-02 - resource_class: gpu.nvidia.medium.multi - steps: - - checkout - - install_cuda - - py_3_7_setup - - simple_pip_install - - build_package - - unit_tests - - auto_deploy_site: - docker: - - image: cimg/python:3.6-node - steps: - - checkout - - pip_install: - args: "-n -d" - - configure_github_bot - - deploy_site - - -aliases: - - - &exclude_ghpages_fbconfig - branches: - ignore: - - gh-pages - - fb-config - - -workflows: - - lint_test_and_deploy_site: - jobs: - - lint_py36: - filters: *exclude_ghpages_fbconfig - - test_py36_pip: - filters: *exclude_ghpages_fbconfig - - test_py36_pip_release: - filters: *exclude_ghpages_fbconfig - - test_py37_conda: - filters: *exclude_ghpages_fbconfig - - test_py36_pip_torch_1_6: - filters: *exclude_ghpages_fbconfig - - test_py36_pip_torch_1_7: - filters: *exclude_ghpages_fbconfig - - test_py36_pip_torch_1_8: - filters: *exclude_ghpages_fbconfig - - test_py36_pip_torch_1_9: - filters: *exclude_ghpages_fbconfig - - test_cuda_multi_gpu: - filters: *exclude_ghpages_fbconfig - - - auto_deploy_site: - requires: - - lint_py36 - - test_py36_pip - - test_py36_pip_release - - test_py37_conda - - test_py36_pip_torch_1_6 - - test_py36_pip_torch_1_7 - - test_py36_pip_torch_1_8 - - test_py36_pip_torch_1_9 - - test_cuda_multi_gpu - filters: - branches: - only: - - master diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..0aa7c68b4c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,23 @@ +name: Captum Lint + +on: + pull_request: + push: + branches: + - master + + workflow_dispatch: + +jobs: + tests: + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main + with: + runner: linux.12xlarge + docker-image: cimg/python:3.6 + repository: pytorch/captum + script: | + sudo chmod -R 777 . + ./scripts/install_via_pip.sh + ufmt check . + flake8 + sphinx-build -WT --keep-going sphinx/source sphinx/build diff --git a/.github/workflows/test-conda-cpu.yml b/.github/workflows/test-conda-cpu.yml new file mode 100644 index 0000000000..9ae71846d1 --- /dev/null +++ b/.github/workflows/test-conda-cpu.yml @@ -0,0 +1,34 @@ +name: Unit-tests for Conda install + +on: + pull_request: + push: + branches: + - master + + workflow_dispatch: + +env: + CHANNEL: "nightly" + +jobs: + tests: + strategy: + matrix: + python_version: ["3.7", "3.8", "3.9", "3.10"] + fail-fast: false + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main + with: + runner: linux.12xlarge + repository: pytorch/captum + script: | + # Set up Environment Variables + export PYTHON_VERSION="${{ matrix.python_version }}" + + # Create Conda Env + conda create -yp ci_env python="${PYTHON_VERSION}" + conda activate /pytorch/captum/ci_env + ./scripts/install_via_conda.sh -n + + # Run Tests + python3 -m pytest -ra --cov=. --cov-report term-missing diff --git a/.github/workflows/test-pip-cpu-with-mypy.yml b/.github/workflows/test-pip-cpu-with-mypy.yml new file mode 100644 index 0000000000..4a721cb85b --- /dev/null +++ b/.github/workflows/test-pip-cpu-with-mypy.yml @@ -0,0 +1,27 @@ +name: Unit-tests for Pip install with mypy type checks + +on: + pull_request: + push: + branches: + - master + + workflow_dispatch: + +jobs: + tests: + strategy: + matrix: + pytorch_args: ["", "-n"] + fail-fast: false + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main + with: + runner: linux.12xlarge + docker-image: cimg/python:3.6 + repository: pytorch/captum + script: | + sudo chmod -R 777 . + ./scripts/install_via_pip.sh ${{ matrix.pytorch_args }} + ./scripts/run_mypy.sh + # Run Tests + python3 -m pytest -ra --cov=. --cov-report term-missing diff --git a/.github/workflows/test-pip-cpu.yml b/.github/workflows/test-pip-cpu.yml new file mode 100644 index 0000000000..b1e6028226 --- /dev/null +++ b/.github/workflows/test-pip-cpu.yml @@ -0,0 +1,26 @@ +name: Unit-tests for Pip install + +on: + pull_request: + push: + branches: + - master + + workflow_dispatch: + +jobs: + tests: + strategy: + matrix: + pytorch_args: ["-v 1.6", "-v 1.7", " -v 1.8", "-v 1.9"] + fail-fast: false + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main + with: + runner: linux.12xlarge + docker-image: cimg/python:3.6 + repository: pytorch/captum + script: | + sudo chmod -R 777 . + ./scripts/install_via_pip.sh ${{ matrix.pytorch_args }} + # Run Tests + python3 -m pytest -ra --cov=. --cov-report term-missing diff --git a/.github/workflows/test-pip-gpu.yml b/.github/workflows/test-pip-gpu.yml new file mode 100644 index 0000000000..117f515f48 --- /dev/null +++ b/.github/workflows/test-pip-gpu.yml @@ -0,0 +1,32 @@ +name: Unit-tests for Pip install + +on: + pull_request: + push: + branches: + - master + + workflow_dispatch: + +jobs: + tests: + strategy: + matrix: + cuda_arch_version: ["12.1"] + fail-fast: false + uses: pytorch/test-infra/.github/workflows/linux_job.yml@main + with: + runner: linux.4xlarge.nvidia.gpu + repository: pytorch/captum + gpu-arch-type: cuda + gpu-arch-version: ${{ matrix.cuda_arch_version }} + script: | + python3 -m pip install --upgrade pip --progress-bar off + python3 -m pip install -e .[dev] --progress-bar off + + # Build package + python3 -m pip install build --progress-bar off + python3 -m build + + # Run Tests + python3 -m pytest -ra --cov=. --cov-report term-missing diff --git a/.github/workflows/test-website-depoy.yml b/.github/workflows/test-website-depoy.yml new file mode 100644 index 0000000000..9bb9e26ded --- /dev/null +++ b/.github/workflows/test-website-depoy.yml @@ -0,0 +1,22 @@ +name: Test deployment + +on: + pull_request: + # Review gh actions docs if you want to further define triggers, paths, etc + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on + +jobs: + test-deploy: + name: Test deployment + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup / build docs + run: | + sudo chmod -R 777 . + python3 -m pip install --upgrade pip --progress-bar off + python3 -m pip install -e .[dev] --progress-bar off + python3 -m pip install beautifulsoup4 ipython jinja2==3.0.0 nbconvert==5.6.1 --progress-bar off + ./scripts/build_docs.sh -b + cd website diff --git a/.github/workflows/website-depoy.yml b/.github/workflows/website-depoy.yml new file mode 100644 index 0000000000..960c5a2167 --- /dev/null +++ b/.github/workflows/website-depoy.yml @@ -0,0 +1,38 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: + - master + # Review gh actions docs if you want to further define triggers, paths, etc + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on + +permissions: + contents: write + pages: write + +jobs: + deploy: + name: Deploy to GitHub Pages + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup / build docs + run: | + sudo chmod -R 777 . + python3 -m pip install --upgrade pip --progress-bar off + python3 -m pip install -e .[dev] --progress-bar off + python3 -m pip install beautifulsoup4 ipython jinja2==3.0.0 nbconvert==5.6.1 --progress-bar off + ./scripts/build_docs.sh -b + cd website + + + # Popular action to deploy to GitHub Pages: + # Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + # Build output to publish to the `gh-pages` branch: + publish_dir: ./website/build/captum/ diff --git a/scripts/install_via_conda.sh b/scripts/install_via_conda.sh index 14767c047a..a290fc3299 100755 --- a/scripts/install_via_conda.sh +++ b/scripts/install_via_conda.sh @@ -35,7 +35,7 @@ else fi # install other deps -conda install -q -y pytest ipywidgets ipython scikit-learn parameterized +conda install -q -y pytest ipywidgets ipython scikit-learn parameterized werkzeug==2.2.2 conda install -q -y -c conda-forge matplotlib pytest-cov flask flask-compress # install captum diff --git a/scripts/install_via_pip.sh b/scripts/install_via_pip.sh index 7fb8286fe9..825804fa76 100755 --- a/scripts/install_via_pip.sh +++ b/scripts/install_via_pip.sh @@ -35,30 +35,30 @@ sudo apt install yarn export TERM=xterm # upgrade pip -pip install --upgrade pip +pip install --upgrade pip --progress-bar off # install captum with dev deps -pip install -e .[dev] +pip install -e .[dev] --progress-bar off BUILD_INSIGHTS=1 python setup.py develop # install other frameworks if asked for and make sure this is before pytorch if [[ $FRAMEWORKS == true ]]; then - pip install pytext-nlp + pip install pytext-nlp --progress-bar off fi # install pytorch nightly if asked for if [[ $PYTORCH_NIGHTLY == true ]]; then - pip install --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html + pip install --upgrade --pre torch -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html --progress-bar off else # If no version is specified, upgrade to the latest release. if [[ $CHOSEN_TORCH_VERSION == -1 ]]; then - pip install --upgrade torch + pip install --upgrade torch --progress-bar off else - pip install torch==$CHOSEN_TORCH_VERSION + pip install torch==$CHOSEN_TORCH_VERSION --progress-bar off fi fi # install deployment bits if asked for if [[ $DEPLOY == true ]]; then - pip install beautifulsoup4 ipython nbconvert==5.6.1 + pip install beautifulsoup4 ipython nbconvert==5.6.1 --progress-bar off fi