-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from megagonlabs/develop
Release v5.0.3
- Loading branch information
Showing
7 changed files
with
152 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
from datetime import datetime | ||
import json | ||
import sys | ||
|
||
|
||
REPEAT = 5 | ||
BATCH_SIZE = 128 | ||
|
||
assert len(sys.argv) == 1 or len(sys.argv) == 2 and sys.argv[1] == "-g", "Usage: python {sys.argv[0]} {sys.argv[1]} [-g]" | ||
require_gpu = len(sys.argv) == 2 and sys.argv[1] == "-g" | ||
if require_gpu: | ||
device = "GPU" | ||
else: | ||
device = "CPU" | ||
|
||
sents = [_.rstrip("\n") for _ in sys.stdin] | ||
|
||
results = {} | ||
|
||
|
||
print("timestamp ", "[msec]", "device", 'procedure description', sep="\t", file=sys.stderr) | ||
start = datetime.now() | ||
prev = start | ||
print(start, 0, f'benchmark started with {len(sents)} sentences', sep="\t", file=sys.stderr) | ||
|
||
import spacy | ||
if require_gpu: | ||
spacy.require_gpu() | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"import spacy"] = [dur] | ||
print(lap, dur, device, 'import spacy', sep="\t", file=sys.stderr) | ||
prev = lap | ||
|
||
nlp = spacy.load("ja_ginza") | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"spacy.load('ja_ginza')"] = [dur] | ||
print(lap, dur, device, f'spacy.load("ja_ginza")', sep="\t", file=sys.stderr) | ||
prev = lap | ||
|
||
results[f"ja_ginza->nlp(batch={BATCH_SIZE})"] = [] | ||
for repeat in range(1, REPEAT + 1): | ||
for _ in range((len(sents) - 1) // BATCH_SIZE + 1): | ||
doc = nlp("\n".join(sents[_ * BATCH_SIZE:(_ + 1) * BATCH_SIZE])) | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"ja_ginza->nlp(batch={BATCH_SIZE})"].append(dur / len(sents)) | ||
print( | ||
lap, | ||
dur, | ||
device, | ||
f'#{repeat} ja_ginza->nlp(batch={BATCH_SIZE}): {dur / len(sents):.03f}[msec/sent]', | ||
sep="\t", file=sys.stderr, | ||
) | ||
prev = lap | ||
|
||
results[f"ja_ginza->nlp(batch=1)"] = [] | ||
for repeat in range(1, REPEAT + 1): | ||
for sent in sents: | ||
doc = nlp(sent) | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"ja_ginza->nlp(batch=1)"].append(dur / len(sents)) | ||
print( | ||
lap, | ||
dur, | ||
device, | ||
f'#{repeat} ja_ginza->nlp(batch=1): {dur / len(sents):.03f}[msec/sent]', | ||
sep="\t", file=sys.stderr, | ||
) | ||
prev = lap | ||
|
||
nlp = spacy.load("ja_ginza_electra") | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"spacy.load('ja_ginza_electra')"] = [dur] | ||
print(lap, dur, device, f'spacy.load("ja_ginza_electra")', sep="\t", file=sys.stderr) | ||
prev = lap | ||
|
||
results[f"ja_ginza_electra->nlp(batch={BATCH_SIZE})"] = [] | ||
for repeat in range(1, REPEAT + 1): | ||
for _ in range((len(sents) - 1) // BATCH_SIZE + 1): | ||
doc = nlp("\n".join(sents[_ * BATCH_SIZE:(_ + 1) * BATCH_SIZE])) | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"ja_ginza_electra->nlp(batch={BATCH_SIZE})"].append(dur / len(sents)) | ||
print( | ||
lap, | ||
dur, | ||
device, | ||
f'#{repeat} ja_ginza_electra->nlp(batch={BATCH_SIZE}): {dur / len(sents):.03f}[msec/sent]', | ||
sep="\t", file=sys.stderr, | ||
) | ||
prev = lap | ||
|
||
results[f"ja_ginza_electra->nlp(batch=1)"] = [] | ||
for repeat in range(1, REPEAT + 1): | ||
for sent in sents: | ||
doc = nlp(sent) | ||
lap = datetime.now() | ||
dur = int((lap - prev).total_seconds() * 1000) | ||
results[f"ja_ginza_electra->nlp(batch=1)"].append(dur / len(sents)) | ||
print( | ||
lap, | ||
dur, | ||
device, | ||
f'#{repeat} ja_ginza_electra->nlp(batch=1): {dur / len(sents):.03f}[msec/sent]', | ||
sep="\t", file=sys.stderr, | ||
) | ||
prev = lap | ||
|
||
dur = int((lap - start).total_seconds() * 1000) | ||
print(lap, dur, device, 'total', sep="\t", file=sys.stderr) | ||
|
||
for k, v in results.items(): | ||
l = sorted(v) | ||
results[k] = l[len(l) // 2] | ||
|
||
json.dump( | ||
{"device": device, "results": results}, | ||
sys.stdout, | ||
ensure_ascii=False, | ||
) | ||
print() |
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,4 @@ | ||
#!/bin/bash | ||
set -e | ||
cat gsd/dev.txt gsd/test.txt | python benchmark.py -g | ||
cat gsd/dev.txt gsd/test.txt | python 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,11 @@ | ||
#!/bin/bash | ||
set -e | ||
mkdir -p gsd | ||
for t in train dev test ; do | ||
curl "https://raw.githubusercontent.com/megagonlabs/UD_Japanese-GSD/c614040872a74587912a15ef4637eabc0dc29a60/ja_gsd-ud-${t}.ne.conllu?raw=true" | grep "# text = " | sed 's/# text = //' > gsd/${t}.txt | ||
done | ||
echo | ||
echo '=== CUDA Related Installation Steps ===' | ||
echo 'The pytorch should be installed with cuda support. See https://pytorch.org/get-started/previous-versions/#linux-and-windows-1' | ||
echo 'Also you need to install spacy with appropriate cuda specifier as `pip install -U spacy[cudaXXX]`. See https://spacy.io/usage#gpu' | ||
echo 'And then, install GiNZA as `pip install -U ginza ja-ginza ja-ginza-electra`.' |
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