diff options
author | Alham Fikri Aji <afaji321@gmail.com> | 2020-11-11 08:40:44 +0300 |
---|---|---|
committer | Alham Fikri Aji <afaji321@gmail.com> | 2020-11-11 08:40:44 +0300 |
commit | fdd7493cd2f922e65b6bb08b7ef84b711cf730da (patch) | |
tree | 2cf3ba57fd363ca33a84788ed441db166e078a1b /tests | |
parent | 4dac388a39adc581ecba6ae88b5a889988d15729 (diff) |
add log-based quantization test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/training/features/quantized-model/quantized-log4bit.expected | 10 | ||||
-rw-r--r-- | tests/training/features/quantized-model/test_quantmodel_log.sh | 36 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/training/features/quantized-model/quantized-log4bit.expected b/tests/training/features/quantized-model/quantized-log4bit.expected new file mode 100644 index 0000000..1de1b38 --- /dev/null +++ b/tests/training/features/quantized-model/quantized-log4bit.expected @@ -0,0 +1,10 @@ +225.47087097 +245.67460632 +232.80288696 +229.51301575 +217.59494019 +207.93991089 +201.96940613 +194.00720215 +197.69416809 +199.42311096 diff --git a/tests/training/features/quantized-model/test_quantmodel_log.sh b/tests/training/features/quantized-model/test_quantmodel_log.sh new file mode 100644 index 0000000..f79809b --- /dev/null +++ b/tests/training/features/quantized-model/test_quantmodel_log.sh @@ -0,0 +1,36 @@ +#!/bin/bash -x + +##################################################################### +# SUMMARY: Train a quantized marian model +# AUTHOR: afaji +##################################################################### + +# Exit on error +set -e + +PREFIX=quantized-log4bit + +# Remove old artifacts and create working directory +rm -rf train $PREFIX.{log,out,diff} +mkdir -p train + +# Train an 8-bits model +$MRT_MARIAN/marian \ + --no-shuffle --seed 1111 --dim-emb 32 --dim-rnn 64 --mini-batch 32 --maxi-batch 1 --maxi-batch-sort none --learn-rate 0.1 --optimizer sgd \ + -m train/model.npz -t $MRT_DATA/europarl.de-en/corpus.bpe.{en,de} -v train/vocab.en.yml train/vocab.de.yml \ + --cost-type cross-entropy --sync-sgd --after-batches 100 --disp-freq 10 --quantize-bits 4 --quantize-log-based --quantize-optimization-steps 3 \ + --log $PREFIX.log + +# Check if files exist +test -e train/model.npz +test -e $PREFIX.log + +# Compare the current output with the expected output +cat $PREFIX.log | $MRT_TOOLS/extract-costs.sh > $PREFIX.out +$MRT_TOOLS/diff-nums.py $PREFIX.out $PREFIX.expected -o $PREFIX.diff + +# make sure that the resulting model has no more than 256 different values (i.e. quantized) +$MRT_TOOLS/check-model-unique-vals.py train/model.npz -b 4 + +# Exit with success code +exit 0 |