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

Paddle frontend #7

Merged
merged 2 commits into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions python/tvm/relay/frontend/paddlepaddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def convert_conv2d(g, op, block):
paddings = [pad_h[0], pad_w[0], pad_h[1], pad_w[1]]
elif padding_algorithm == "EXPLICIT":
if len(paddings) == 2:
paddings = [paddings[0],paddings[1],paddings[0],paddings[1]]
paddings = [paddings[0], paddings[1], paddings[0], paddings[1]]
if len(paddings) == 4:
paddings = [paddings[0],paddings[2],paddings[1],paddings[3]]
paddings = [paddings[0], paddings[2], paddings[1], paddings[3]]
else:
msg = 'Value {} in attribute "padding" of operator Conv is not ' "valid."
raise tvm.error.OpAttributeInvalid(msg.format(padding_algorithm))
Expand Down Expand Up @@ -346,7 +346,8 @@ def convert_layer_norm(g, op, block):
scale_input = op.input('Scale')

x_shape = infer_shape(x)
assert begin_norm_axis == -1 or begin_norm_axis == len(x_shape) - 1, "Support only normalization over last one dimension."
assert begin_norm_axis == -1 or begin_norm_axis == len(
x_shape) - 1, "Support only normalization over last one dimension."

if bias_input:
bias = g.get_node(bias_input[0])
Expand All @@ -356,7 +357,7 @@ def convert_layer_norm(g, op, block):
if scale_input:
scale = g.get_node(scale_input[0])
else:
scale = _expr.const(np.ones(x_shape[begin_norm_axis]))
scale = _expr.const(np.ones(x_shape[begin_norm_axis]))

out = _op.nn.layer_norm(x,
gamma=scale,
Expand Down Expand Up @@ -587,9 +588,9 @@ def convert_pool2d(g, op, block):
paddings = [pad_h[0], pad_w[0], pad_h[1], pad_w[1]]
elif padding_algorithm == "EXPLICIT":
if len(paddings) == 2:
paddings = [paddings[0],paddings[1],paddings[0],paddings[1]]
paddings = [paddings[0], paddings[1], paddings[0], paddings[1]]
if len(paddings) == 4:
paddings = [paddings[0],paddings[2],paddings[1],paddings[3]]
paddings = [paddings[0], paddings[2], paddings[1], paddings[3]]
else:
msg = 'Value {} in attribute "padding" of operator Pool2d is not ' "valid."
raise tvm.error.OpAttributeInvalid(msg.format(padding_algorithm))
Expand Down Expand Up @@ -700,9 +701,7 @@ def parameter_process(starts, ends, axes, dshape):
if isinstance(decrease_axis, int):
decrease_axis = [decrease_axis]
starts, ends, axes = parameter_process(starts, ends, axes, dshape)
out = _op.strided_slice(data,
begin=starts,
end=ends)
out = _op.strided_slice(data, begin=starts, end=ends)
if decrease_axis:
out = _op.squeeze(out, axis=decrease_axis)
g.add_node(op.output('Out')[0], out)
Expand All @@ -721,6 +720,7 @@ def convert_softmax(g, op, block):
out = e / _op.sum(e, axis, keepdims=True)
g.add_node(op.output('Out')[0], out)


def convert_unsqueeze(g, op, block):
"""Operator converter for unsqueeze."""

Expand Down Expand Up @@ -773,7 +773,6 @@ def convert_unsqueeze(g, op, block):

class GraphProto(object):
""" A helper class for handling relay functions from PaddlePaddle model."""

def __init__(self):
self.nodes = {}
self.params = {}
Expand Down
Loading