Skip to content

Commit

Permalink
[pytorch] add script to run all codegen (pytorch#46243)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#46243

Add util script to test whether any codegen output changes.

Test Plan: Imported from OSS

Reviewed By: ezyang

Differential Revision: D24388873

Pulled By: ljk53

fbshipit-source-id: ef9ef7fe6067df1e0c53aba725fc13b0dfd7f4c2
  • Loading branch information
ljk53 authored and facebook-github-bot committed Oct 30, 2020
1 parent 707d271 commit d95e1af
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
60 changes: 60 additions & 0 deletions .jenkins/pytorch/codegen-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

# This script can also be used to test whether your diff changes any codegen output.
#
# Run it before and after your change:
# .jenkins/pytorch/codegen-test.sh <baseline_output_dir>
# .jenkins/pytorch/codegen-test.sh <test_output_dir>
#
# Then run diff to compare the generated files:
# diff -Naur <baseline_output_dir> <test_output_dir>

set -eu -o pipefail

if [ "$#" -eq 0 ]; then
COMPACT_JOB_NAME="${BUILD_ENVIRONMENT}"
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
OUT="$(dirname "${BASH_SOURCE[0]}")/../../codegen_result"
else
OUT=$1
fi

set -x

rm -rf "$OUT"

# aten codegen
python -m tools.codegen.gen \
-d "$OUT"/torch/share/ATen

# torch codegen
python -m tools.setup_helpers.generate_code \
--declarations-path "$OUT"/torch/share/ATen/Declarations.yaml \
--install_dir "$OUT"

# pyi codegen
mkdir -p "$OUT"/pyi/torch/_C
mkdir -p "$OUT"/pyi/torch/nn
python -m tools.pyi.gen_pyi \
--declarations-path "$OUT"/torch/share/ATen/Declarations.yaml \
--out "$OUT"/pyi

# autograd codegen (called by torch codegen but can run independently)
python -m tools.autograd.gen_autograd \
"$OUT"/torch/share/ATen/Declarations.yaml \
"$OUT"/autograd \
tools/autograd

# unboxing_wrappers codegen (called by torch codegen but can run independently)
mkdir -p "$OUT"/unboxing_wrappers
python -m tools.jit.gen_unboxing_wrappers \
"$OUT"/torch/share/ATen/Declarations.yaml \
"$OUT"/unboxing_wrappers \
tools/jit/templates

# annotated_fn_args codegen (called by torch codegen but can run independently)
mkdir -p "$OUT"/annotated_fn_args
python -m tools.autograd.gen_annotated_fn_args \
"$OUT"/torch/share/ATen/Declarations.yaml \
"$OUT"/annotated_fn_args \
tools/autograd
1 change: 1 addition & 0 deletions tools/autograd/gen_annotated_fn_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
get_py_variable_methods,
op_name,
)
import argparse
import textwrap
from .gen_autograd import load_aten_declarations

Expand Down
3 changes: 2 additions & 1 deletion tools/autograd/gen_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ def main():
parser.add_argument('autograd', metavar='AUTOGRAD',
help='path to autograd directory')
args = parser.parse_args()
gen_autograd(args.declarations, args.out, args.autograd)
gen_autograd(args.declarations, args.out, args.autograd,
SelectiveBuilder.get_nop_selector())


if __name__ == '__main__':
Expand Down
3 changes: 2 additions & 1 deletion tools/jit/gen_unboxing_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ def main():
parser.add_argument('template_path', metavar='TEMPLATE_PATH',
help='path to templates directory')
args = parser.parse_args()
gen_unboxing_wrappers(args.declarations, args.out, args.template_path)
gen_unboxing_wrappers(args.declarations, args.out, args.template_path,
SelectiveBuilder.get_nop_selector())


if __name__ == '__main__':
Expand Down

0 comments on commit d95e1af

Please sign in to comment.