Skip to content

Commit

Permalink
Migrate tests to pytest + add GA (#127)
Browse files Browse the repository at this point in the history
Co-authored-by: Eitan Turok <[email protected]>
  • Loading branch information
eitanturok and eitanturok authored Jul 31, 2024
1 parent 790d046 commit 1ae7703
Show file tree
Hide file tree
Showing 34 changed files with 1,640 additions and 1,171 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/pr-gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PR GPU tests
on:
push:
branches:
- main
- release/*
pull_request_target:
branches:
- main
- release/**
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main'}}
jobs:
pytest-gpu:
name: ${{ matrix.name }}
runs-on: linux-ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: "python3.11-pytorch2.3.1-gpus1"
gpu_num: 1
python_version: 3.11
container: mosaicml/pytorch:2.3.1_cu121-python3.11-ubuntu20.04
- name: "python3.11-pytorch2.3.1-gpus2"
gpu_num: 2
python_version: 3.11
container: mosaicml/pytorch:2.3.1_cu121-python3.11-ubuntu20.04
steps:
- name: Run PR GPU tests
uses: mosaicml/ci-testing/.github/actions/[email protected]
with:
name: ${{ matrix.name }}
container: ${{ matrix.container }}
python_version: ${{ matrix.python_version }}
gpu_num: ${{ matrix.gpu_num }}
git_repo: databricks/megablocks
pip_deps: "[all,testing]"
pytest_command: "coverage run -m pytest tests" # todo: remove tests from pytest tests when we delete all tests outside of MegaBlocks repo
pytest_markers: "gpu"
composer_package_name: mosaicml # Required as Composer is built from source
mcloud_timeout: 3600
mcloud_api_key: ${{ secrets.MCLOUD_API_KEY }}
173 changes: 165 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,165 @@
*~
gpt2-merges.txt
gpt2-vocab.json
core
__pycache__
*.egg-info
dist
build
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
docs/path/
docs/source/_build/
docs/source/api_reference/
# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Virtual Env
venv/

# WandB
wandb/

# Neptune
.neptune/

# Spacemacs
._#*
.#*
.vscode/

# Vim
*.swp

# README backups
README.md.bkp

# OS X
.DS_Store

# Sphinx
api_reference/

# Node (for pyright)
node_modules/
package.json
package-lock.json

# pycharm
.idea/
28 changes: 20 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
clean:
rm -rf dist/*
# several pytest settings
WORLD_SIZE ?= 1 # world size for launcher tests
MASTER_PORT ?= 26000 # port for distributed tests
PYTHON ?= python3 # Python command
PYTEST ?= pytest # Pytest command
PYRIGHT ?= pyright # Pyright command. Pyright must be installed seperately -- e.g. `node install -g pyright`
EXTRA_ARGS ?= # extra arguments for pytest
EXTRA_LAUNCHER_ARGS ?= # extra arguments for the composer cli launcher

dist: clean
python3 setup.py sdist
test:
LOCAL_WORLD_SIZE=1 $(PYTHON) -m $(PYTEST) $(EXTRA_ARGS)

upload: dist
twine upload dist/*
test-gpu:
LOCAL_WORLD_SIZE=1 $(PYTHON) -m $(PYTEST) -m gpu $(EXTRA_ARGS)

upload-test: dist
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
# runs tests with the launcher
test-dist:
$(PYTHON) -m composer.cli.launcher -n $(WORLD_SIZE) --master_port $(MASTER_PORT) $(EXTRA_LAUNCHER_ARGS) -m $(PYTEST) $(EXTRA_ARGS)

test-dist-gpu:
$(PYTHON) -m composer.cli.launcher -n $(WORLD_SIZE) --master_port $(MASTER_PORT) $(EXTRA_LAUNCHER_ARGS) -m $(PYTEST) -m gpu $(EXTRA_ARGS)

.PHONY: test test-gpu test-dist test-dist-gpu
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ NOTE: This assumes you have `numpy` and `torch` installed.

Installing `megablocks[gg]` enables dMoE computation with grouped GEMM. This feature is enabled by setting the `mlp_impl` argument to `grouped`. This is currently our recommended path for Hopper-generation GPUs.

Installing `megablocks[dev]` allows you to contribute to MegaBlocks and test locally. Installing `megablocks[testing]` allows you to test via Github Actions.

MegaBlocks can be installed with all dependencies via the `megablocks[all]` package.

# :steam_locomotive: Usage
Expand Down
Loading

0 comments on commit 1ae7703

Please sign in to comment.