Skip to content

Commit

Permalink
[enhancement] Speed up build and docs by removing tensorboard dep (fa…
Browse files Browse the repository at this point in the history
…cebookresearch#254)

Summary:
- Tensorboard has been slowing down our building time by huge factor due
to grpcio build times
- Expose version in the mmf's __init__.py
- Now, the warning will only be thrown in case if user tries to use
Tensorboard
Pull Request resolved: facebookresearch#254

Test Plan: Tested on CircleCI as well as RTD

Reviewed By: vedanuj

Differential Revision: D21599427

Pulled By: apsdehal

fbshipit-source-id: f7cd2e745f44b9123035ae67ef07e26d19f2c438
  • Loading branch information
apsdehal authored and facebook-github-bot committed May 16, 2020
1 parent d9d1d9a commit 93cd2a7
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 65 deletions.
121 changes: 60 additions & 61 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Python CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-python/ for more details
#
# Adopted from
# https://github.com/facebookresearch/detectron2/blob/master/.circleci/config.yml

# Use 2.1 for orbs
version: 2.1

# Include windows orb for windows bui
orbs:
win: circleci/[email protected]

# -------------------------------------------------------------------------------------
# Environments to run the jobs in
# -------------------------------------------------------------------------------------
Expand All @@ -26,23 +23,13 @@ gpu: &gpu
# -------------------------------------------------------------------------------------
# Re-usable commands
# -------------------------------------------------------------------------------------
setup_venv: &setup_venv
- run:
name: Setup Virtual Env
working_directory: ~/
command: |
python -m venv ~/venv
echo ". ~/venv/bin/activate" >> $BASH_ENV
. ~/venv/bin/activate
python --version
which python
which pip
pip install --upgrade pip
cache_key: &cache_key cache-key-{{ .Environment.CIRCLE_JOB }}-{{ checksum ".circleci/config.yml" }}-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}

install_dep: &install_dep
- run:
name: Install Dependencies
command: |
source activate mmf
pip install --upgrade setuptools
pip install --progress-bar off flake8
pip install --progress-bar off black
Expand Down Expand Up @@ -72,6 +59,7 @@ install_repo: &install_repo
- run:
name: Install Repository
command: |
source activate mmf
python setup.py build develop
install_repo_windows: &install_repo_windows
Expand All @@ -85,13 +73,15 @@ run_unittests: &run_unittests
- run:
name: Run Unit Tests
command: |
source activate mmf
cd tests
pytest --junitxml=test-results/junit.xml -v .
run_flake8: &run_flake8
- run:
name: Run Linter (flake8)
command: |
source activate mmf
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
# exit-zero treats all errors as warnings
Expand All @@ -106,9 +96,29 @@ install_nvidia_driver: &install_nvidia_driver
sudo /bin/bash ~/nvidia-downloads/NVIDIA-Linux-x86_64-430.40.run -s --no-drm
pyenv versions
nvidia-smi
pyenv global 3.7.0
pyenv global 3.6.5
create_conda_env: &create_conda_env
- run:
name: Install and Create Conda Environment
command: |
curl -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x ~/miniconda.sh
~/miniconda.sh -b -p $HOME/miniconda
rm ~/miniconda.sh
echo 'export PATH=$HOME/miniconda/bin:$PATH' >> $BASH_ENV
source $BASH_ENV
if [ ! -d ~/miniconda/envs/mmf ]
then
conda create -y -n mmf python=3.6
fi
source activate mmf
python --version
which python
which pip
pip install --upgrade pip
create_conda_env_windows: &create_conda_env_windows
- run:
name: Create Conda Environment
command: |
Expand All @@ -121,6 +131,20 @@ create_conda_env: &create_conda_env
which pip
pip install --user --upgrade pip
run_black: &run_black
- run:
name: Run Linter (black)
command: |
source activate mmf
black --check .
run_isort: &run_isort
- run:
name: Run Linter (isort)
command: |
source activate mmf
isort -c -sp .
# -------------------------------------------------------------------------------------
# Jobs to run
# -------------------------------------------------------------------------------------
Expand All @@ -133,13 +157,13 @@ jobs:

