forked from mlcommons/algorithmic-efficiency
-
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.
- Loading branch information
1 parent
572cebf
commit f660a21
Showing
7 changed files
with
167 additions
and
8 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
Empty file.
53 changes: 53 additions & 0 deletions
53
tests/modeldiffs/librispeech_deepspeech_noresnet/compare.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,53 @@ | ||
import os | ||
|
||
# Disable GPU access for both jax and pytorch. | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '' | ||
|
||
import jax | ||
import torch | ||
|
||
from algorithmic_efficiency import spec | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_jax.workload import \ | ||
LibriSpeechDeepSpeechTanhWorkload as JaxWorkload | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_pytorch.workload import \ | ||
LibriSpeechDeepSpeechTanhWorkload as PyTorchWorkload | ||
from tests.modeldiffs.diff import out_diff | ||
from tests.modeldiffs.librispeech_deepspeech.compare import key_transform | ||
from tests.modeldiffs.librispeech_deepspeech.compare import sd_transform | ||
|
||
if __name__ == '__main__': | ||
# pylint: disable=locally-disabled, not-callable | ||
|
||
jax_workload = JaxWorkload() | ||
pytorch_workload = PyTorchWorkload() | ||
|
||
# Test outputs for identical weights and inputs. | ||
wave = torch.randn(2, 320000) | ||
pad = torch.zeros_like(wave) | ||
pad[0, 200000:] = 1 | ||
|
||
jax_batch = {'inputs': (wave.detach().numpy(), pad.detach().numpy())} | ||
pyt_batch = {'inputs': (wave, pad)} | ||
|
||
pytorch_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=pyt_batch, | ||
model_state=None, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=None, | ||
update_batch_norm=False) | ||
|
||
jax_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=jax_batch, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=jax.random.PRNGKey(0), | ||
update_batch_norm=False) | ||
|
||
out_diff( | ||
jax_workload=jax_workload, | ||
pytorch_workload=pytorch_workload, | ||
jax_model_kwargs=jax_model_kwargs, | ||
pytorch_model_kwargs=pytorch_model_kwargs, | ||
key_transform=key_transform, | ||
sd_transform=sd_transform, | ||
out_transform=lambda out_outpad: out_outpad[0] * | ||
(1 - out_outpad[1][:, :, None])) |
Empty file.
53 changes: 53 additions & 0 deletions
53
tests/modeldiffs/librispeech_deepspeech_normaug/compare.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,53 @@ | ||
import os | ||
|
||
# Disable GPU access for both jax and pytorch. | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '' | ||
|
||
import jax | ||
import torch | ||
|
||
from algorithmic_efficiency import spec | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_jax.workload import \ | ||
LibriSpeechDeepSpeechNormAndSpecAugWorkload as JaxWorkload | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_pytorch.workload import \ | ||
LibriSpeechDeepSpeechNormAndSpecAugWorkload as PyTorchWorkload | ||
from tests.modeldiffs.diff import out_diff | ||
from tests.modeldiffs.librispeech_deepspeech.compare import key_transform | ||
from tests.modeldiffs.librispeech_deepspeech.compare import sd_transform | ||
|
||
if __name__ == '__main__': | ||
# pylint: disable=locally-disabled, not-callable | ||
|
||
jax_workload = JaxWorkload() | ||
pytorch_workload = PyTorchWorkload() | ||
|
||
# Test outputs for identical weights and inputs. | ||
wave = torch.randn(2, 320000) | ||
pad = torch.zeros_like(wave) | ||
pad[0, 200000:] = 1 | ||
|
||
jax_batch = {'inputs': (wave.detach().numpy(), pad.detach().numpy())} | ||
pyt_batch = {'inputs': (wave, pad)} | ||
|
||
pytorch_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=pyt_batch, | ||
model_state=None, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=None, | ||
update_batch_norm=False) | ||
|
||
jax_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=jax_batch, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=jax.random.PRNGKey(0), | ||
update_batch_norm=False) | ||
|
||
out_diff( | ||
jax_workload=jax_workload, | ||
pytorch_workload=pytorch_workload, | ||
jax_model_kwargs=jax_model_kwargs, | ||
pytorch_model_kwargs=pytorch_model_kwargs, | ||
key_transform=key_transform, | ||
sd_transform=sd_transform, | ||
out_transform=lambda out_outpad: out_outpad[0] * | ||
(1 - out_outpad[1][:, :, None])) |
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,53 @@ | ||
import os | ||
|
||
# Disable GPU access for both jax and pytorch. | ||
os.environ['CUDA_VISIBLE_DEVICES'] = '' | ||
|
||
import jax | ||
import torch | ||
|
||
from algorithmic_efficiency import spec | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_jax.workload import \ | ||
LibriSpeechDeepSpeechNoResNetWorkload as JaxWorkload | ||
from algorithmic_efficiency.workloads.librispeech_deepspeech.librispeech_pytorch.workload import \ | ||
LibriSpeechDeepSpeechNoResNetWorkload as PyTorchWorkload | ||
from tests.modeldiffs.diff import out_diff | ||
from tests.modeldiffs.librispeech_deepspeech.compare import key_transform | ||
from tests.modeldiffs.librispeech_deepspeech.compare import sd_transform | ||
|
||
if __name__ == '__main__': | ||
# pylint: disable=locally-disabled, not-callable | ||
|
||
jax_workload = JaxWorkload() | ||
pytorch_workload = PyTorchWorkload() | ||
|
||
# Test outputs for identical weights and inputs. | ||
wave = torch.randn(2, 320000) | ||
pad = torch.zeros_like(wave) | ||
pad[0, 200000:] = 1 | ||
|
||
jax_batch = {'inputs': (wave.detach().numpy(), pad.detach().numpy())} | ||
pyt_batch = {'inputs': (wave, pad)} | ||
|
||
pytorch_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=pyt_batch, | ||
model_state=None, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=None, | ||
update_batch_norm=False) | ||
|
||
jax_model_kwargs = dict( | ||
augmented_and_preprocessed_input_batch=jax_batch, | ||
mode=spec.ForwardPassMode.EVAL, | ||
rng=jax.random.PRNGKey(0), | ||
update_batch_norm=False) | ||
|
||
out_diff( | ||
jax_workload=jax_workload, | ||
pytorch_workload=pytorch_workload, | ||
jax_model_kwargs=jax_model_kwargs, | ||
pytorch_model_kwargs=pytorch_model_kwargs, | ||
key_transform=key_transform, | ||
sd_transform=sd_transform, | ||
out_transform=lambda out_outpad: out_outpad[0] * | ||
(1 - out_outpad[1][:, :, None])) |