Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the cloned project #2

Merged
merged 118 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
c4f90be
Add QAT instructions for RN50
peri044 Jun 21, 2020
4972eb1
[FT] 1. Push the FasterTransformer v2.1 (#582)
byshiue Jun 30, 2020
e0f399d
Update frozen graph script and instructions
peri044 Jun 30, 2020
4f02f7a
Update Dockerfile
Jul 1, 2020
4d80805
Merge pull request #583 from NVIDIA/tts-taco2-convai-patch-1
Jul 1, 2020
6d2357a
code Refactor
peri044 Jul 1, 2020
da2e33a
Merge branch 'master' into rn50_qat_v2
peri044 Jul 1, 2020
ed7831d
Update instructions and output node name
peri044 Jul 1, 2020
00bde50
Remove folder for QAT
peri044 Jul 1, 2020
57d9cc0
Update instructions
peri044 Jul 1, 2020
ac4c539
fix file location
vinhngx Jul 3, 2020
24b8c9c
Merge pull request #586 from vinhngx/vinhn-jasper-file-location-fix
nvpstr Jul 3, 2020
96138d5
[BERT/TF] Updating for Ampere
nvpstr Jul 3, 2020
f0c8bc5
[Tacotron2/PyT} Updating for Ampere
nvpstr Jul 3, 2020
36f3b1b
[DLRM/PyT] Updates for Ampere
nvpstr Jul 3, 2020
76a056c
[VNet/TF] Updating for 20.06 container
nvpstr Jul 3, 2020
b27abeb
[UNet_medical/TF1&2] Updating for Ampere
nvpstr Jul 3, 2020
9f4678d
[UNet industrial/TF] Updating for Ampere
nvpstr Jul 4, 2020
77dad06
[FastPitch] Updating for Ampere
nvpstr Jul 4, 2020
2860d6f
[Transformer/PyT] Updating for 20.06 and Ampere
nvpstr Jul 4, 2020
6e12b5a
[Transformer-XL/TF] Updating for Ampere
nvpstr Jul 4, 2020
f8b3a63
[BERT/PyT] Updating for Ampere and 20.06 container
nvpstr Jul 4, 2020
79d4ced
Adding 3DUnet/TF
nvpstr Jul 4, 2020
8011a06
Update README.md
nv-kkudrynski Jul 6, 2020
2de2945
Merge pull request #587 from NVIDIA/nvpstr/79d4ced
nv-kkudrynski Jul 6, 2020
4cb58b6
Add licenses to new files
peri044 Jul 6, 2020
18db1c1
Update README.md
sharathts Jul 7, 2020
d9050d6
[MaskRCNN/PyT] Fix indentation (#588)
sharathts Jul 7, 2020
b2763ae
[BERT/PyT] Update ampere perf params (#589)
sharathts Jul 7, 2020
ae7fce1
[Jasper/PyT] Updating for Ampere
nv-kkudrynski Jul 7, 2020
b2b2d1c
Merge pull request #590 from NVIDIA/jasper-ampere
nv-kkudrynski Jul 7, 2020
31ca062
[SSD/PyT] Updating for Ampere
nv-kkudrynski Jul 7, 2020
1e35179
[SSD/TF] Updating for Ampere
nv-kkudrynski Jul 7, 2020
7f4ea44
Merge pull request #591 from NVIDIA/ssds-ampere
nv-kkudrynski Jul 7, 2020
c480fbf
[Tacotron2] fixed get_model in inference.py
Jul 8, 2020
33bdf65
readme fixes
nv-kkudrynski Jul 8, 2020
3d497a6
Merge pull request #593 from NVIDIA/readme_fixes
nv-kkudrynski Jul 8, 2020
2729732
Update README.md
nv-kkudrynski Jul 8, 2020
37672df
Merge pull request #584 from peri044/rn50_qat_v2
nv-kkudrynski Jul 8, 2020
25fe4d3
Merge pull request #592 from tonmoay/tonmoay-tt2patch
Jul 8, 2020
aa36bc0
[Jasper/Pyt] Fix images in readme
nv-kkudrynski Jul 8, 2020
038e7f1
Merge pull request #594 from NVIDIA/images-fix
nv-kkudrynski Jul 8, 2020
3337f72
[BERT/PyT] Update DataPrep (#595)
sharathts Jul 9, 2020
40c3be6
[Transformer-XL/TF] Updated perf table
nv-kkudrynski Jul 9, 2020
ced4afc
Merge pull request #596 from NVIDIA/gh/release
nv-kkudrynski Jul 9, 2020
878b004
[NCF/TF, WideAndDeep/TF] Updating for Ampere, [BERT/TF] MRPC support
nv-kkudrynski Jul 14, 2020
8a58081
Merge pull request #606 from NVIDIA/gh/release
nvpstr Jul 14, 2020
1803824
[Transformer/PyT] Removing unnecessary files
nvpstr Jul 16, 2020
b31d091
[Electra/TF2] Adding new model
nvpstr Jul 20, 2020
1182059
Merge pull request #10 from NVIDIA/master
swethmandava Jul 20, 2020
26e47a1
update triton for amp
Jul 20, 2020
c2051b4
pulling v1 tritonserver
Jul 20, 2020
cbe6746
Merge pull request #611 from NVIDIA/nvpstr/b31d09
nvpstr Jul 21, 2020
67370c8
Merge pull request #612 from swethmandava/master
nvpstr Jul 21, 2020
108a783
fix typo (#605)
372046933 Jul 21, 2020
0ef5568
[BERT/PyT] default train:test 9:1 (#616)
sharathts Jul 22, 2020
9ba22d1
[MaskRCNN/TF] Update extract_RN50_weights.py (#597)
amrragab8080 Jul 23, 2020
f3f1311
Enable async_io for squad.
trentlo Jul 23, 2020
388f1ac
Insert needed space as seperator.
trentlo Jul 23, 2020
f4625a2
Update checkpoint MaskRCNN
pribalta Jul 23, 2020
cd7d870
Merge pull request #619 from NVIDIA/pribalta/maskrcnn_checkpoint_update
nvpstr Jul 23, 2020
63a2a2e
Update README.md
alvarognvidia Jul 27, 2020
a275790
Merge pull request #623 from alvarognvidia/master
nvpstr Jul 30, 2020
5a87078
[Electra/TF2] Fix container image and num_gpu arg (#628)
sharathts Jul 30, 2020
e0fcb62
Add FastSpeech in CUDA-Optimized
andabi Jul 31, 2020
a2a5e00
Merge pull request #629 from andabi/master
nvpstr Jul 31, 2020
21a77af
Merge pull request #617 from trentlo/async_io_for_squad
swethmandava Jul 31, 2020
5d2914e
[GNMT/PyT] Updating for Ampere]
nv-kkudrynski Aug 1, 2020
360d1f4
[GNMT/TF] Updating for Ampere
nv-kkudrynski Aug 1, 2020
adddf66
Update README.md
mmarcinkiewicz Aug 2, 2020
d8cc4a9
remove pretrained aligns and update readme accordingly.
andabi Aug 3, 2020
409f03c
Merge pull request #631 from NVIDIA/unetmed-perf-fix
pribalta Aug 3, 2020
1f92262
[BERT/PyT] link gitlab -> DLE (#634)
sharathts Aug 4, 2020
9fa7581
Merge branch 'gh/master' into gh/release
nv-kkudrynski Aug 5, 2020
557f4d0
[Jasper/PyT] Triton update
nv-kkudrynski Aug 5, 2020
2356b89
[WideAndDeep/TF] scripts fix
nv-kkudrynski Aug 5, 2020
386dd8e
Merge pull request #630 from NVIDIA/gh/release
nv-kkudrynski Aug 5, 2020
22f354e
[VAE/TF] Updating for Ampere
nv-kkudrynski Aug 5, 2020
280e75c
Merge pull request #636 from NVIDIA/gh/release
nv-kkudrynski Aug 5, 2020
1aa6813
[FT] 1. Fix the bug of TensorRT plugin of FasterTransformer encoder. …
byshiue Aug 6, 2020
36ad5fe
Update .gitmodules
nv-kkudrynski Aug 6, 2020
769843e
Merge pull request #11 from NVIDIA/master
swethmandava Aug 10, 2020
b82c372
triton v2 api, download mrpc fix, update for mpi 4.2
Aug 10, 2020
efd6384
pointing to wikiextractor commit
Aug 10, 2020
e8f87ac
Keep wikiextractor version fixed
sharathts Aug 10, 2020
1069a73
converge to pyt
Aug 10, 2020
c8bbdb5
Merge pull request #644 from swethmandava/master
swethmandava Aug 11, 2020
41a0891
Merge pull request #645 from NVIDIA/sharathts-patch-4
nv-kkudrynski Aug 11, 2020
fb40734
Remove autobench scripts (#647)
pribalta Aug 12, 2020
9d4c9f3
tfrecords with correct name
Aug 13, 2020
7c0afee
Merge pull request #648 from swethmandava/master
swethmandava Aug 13, 2020
88864b9
[BERT/PyT] MRPC and SST-2 support
nv-kkudrynski Aug 14, 2020
ff7e38b
Merge pull request #650 from NVIDIA/bert_pyt_mrpc
nv-kkudrynski Aug 14, 2020
3745b49
[DLRM/PyT] Update
nv-kkudrynski Aug 17, 2020
d875531
Merge pull request #654 from NVIDIA/dlrm_update
nv-kkudrynski Aug 17, 2020
0d15a95
[DLRM/PyT] Readme fixes
nv-kkudrynski Aug 18, 2020
bbbc823
Merge pull request #655 from NVIDIA/gh/release
nv-kkudrynski Aug 18, 2020
446c878
[ELECTRA/TF2] Update inference latency (#657)
sharathts Aug 20, 2020
8bd6dd1
Document synthetic dataset options
hXl3s Aug 20, 2020
0e6cfbd
Merge pull request #659 from hXl3s/RN50/readme-update
nv-kkudrynski Aug 20, 2020
5cc03ca
[BERT/PyT] Update pretrained checkpoint links (#660)
sharathts Aug 21, 2020
8588e98
[BERT/PyT] specify GPU for triton (#666)
sharathts Sep 2, 2020
21fcdd6
[DLRM/PyT] Triton updates
nv-kkudrynski Sep 7, 2020
323005c
Merge pull request #676 from NVIDIA/gh/release
nv-kkudrynski Sep 8, 2020
5d36b4f
Fixing hyperlinks
nv-kkudrynski Sep 8, 2020
7a4c425
[BERT/PyT] Fix dataloader typo
Sep 9, 2020
cf54b78
fixed link
nv-kkudrynski Sep 10, 2020
1402e94
Update CUDA-Optimized/FastSpeech/README.md
nv-kkudrynski Sep 11, 2020
49e387c
Merge pull request #633 from andabi/master
nv-kkudrynski Sep 11, 2020
152d0c0
Merge pull request #684 from gpauloski/bert_pytorch_fix
nv-kkudrynski Sep 11, 2020
6b82d3a
[TXL/PyT] Minor update for PyTorch Transformer-XL (#688)
szmigacz Sep 14, 2020
437b950
Fixed links in readme
nv-kkudrynski Sep 14, 2020
482fe9a
[BERT/PyT] fix onnx export (#689)
sharathts Sep 15, 2020
aacbda6
Update Jasper sample to TensorRT 7.1.3.4 (#687)
rajeevsrao Sep 15, 2020
a74236a
[BERT/PyT] remove redundant section (#690)
sharathts Sep 17, 2020
72f40b8
Fixed distributed checkpoint loading
hXl3s Sep 18, 2020
94518be
Merge pull request #693 from hXl3s/RN50/ngc-checkpoint-update
nv-kkudrynski Sep 18, 2020
66d1891
Merge branch 'master' into master
byshiue Sep 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 4 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[submodule "PyTorch/Translation/Transformer/cutlass"]
path = PyTorch/Translation/Transformer/cutlass
url = https://github.com/NVIDIA/cutlass.git
[submodule "PyTorch/SpeechRecognition/Jasper/external/tensorrt-inference-server"]
path = PyTorch/SpeechRecognition/Jasper/external/tensorrt-inference-server
url = https://github.com/NVIDIA/tensorrt-inference-server.git
branch = r19.06
[submodule "PyTorch/SpeechRecognition/Jasper/external/triton-inference-server"]
path = PyTorch/SpeechRecognition/Jasper/external/triton-inference-server
url = https://github.com/NVIDIA/triton-inference-server.git
branch = r19.12
5 changes: 5 additions & 0 deletions CUDA-Optimized/FastSpeech/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea
__pycache__
.DS_Store
*.egg-info
.vscode
6 changes: 6 additions & 0 deletions CUDA-Optimized/FastSpeech/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "waveglow"]
path = waveglow
url = https://github.com/NVIDIA/waveglow.git
[submodule "cub"]
path = cub
url = https://github.com/NVlabs/cub.git
7 changes: 7 additions & 0 deletions CUDA-Optimized/FastSpeech/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG FROM_IMAGE_NAME=nvcr.io/nvidia/pytorch:20.03-py3
FROM ${FROM_IMAGE_NAME}

ADD . /workspace/fastspeech
WORKDIR /workspace/fastspeech

RUN sh ./scripts/install.sh
23 changes: 23 additions & 0 deletions CUDA-Optimized/FastSpeech/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the NVIDIA CORPORATION nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions CUDA-Optimized/FastSpeech/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include fastspeech/hparams/*.yaml
recursive-include fastspeech/trt/plugins *.so
450 changes: 450 additions & 0 deletions CUDA-Optimized/FastSpeech/README.md

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions CUDA-Optimized/FastSpeech/fastspeech/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the NVIDIA CORPORATION nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
from fastspeech.utils.hparam import Hparam
import torch

# hyperparamter
HP_ROOT_PATH = os.path.join(os.path.dirname(__file__), 'hparams')
hparam = Hparam(HP_ROOT_PATH)

# device
DEFAULT_DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
137 changes: 137 additions & 0 deletions CUDA-Optimized/FastSpeech/fastspeech/align_tacotron2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the NVIDIA CORPORATION nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import pathlib

import fire
import torch
from tqdm import tqdm
from fastspeech.data_load import PadDataLoader
from fastspeech.dataset.ljspeech_dataset import LJSpeechDataset
import tacotron2.train
import tacotron2.hparams
from fastspeech import hparam as hp, DEFAULT_DEVICE
import os
import numpy as np

from fastspeech.utils.logging import tprint
from fastspeech.utils.pytorch import to_device_async, to_cpu_numpy


def get_tacotron2(device, is_training=False):
hparams = tacotron2.hparams.create_hparams()
model = tacotron2.train.load_model(hparams)
model.load_state_dict(torch.load(
hp.tacotron2_path, map_location=torch.device(device))["state_dict"])
if is_training:
model.train()
else:
model.eval()
return model


def get_duration(texts, text_lens, mels, mel_lens, tacotron2, device):
texts = to_device_async(texts, device)
text_lens = to_device_async(text_lens, device)
mels = to_device_async(mels, device)
mel_lens = to_device_async(mel_lens, device)

_, _, _, aligns = tacotron2.forward(
(texts, text_lens, mels, None, mel_lens))

aligns = to_cpu_numpy(aligns)
durs = torch.FloatTensor([compute_duration(align) for align in aligns])

return durs


def compute_duration(align):
"""
Warning. This code assumes the attention is monotonic.
"""
d_mel, d_text = align.shape
dur = np.array([0 for _ in range(d_text)])

for i in range(d_mel):
idx = np.argmax(align[i])
dur[idx] += 1

return dur


def preprocess_aligns(
hparam="base.yaml",
device=DEFAULT_DEVICE):
""" The script for preprocessing alignments.

By default, this script assumes to load parameters in the default config file, fastspeech/hparams/base.yaml.

--dataset_path=DATASET_PATH
Path to dataset directory.
--tacotron2_path=TACOTRON2_PATH
Path to tacotron2 checkpoint file.
--aligns_path=ALIGNS_PATH
Path to output preprocessed alignments directory.

Refer to fastspeech/hparams/base.yaml to see more parameters.

Args:
hparam (str, optional): Path to default config file. Defaults to "base.yaml".
device (str, optional): Device to use. Defaults to "cuda" if avaiable, or "cpu".
"""

hp.set_hparam(hparam)

pathlib.Path(hp.aligns_path).mkdir(parents=True, exist_ok=True)

dataset = LJSpeechDataset(hp.dataset_path)
dataloader = PadDataLoader(
dataset, batch_size=1, shuffle=False, num_workers=32, drop_last=True)

tacotron2 = get_tacotron2(device, is_training=True)
to_device_async(tacotron2, device)

for batched in tqdm(dataloader):
names = batched['name']
texts = batched['text_encoded']
text_lens = batched['text_len']
mels = batched['mel']
mel_lens = batched['mel_len']

tprint("Processing {}.".format(', '.join(names)))
durs = get_duration(texts, text_lens, mels,
mel_lens, tacotron2, device)

for i, (name, dur) in enumerate(zip(names, durs)):
save_path = os.path.join(hp.aligns_path, name + ".align.npy")

if os.path.exists(save_path):
continue

np.save(save_path, dur)
# assert sum(duration) == len(align)


if __name__ == '__main__':
fire.Fire(preprocess_aligns)
43 changes: 43 additions & 0 deletions CUDA-Optimized/FastSpeech/fastspeech/audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the NVIDIA CORPORATION nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import numpy as np


def dynamic_range_compression(x, C=1, clip_val=1e-5):
"""
PARAMS
------
C: compression factor
"""
return np.log(np.clip(x, a_min=clip_val, a_max=None) * C)


def dynamic_range_decompression(x, C=1):
"""
PARAMS
------
C: compression factor used to compress
"""
return np.exp(x) / C
89 changes: 89 additions & 0 deletions CUDA-Optimized/FastSpeech/fastspeech/data_load.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the NVIDIA CORPORATION nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import numpy as np
import torch
from torch.utils.data import DataLoader

class PadDataLoader(DataLoader):

@staticmethod
def pad_collate_fn(batch):
"""
Apply zero-padding.
"""
# TODO refactor
result = dict()
for key in batch[0].keys():
# apply padding on dataset
sub_batch = [elem[key] for elem in batch]
# check diff dims
if not isinstance(sub_batch[0], np.ndarray):
# if list of float or int
assert all([type(x) == type(sub_batch[0]) for x in sub_batch[1:]]), sub_batch
if isinstance(sub_batch[0], int):
sub_batch = torch.LongTensor(sub_batch)
elif isinstance(sub_batch[0], float):
sub_batch = torch.DoubleTensor(sub_batch)

elif any(list(map(lambda x: x.shape != sub_batch[0].shape, sub_batch[1:]))):
sub_batch = torch.from_numpy(__class__.pad_zero(sub_batch))
else:
sub_batch = torch.from_numpy(np.concatenate(np.expand_dims(sub_batch, axis=0)))
result[key] = sub_batch
return result

def __init__(self, dataset, batch_size, num_workers, shuffle=True, pin_memory=True, drop_last=True):
super().__init__(dataset,
batch_size=batch_size,
shuffle=shuffle,
num_workers=num_workers,
pin_memory=pin_memory,
collate_fn=self.pad_collate_fn,
drop_last=drop_last
)

@staticmethod
def pad_zero(sub_batch):
dims = [b.shape for b in sub_batch]

max_dims = list(dims[0])
for d_li in dims[1:]:
for d_idx in range(len(d_li)):
if max_dims[d_idx] < d_li[d_idx]:
max_dims[d_idx] = d_li[d_idx]

temp = np.zeros((len(sub_batch), *max_dims), dtype=sub_batch[0].dtype)
for i, b in enumerate(sub_batch):
if len(b.shape) == 1:
temp[i, :b.shape[0]] = b
elif len(b.shape) == 2:
temp[i, :b.shape[0], :b.shape[1]] = b
elif len(b.shape) == 3:
temp[i, :b.shape[0], :b.shape[1], :b.shape[2]] = b
else:
raise ValueError
return temp


24 changes: 24 additions & 0 deletions CUDA-Optimized/FastSpeech/fastspeech/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the NVIDIA CORPORATION nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Loading