steps:
- checkout
- <<: *create_conda_env
- <<: *create_conda_env_windows
- restore_cache:
key: cache-key-windows-cpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}
key: *cache_key
- <<: *install_dep_windows
- <<: *install_repo_windows
- save_cache:
key: cache-key-windows-cpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}
key: *cache_key
paths:
- C:\tools\miniconda3\envs\mmf

Expand All @@ -150,39 +174,24 @@ jobs:

steps:
- checkout
- <<: *setup_venv

# Cache the venv directory that contains dependencies
- <<: *create_conda_env
- restore_cache:
keys:
- cache-key-cpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}

key: *cache_key
- <<: *install_dep

# Cache the miniconda directory that contains dependencies
- save_cache:
paths:
- ~/venv
key: cache-key-cpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}

- ~/miniconda/
key: *cache_key
- <<: *install_repo

- run:
name: Run Linter (isort)
command: |
isort -c -sp .
- run:
name: Run Linter (black)
command: |
black --check -l 88 .
- <<: *run_isort
- <<: *run_black
- <<: *run_flake8

- <<: *run_unittests

- store_test_results:
path: tests/test-results

# GPU config initially taken from detectron2
gpu_tests:
<<: *gpu

Expand All @@ -194,32 +203,22 @@ jobs:
# Cache the nvidia driver downloads
- restore_cache:
key: nvidia-downloads-v4

- <<: *install_nvidia_driver

- save_cache:
key: nvidia-downloads-v4
paths:
- "~/nvidia-downloads/"

- <<: *setup_venv

# Cache the venv directory that contains dependencies
- <<: *create_conda_env
- restore_cache:
keys:
- cache-key-gpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}

key: *cache_key
- <<: *install_dep

# Cache the miniconda directory that contains dependencies
- save_cache:
paths:
- ~/venv
key: cache-key-gpu-{{ checksum "setup.py"}}-{{ checksum "requirements.txt"}}

- ~/miniconda/
key: *cache_key
- <<: *install_repo

- <<: *run_unittests

- store_test_results:
path: tests/test-results

Expand Down
3 changes: 3 additions & 0 deletions mmf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) Facebook, Inc. and its affiliates.
# isort:skip_file
# flake8: noqa: F401

import mmf.utils
import mmf.common
Expand All @@ -10,3 +11,5 @@
import mmf.modules.metrics
import mmf.datasets
import mmf.models

from mmf.version import __version__
5 changes: 3 additions & 2 deletions mmf/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
import sys

from torch.utils.tensorboard import SummaryWriter

from mmf.utils.configuration import get_mmf_env
from mmf.utils.distributed import is_master
from mmf.utils.file_io import PathManager
Expand Down Expand Up @@ -131,6 +129,9 @@ def single_write(self, x, level="info", log_all=False):

class TensorboardLogger:
def __init__(self, log_folder="./logs", iteration=0):
# This would handle warning of missing tensorboard
from torch.utils.tensorboard import SummaryWriter

self.summary_writer = None
self._is_master = is_master()
self.timer = Timer()
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
torch==1.4.0
torchvision==0.5.0
tensorboard==2.1.0
numpy==1.16.6
tqdm==4.43.0
demjson==2.2.4
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ def fetch_requirements():

with open(requirements_file) as f:
reqs = f.read()

reqs = reqs.strip().split("\n")
reqs = remove_specific_requirements(reqs)
return reqs


def remove_specific_requirements(reqs):
excluded = {"fasttext": "READTHEDOCS" in os.environ}
rtd = "READTHEDOCS" in os.environ
excluded = {"fasttext": rtd}
updated_reqs = []
for req in reqs:
without_version = req.split("==")[0]
Expand Down

0 comments on commit 93cd2a7

Please sign in to comment.