Skip to content

Commit

Permalink
Bump up CUDA version used for tests
Browse files Browse the repository at this point in the history
- disable MXNet tests are MXNet is no longer
  actively developed
- extend support for DLPack capsules that provide
  strides collapsing dimensions

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
  • Loading branch information
JanuszL committed Oct 25, 2023
1 parent 15a4956 commit 5c33c7f
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 97 deletions.
9 changes: 8 additions & 1 deletion dali/python/backend_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,18 @@ void CheckContiguousTensor(const TStrides &strides, int num_strides,
DALI_ENFORCE(num_strides == num_extents,
"There should be exactly as many strides as there are extents in array shape.");
int64_t stride_from_shape = element_size;
int64_t stride_from_shape_collapsed = 1;
int64_t last_non_one_dim = 1;
for (int i = num_strides - 1; i >= 0; i--) {
DALI_ENFORCE(strides[i] == stride_from_shape,
DALI_ENFORCE(strides[i] == stride_from_shape || strides[i] == stride_from_shape_collapsed,
make_string("Strided data not supported. Dimension ", i, " has stride ", strides[i],
" whereas densely packed data of this shape would have a stride ", stride_from_shape));
stride_from_shape *= shape[i];
// for shapes [1, 1, 5] leading dimensions may not contribute to
if (shape[i] != 1) {
stride_from_shape_collapsed *= last_non_one_dim;
last_non_one_dim = shape[i];
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions dali/test/python/test_torch_pipeline_rnnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ def forward(self, inp, seq_len):
# do stft
x = torch.stft(x, n_fft=self.n_fft, hop_length=self.hop_length,
win_length=self.win_length, pad_mode='reflect',
center=True, window=self.window.to(dtype=torch.float).to(x.device))
center=True, window=self.window.to(dtype=torch.float).to(x.device),
return_complex=True)
x = torch.view_as_real(x)

# get power spectrum
x = x.pow(2).sum(-1)
Expand Down Expand Up @@ -214,7 +216,9 @@ def torch_spectrogram(audio, sample_rate, device='cpu',
window_tensor = window_fn(win_length, periodic=False) if window_fn else None
stft_out = torch.stft(audio, n_fft=n_fft, hop_length=hop_length,
win_length=win_length, pad_mode=pad_mode,
center=center, window=window_tensor.to(dtype=torch.float))
center=center, window=window_tensor.to(dtype=torch.float),
return_complex=True)
stft_out = torch.view_as_real(stft_out)
# get power spectrum
spectrogram = stft_out.pow(2).sum(-1)
spectrogram = spectrogram.cpu().numpy()
Expand Down
Binary file added docs/examples/use_cases/paddle/tsm/demo/7.mp4
Binary file not shown.
19 changes: 9 additions & 10 deletions docs/examples/use_cases/paddle/tsm/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import json
import os

from paddle import fluid
import paddle
import paddle.static as static

from nvidia.dali.pipeline import Pipeline
import nvidia.dali.types as types
Expand Down Expand Up @@ -50,10 +50,9 @@ def create_video_pipe(video_files, sequence_length=8, target_size=224,stride=30)


def build(seg_num=8, target_size=224):
image_shape = [seg_num, 3, target_size, target_size]
image_shape = [1, seg_num, 3, target_size, target_size]

image = fluid.layers.data(
name='image', shape=image_shape, dtype='float32')
image = static.data(name='image', shape=image_shape, dtype='float32')

model = TSM()
return model(image)
Expand All @@ -69,16 +68,16 @@ def main():
video_loader = DALIGenericIterator(
pipeline, ['image'], reader_name="Reader", dynamic_shape=True)

exe = fluid.Executor(fluid.CUDAPlace(0))
startup_prog = fluid.Program()
eval_prog = fluid.Program()
exe = static.Executor(paddle.CUDAPlace(0))
startup_prog = static.Program()
eval_prog = static.Program()

with fluid.program_guard(eval_prog, startup_prog):
with fluid.unique_name.guard():
with static.program_guard(eval_prog, startup_prog):
with paddle.utils.unique_name.guard():
fetch_list = build(seg_num, target_size)

exe.run(startup_prog)
compiled_eval_prog = fluid.CompiledProgram(eval_prog)
compiled_eval_prog = static.CompiledProgram(eval_prog)

load_weights(exe, eval_prog, PRETRAIN_WEIGHTS)

Expand Down
106 changes: 51 additions & 55 deletions docs/examples/use_cases/paddle/tsm/tsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# limitations under the License.

import math
import paddle.fluid as fluid
import paddle
from paddle import static


class TSM():
Expand All @@ -27,7 +28,9 @@ def __init__(self, training=False):
self.num_filters = [64, 128, 256, 512]

def shift_module(self, input):
output = fluid.layers.temporal_shift(input, self.num_segs, 1.0 / 8)
output = paddle.nn.functional.temporal_shift(input,
self.num_segs,
1.0 / self.num_segs)
return output

def conv_bn_layer(self,
Expand All @@ -38,27 +41,26 @@ def conv_bn_layer(self,
groups=1,
act=None,
name=None):
conv = fluid.layers.conv2d(
conv = paddle.static.nn.conv2d(
input=input,
num_filters=num_filters,
filter_size=filter_size,
stride=stride,
padding=(filter_size - 1) // 2,
groups=groups,
act=None,
param_attr=fluid.param_attr.ParamAttr(name=name + "_weights"),
param_attr=paddle.ParamAttr(name=name + "_weights"),
bias_attr=False)
if name == "conv1":
bn_name = "bn_" + name
else:
bn_name = "bn" + name[3:]

return fluid.layers.batch_norm(
return paddle.static.nn.batch_norm(
input=conv,
act=act,
is_test=(not self.training),
param_attr=fluid.param_attr.ParamAttr(name=bn_name + "_scale"),
bias_attr=fluid.param_attr.ParamAttr(bn_name + '_offset'),
param_attr=paddle.ParamAttr(name=bn_name + "_scale"),
bias_attr=paddle.ParamAttr(bn_name + '_offset'),
moving_mean_name=bn_name + "_mean",
moving_variance_name=bn_name + '_variance')

Expand All @@ -71,36 +73,35 @@ def shortcut(self, input, ch_out, stride, name):

def bottleneck_block(self, input, num_filters, stride, name):
shifted = self.shift_module(input)

conv0 = self.conv_bn_layer(
input=shifted,
num_filters=num_filters,
filter_size=1,
act='relu',
name=name + "_branch2a")
conv1 = self.conv_bn_layer(
input=conv0,
num_filters=num_filters,
filter_size=3,
stride=stride,
act='relu',
name=name + "_branch2b")
conv2 = self.conv_bn_layer(
input=conv1,
num_filters=num_filters * 4,
filter_size=1,
act=None,
name=name + "_branch2c")

short = self.shortcut(
input, num_filters * 4, stride, name=name + "_branch1")

return fluid.layers.elementwise_add(x=short, y=conv2, act='relu')
conv0 = self.conv_bn_layer(input=shifted,
num_filters=num_filters,
filter_size=1,
act='relu',
name=name + "_branch2a")
conv1 = self.conv_bn_layer(input=conv0,
num_filters=num_filters,
filter_size=3,
stride=stride,
act='relu',
name=name + "_branch2b")
conv2 = self.conv_bn_layer(input=conv1,
num_filters=num_filters * 4,
filter_size=1,
act=None,
name=name + "_branch2c")

short = self.shortcut(input,
num_filters * 4,
stride,
name=name + "_branch1")

add = paddle.add(x=short, y=conv2)
return paddle.nn.functional.relu(add)

def __call__(self, input):
channels = input.shape[2]
short_size = input.shape[3]
input = fluid.layers.reshape(
input = paddle.reshape(
x=input, shape=[-1, channels, short_size, short_size])

conv = self.conv_bn_layer(
Expand All @@ -110,12 +111,10 @@ def __call__(self, input):
stride=2,
act='relu',
name='conv1')
conv = fluid.layers.pool2d(
input=conv,
pool_size=3,
pool_stride=2,
pool_padding=1,
pool_type='max')
conv = paddle.nn.functional.max_pool2d(x=conv,
kernel_size=3,
stride=2,
padding=1)

for block in range(len(self.layers)):
for i in range(self.layers[block]):
Expand All @@ -127,24 +126,21 @@ def __call__(self, input):
stride=2 if i == 0 and block != 0 else 1,
name=conv_name)

pool = fluid.layers.pool2d(
input=conv, pool_size=7, pool_type='avg', global_pooling=True)
pool = paddle.nn.functional.avg_pool2d(x=conv, kernel_size=7)

dropout = fluid.layers.dropout(
x=pool, dropout_prob=0.5, is_test=(not self.training))
dropout = paddle.nn.functional.dropout(x=pool, p=0.5, training=(not self.training))

feature = fluid.layers.reshape(
x=dropout, shape=[-1, self.num_segs, pool.shape[1]])
out = fluid.layers.reduce_mean(feature, dim=1)
feature = paddle.reshape(x=dropout, shape=[-1, self.num_segs, pool.shape[1]])
out = paddle.mean(x=feature, axis=1)

stdv = 1.0 / math.sqrt(pool.shape[1] * 1.0)
out = fluid.layers.fc(input=out,
size=self.num_classes,
act='softmax',
param_attr=fluid.param_attr.ParamAttr(
initializer=fluid.initializer.Uniform(-stdv,
stdv)),
bias_attr=fluid.param_attr.ParamAttr(
out = static.nn.fc(
x=out,
size=self.num_classes,
activation='softmax',
weight_attr=paddle.ParamAttr(
initializer=paddle.nn.initializer.Uniform(low=-stdv, high=stdv)),
bias_attr=paddle.ParamAttr(
learning_rate=2.0,
regularizer=fluid.regularizer.L2Decay(0.)))
regularizer=paddle.regularizer.L2Decay(0.)))
return out
9 changes: 5 additions & 4 deletions docs/examples/use_cases/paddle/tsm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from urllib2 import urlopen
from urlparse import urlparse

from paddle import fluid

import paddle
from paddle import static

Check notice

Code scanning / CodeQL

Unused import Note documentation

Import of 'static' is not used.

def _extract_tar(filename, dest):
print("extracting to {}".format(dest))
Expand All @@ -44,6 +44,7 @@ def _extract_tar(filename, dest):

def _download_weight(url):
weight_dir = os.path.expanduser("~/.cache/paddle/weights")
os.makedirs(weight_dir, exist_ok=True)
filename = os.path.basename(urlparse(url).path)
base, ext = os.path.splitext(filename)
assert ext in ['.tar', '.pdparams'], "Unsupported weight format"
Expand Down Expand Up @@ -92,9 +93,9 @@ def load_weights(exe, prog, url):
weight_path = _download_weight(url)

if os.path.isdir(weight_path):
fluid.io.load_vars(
paddle.distributed.io.load_persistable(
exe, weight_path, prog,
predicate=lambda v: os.path.exists(
os.path.join(weight_path, v.name)))
else:
fluid.io.load_params(exe, '', prog, filename=weight_path)
paddle.distributed.io.load_persistables(exe, '', prog, filename=weight_path)
1 change: 0 additions & 1 deletion qa/TL0_FW_iterators/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash -e
bash -e ./test_tf.sh
bash -e ./test_paddle.sh
bash -e ./test_mxnet.sh
bash -e ./test_pytorch.sh
bash -e ./test_jax.sh
2 changes: 1 addition & 1 deletion qa/TL0_FW_iterators/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
# used pip packages
pip_packages='${python_test_runner_package} numpy mxnet'
pip_packages='${python_test_runner_package} numpy'
target_dir=./dali/test/python

one_config_only=true
Expand Down
1 change: 0 additions & 1 deletion qa/TL0_framework_imports/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash -e
bash -e ./test_tf.sh
bash -e ./test_mxnet.sh
bash -e ./test_pytorch.sh
bash -e ./test_jax.sh
bash -e ./test_no_fw.sh
4 changes: 1 addition & 3 deletions qa/TL0_framework_imports/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/bash -e
# used pip packages

pip_packages='mxnet'
# to be run inside a MXNet container - so don't need to list it here as a pip package dependency

test_body() {
# test code
Expand Down
1 change: 0 additions & 1 deletion qa/TL0_python_self_test_frameworks/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -e
./test_mxnet.sh
./test_cupy.sh
./test_pytorch.sh
./test_pytorch_cupy.sh
3 changes: 2 additions & 1 deletion qa/TL0_python_self_test_frameworks/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash -e
# used pip packages
pip_packages='${python_test_runner_package} numpy mxnet psutil'
# to be run inside a MXNet container - so don't need to list it here as a pip package dependency
pip_packages='${python_test_runner_package} numpy psutil'
target_dir=./dali/test/python

test_body() {
Expand Down
1 change: 1 addition & 0 deletions qa/TL1_custom_src_pattern_build/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash -e

build_and_check() {
pip install black dm-tree
make -j
pip install ./dali/python

Expand Down
1 change: 0 additions & 1 deletion qa/TL1_jupyter_plugins/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -e
bash -e ./test_mxnet.sh
bash -e ./test_tf.sh
bash -e ./test_paddle.sh
bash -e ./test_pytorch.sh
3 changes: 2 additions & 1 deletion qa/TL1_jupyter_plugins/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash -e

# used pip packages
pip_packages='jupyter matplotlib<3.5.3 mxnet'
# to be run inside a MXNet container - so don't need to list it here as a pip package dependency
pip_packages='jupyter matplotlib<3.5.3'
target_dir=./docs/examples/

do_once() {
Expand Down
2 changes: 1 addition & 1 deletion qa/TL1_paddle_tsm/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ do_once() {

test_body() {
out=`python infer.py -k 1 -s 15 demo`
if echo $out | grep -E "(paragliding|sticking_tongue_out)"; then
if echo $out | grep -E "(waxing_legs)"; then
exit 0
fi
exit 3
Expand Down
1 change: 0 additions & 1 deletion qa/TL1_separate_executor/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
bash -e ./test_nofw.sh
bash -e ./test_tf.sh
bash -e ./test_pytorch.sh
bash -e ./test_mxnet.sh
bash -e ./test_paddle.sh
2 changes: 1 addition & 1 deletion qa/TL1_separate_executor/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
# used pip packages
pip_packages='torch mxnet'
# to be run inside a MXNet container - so don't need to list it here as a pip package dependency
target_dir=./dali/test/python
one_config_only=true

Expand Down
1 change: 0 additions & 1 deletion qa/TL2_FW_iterators_perf/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -e
bash -e ./test_tf.sh
bash -e ./test_paddle.sh
bash -e ./test_mxnet.sh
bash -e ./test_pytorch.sh
2 changes: 1 addition & 1 deletion qa/TL2_FW_iterators_perf/test_mxnet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
# used pip packages
pip_packages='mxnet'
# to be run inside a MXNet container - so don't need to list it here as a pip package dependency
target_dir=./dali/test/python
one_config_only=true

Expand Down
Loading

0 comments on commit 5c33c7f

Please sign in to comment.