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

Functorch nvfuser revisions #363

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9474fc3
added nvfuser implementation, benchmark for biasReluDropout
Jul 7, 2022
5ea028e
reformatted fuse pattern
Jul 8, 2022
8453069
revised benchamrking, nvfused patterns
Jul 11, 2022
fdd6b16
adds BiasDropoutRes and BiasDropoutResLayernorm patterns, minor edits
Jul 13, 2022
291f439
unit testing for all fused patterns, minor edits
Jul 19, 2022
5004562
benchmarking for all nvfused patterns
Jul 19, 2022
ea85ea4
mypy wip
Jul 19, 2022
568c09a
benchmarking nvfuser patterns, adding plots, minor testing changes
Jul 22, 2022
7c7f6de
fixing mypy errors
Jul 25, 2022
8c59bb9
fixed benchmarking bug, minor test change
Jul 25, 2022
fd82a43
final benchmark plots, benchmmark edits
Jul 25, 2022
bd4499a
nvfuser documentation, minor edits
Jul 26, 2022
b004d87
fixing functorch version error, documentation revisions
Jul 26, 2022
14cc332
Merge branch 'main' into op_fusion_functorch
yuanandonly Jul 26, 2022
9ea013a
fixing circleci functorch errors, mypy errors
Jul 26, 2022
c774755
circleci config wip
Jul 27, 2022
4f18220
circleci test wip
Jul 27, 2022
d5e0765
wip2
Jul 27, 2022
477c208
testing revisions, circleci fixes, minor changes
Jul 27, 2022
7d9d659
changelog changes, fixes functorch flag bug
Jul 27, 2022
339a556
circle-ci fix
Jul 27, 2022
5d8221d
circle-ci spacing fix
Jul 27, 2022
d9199f0
build error wip
Jul 27, 2022
bcf746e
revised documentation, reverted circleci config
Jul 27, 2022
bd5b799
Fix functorch errors, circleci issue, testing changes
yuanandonly Jul 27, 2022
a6f3221
updating changelog
yuanandonly Jul 28, 2022
33431d0
added mlp plots, mlp functionality to switch weights to nvfused mlp
yuanandonly Aug 11, 2022
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
Prev Previous commit
Next Next commit
testing revisions, circleci fixes, minor changes
  • Loading branch information
Chris Yuan committed Jul 27, 2022
commit 477c2083f472096d1380df68228116880f549edc
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ jobs:


gpu_tests:
<<: *gpu_cu102
<<: *gpu_cu114

working_directory: ~/xformers

Expand All @@ -324,7 +324,7 @@ jobs:
# Cache the venv directory that contains dependencies
- restore_cache:
keys:
- cache-key-gpu-102-{{ checksum "requirements-test.txt" }}-{{ checksum ".circleci/config.yml" }}
- cache-key-gpu-114-{{ checksum "requirements-test.txt" }}-{{ checksum ".circleci/config.yml" }}

- <<: *setup_conda
- <<: *install_dep
Expand All @@ -338,7 +338,7 @@ jobs:
- ~/miniconda
- ~/venv

key: cache-key-gpu-102-{{ checksum "requirements-test.txt"}}-{{ checksum ".circleci/config.yml"}}
key: cache-key-gpu-114-{{ checksum "requirements-test.txt"}}-{{ checksum ".circleci/config.yml"}}

- <<: *install_repo

Expand All @@ -354,7 +354,7 @@ jobs:
path: test-results

gpu_experimental_tests:
<<: *gpu_cu102
<<: *gpu_cu114

working_directory: ~/xformers

Expand All @@ -366,7 +366,7 @@ jobs:
# Cache the venv directory that contains dependencies
- restore_cache:
keys:
- cache-key-gpu-exp-102-{{ checksum "experimental/requirements.txt" }}-{{ checksum ".circleci/config.yml" }}
- cache-key-gpu-exp-114-{{ checksum "experimental/requirements.txt" }}-{{ checksum ".circleci/config.yml" }}

- <<: *setup_conda
- <<: *install_dep_exp
Expand All @@ -381,7 +381,7 @@ jobs:
- ~/miniconda
- ~/venv

key: cache-key-gpu-exp-102-{{ checksum "experimental/requirements.txt"}}-{{ checksum ".circleci/config.yml"}}
key: cache-key-gpu-exp-114-{{ checksum "experimental/requirements.txt"}}-{{ checksum ".circleci/config.yml"}}

- <<: *install_experimental_repo
- <<: *run_experimental_unittests
Expand Down
3 changes: 2 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ fairscale >= 0.4.5
triton == 2.0.0.dev20220701

# Functorch: Dependency for fused layers, optional
git+https://github.com/pytorch/functorch@v0.2.0
# git+https://github.com/pytorch/functorch@v0.2.0
git+https://github.com/pytorch/functorch.git
22 changes: 18 additions & 4 deletions tests/test_nvfuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@


import logging
from collections import OrderedDict
from contextlib import nullcontext

import pytest
Expand All @@ -13,13 +14,14 @@
from torch.cuda.amp.autocast_mode import autocast

import xformers
from xformers.components import Activation, ResidualNormStyle
from xformers.components.feedforward import build_feedforward

_gpu_available = torch.cuda.is_available()

xformers._is_functorch_available = True

from xformers.components import Activation, ResidualNormStyle # noqa : E402
from xformers.components.feedforward import build_feedforward # noqa : E402

_gpu_available = torch.cuda.is_available()

try:
from xformers.components.nvfuser import (
NVFusedBiasActivationDropout,
Expand Down Expand Up @@ -172,5 +174,17 @@ def test_nvfused_mlp(activation: Activation, device: torch.device, p: float):
# Check fused pattern w/ unfused default (switch happens within MLP)
mlp.cuda()
mlp_default.cuda()

# Load same weight parameters into both models
default_param_dict = OrderedDict(
[
("mlp.2.weight", v) if k == "mlp.3.weight" else (k, v)
for k, v in mlp_default.state_dict().items()
]
)
mlp.load_state_dict(default_param_dict)
fused_res = mlp(inputs)
unfused_res = mlp_default(inputs)

if p == 0.0:
assert torch.allclose(unfused_res, fused_res, atol=1e-6, rtol=1e-2)
1 change: 0 additions & 1 deletion xformers/components/nvfuser/bias_dropout_res.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def forward(self, x: torch.Tensor, residual: torch.Tensor) -> torch.Tensor:

# Catch a non-cuda setup, fallback to pytorch
if not x.is_cuda:
print("defaulting")
return _fn(x, self.bias, p, residual)

# AOTAutograd, NVFuser backed path
Expand Down