forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add instruction count benchmark to run on pull requests (pytorch#131475)
This PR only adds the execution of the benchmarks on this PR and print results, following diffs will add checking out head~1 and running it and comparing. to access results goto test pr_time_benchmarks and inspect logs: you should see ``` + echo 'benchmark results on current PR: ' benchmark results on current PR: + cat /var/lib/jenkins/workspace/test/test-reports/pr_time_benchmarks_before.txt update_hint_regression,instruction_count,27971461254 ``` Pull Request resolved: pytorch#131475 Approved by: https://github.com/ezyang
- Loading branch information
1 parent
27c44c8
commit f5e704a
Showing
34 changed files
with
287 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import csv | ||
from abc import ABC, abstractmethod | ||
|
||
import torch._C._instruction_counter as i_counter | ||
|
||
|
||
class BenchmarkBase(ABC): | ||
_instruction_count = False | ||
|
||
def enable_instruction_count(self): | ||
self._instruction_count = True | ||
return self | ||
|
||
def name(self): | ||
return "" | ||
|
||
def description(self): | ||
return "" | ||
|
||
@abstractmethod | ||
def prepare(self): | ||
pass | ||
|
||
@abstractmethod | ||
def work(self): | ||
pass | ||
|
||
def prepare_once(self): # noqa: B027 | ||
pass | ||
|
||
def count_instructions(self): | ||
print(f"collecting instruction count for {self.name()}") | ||
self.prepare_once() | ||
|
||
results = [] | ||
for i in range(10): | ||
self.prepare() | ||
id = i_counter.start() | ||
self.work() | ||
count = i_counter.end(id) | ||
print(f"instruction count for iteration {i} is {count}") | ||
if i != 0: | ||
results.append(count) | ||
return min(results) | ||
|
||
def append_results(self, path): | ||
with open(path, "a", newline="") as csvfile: | ||
# Create a writer object | ||
writer = csv.writer(csvfile) | ||
# Write the data to the CSV file | ||
for entry in self.results: | ||
writer.writerow(entry) | ||
|
||
def print(self): | ||
for entry in self.results: | ||
print(f"{entry[0]},{entry[1]},{entry[2]}") | ||
|
||
def collect_all(self): | ||
self.results = [] | ||
if self._instruction_count: | ||
self.results.append( | ||
(self.name(), "instruction_count", self.count_instructions()) | ||
) | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
# Check if the output file argument was provided | ||
if [ $# -eq 0 ] | ||
then | ||
echo "Please provide the output file as an argument" | ||
return | ||
fi | ||
|
||
# Check if the directory of Python programs argument was provided | ||
if [ $# -eq 1 ] | ||
then | ||
echo "Please provide the directory of Python programs as an argument" | ||
return | ||
fi | ||
|
||
# Set the output file | ||
output_file=$1 | ||
# Set the directory of Python programs | ||
python_programs_dir=$2 | ||
# Loop through all files in the directory of Python programs | ||
for file in $python_programs_dir/*.py | ||
do | ||
# Execute the Python program and append the output to the output file | ||
sudo env PATH="$PATH" python $file $output_file | ||
done |
46 changes: 46 additions & 0 deletions
46
benchmarks/dynamo/pr_time_benchmarks/benchmarks/update_hint_benchmark.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import random | ||
import sys | ||
|
||
from benchmarks.dynamo.pr_time_benchmarks.benchmark_base import BenchmarkBase | ||
|
||
import torch | ||
|
||
|
||
class Benchmark(BenchmarkBase): | ||
N = 20 | ||
|
||
def name(self): | ||
return "update_hint_regression" | ||
|
||
def description(self): | ||
return "information at https://github.com/pytorch/pytorch/pull/129893" | ||
|
||
def prepare_once(self): | ||
torch._dynamo.config.capture_scalar_outputs = True | ||
random.seed(42) | ||
self.splits = torch.randint(10, (self.N,)) | ||
sz = self.splits.sum().item() | ||
self.input = torch.randn(sz) | ||
|
||
def prepare(self): | ||
torch._dynamo.reset() | ||
|
||
def work(self): | ||
@torch.compile(fullgraph=True) | ||
def f(a, b): | ||
xs = b.tolist() | ||
for x in xs: | ||
torch._check_is_size(x) | ||
torch._check(x <= self.N) | ||
return a.split(xs) | ||
|
||
f(self.input, self.splits) | ||
|
||
|
||
def main(): | ||
result_path = sys.argv[1] | ||
Benchmark().enable_instruction_count().collect_all().append_results(result_path) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# mypy: ignore-errors | ||
import atexit | ||
import re | ||
import shutil | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import numpy | ||
from pt import configs | ||
|
||
import operator_benchmark as op_bench | ||
from pt import configs | ||
|
||
import torch | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import numpy | ||
|
||
import operator_benchmark as op_bench | ||
|
||
import torch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import numpy | ||
|
||
import operator_benchmark as op_bench | ||
|
||
import torch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
benchmarks/operator_benchmark/pt/qembedding_bag_lookups_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
from typing import Optional | ||
|
||
import numpy as np | ||
|
||
import operator_benchmark as op_bench | ||
|
||
import torch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.