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

reaplce fill_constant_batch_size_like #55522

Merged
merged 5 commits into from
Jul 31, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,14 @@ def __init__(self, op=None, op_desc=None, cluster=None):
super().__init__(op=op, op_desc=op_desc, cluster=cluster)


@register_op_cost
class ShapeOpCost(CompOpCost):
OP_TYPE = "shape"

def __init__(self, op=None, op_desc=None, cluster=None):
super().__init__(op=op, op_desc=op_desc, cluster=cluster)


@register_op_cost
class SliceOpCost(CompOpCost):
OP_TYPE = "slice"
Expand Down
14 changes: 7 additions & 7 deletions python/paddle/distribution/bernoulli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import paddle
from paddle.distribution import exponential_family
from paddle.fluid.data_feeder import check_type, convert_dtype
from paddle.fluid.layers import tensor
from paddle.fluid.framework import Variable
from paddle.framework import in_dynamic_mode
from paddle.nn.functional import (
binary_cross_entropy_with_logits,
Expand Down Expand Up @@ -97,7 +97,7 @@ def __init__(self, probs, name=None):
check_type(
probs,
'probs',
(float, tensor.Variable),
(float, Variable),
self.name,
)

Expand Down Expand Up @@ -180,7 +180,7 @@ def sample(self, shape):
check_type(
shape,
'shape',
(np.ndarray, tensor.Variable, list, tuple),
(np.ndarray, Variable, list, tuple),
name,
)

Expand Down Expand Up @@ -259,7 +259,7 @@ def rsample(self, shape, temperature=1.0):
check_type(
shape,
'shape',
(np.ndarray, tensor.Variable, list, tuple),
(np.ndarray, Variable, list, tuple),
name,
)
check_type(
Expand Down Expand Up @@ -318,7 +318,7 @@ def cdf(self, value):
"""
name = self.name + '_cdf'
if not in_dynamic_mode():
check_type(value, 'value', tensor.Variable, name)
check_type(value, 'value', Variable, name)

value = self._check_values_dtype_in_probs(self.probs, value)
probs, value = paddle.broadcast_tensors([self.probs, value])
Expand Down Expand Up @@ -356,7 +356,7 @@ def log_prob(self, value):
"""
name = self.name + '_log_prob'
if not in_dynamic_mode():
check_type(value, 'value', tensor.Variable, name)
check_type(value, 'value', Variable, name)

value = self._check_values_dtype_in_probs(self.probs, value)
logits, value = paddle.broadcast_tensors([self.logits, value])
Expand Down Expand Up @@ -395,7 +395,7 @@ def prob(self, value):
"""
name = self.name + '_prob'
if not in_dynamic_mode():
check_type(value, 'value', tensor.Variable, name)
check_type(value, 'value', Variable, name)

return self.log_prob(value).exp(name=name)

Expand Down
4 changes: 2 additions & 2 deletions python/paddle/distribution/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import paddle
from paddle.distribution import distribution
from paddle.fluid.data_feeder import check_type, convert_dtype
from paddle.fluid.layers import tensor
from paddle.fluid.framework import Variable
from paddle.framework import in_dynamic_mode
from paddle.tensor import multinomial

Expand Down Expand Up @@ -100,7 +100,7 @@ def __init__(self, logits, name=None):
check_type(
logits,
'logits',
(np.ndarray, tensor.Variable, list, tuple),
(np.ndarray, Variable, list, tuple),
'Categorical',
)

Expand Down
8 changes: 3 additions & 5 deletions python/paddle/distribution/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import paddle
from paddle import _C_ops
from paddle.fluid.data_feeder import check_variable_and_dtype, convert_dtype
from paddle.fluid.layers import tensor
from paddle.fluid.framework import Variable
from paddle.framework import in_dynamic_mode


Expand Down Expand Up @@ -150,7 +150,7 @@ def _validate_args(self, *args):
is_variable = False
is_number = False
for arg in args:
if isinstance(arg, tensor.Variable):
if isinstance(arg, Variable):
is_variable = True
else:
is_number = True
Expand All @@ -176,9 +176,7 @@ def _to_tensor(self, *args):
tmp = 0.0

for arg in args:
if not isinstance(
arg, (float, list, tuple, np.ndarray, tensor.Variable)
):
if not isinstance(arg, (float, list, tuple, np.ndarray, Variable)):
raise TypeError(
"Type of input args must be float, list, tuple, numpy.ndarray or Tensor, but received type {}".format(
type(arg)
Expand Down
19 changes: 10 additions & 9 deletions python/paddle/distribution/normal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import paddle
from paddle.distribution import distribution
from paddle.fluid.data_feeder import check_type, convert_dtype
from paddle.fluid.layers import tensor
from paddle.fluid.framework import Variable
from paddle.framework import in_dynamic_mode
from paddle.tensor import random

Expand Down Expand Up @@ -91,13 +91,13 @@ def __init__(self, loc, scale, name=None):
check_type(
loc,
'loc',
(int, float, np.ndarray, tensor.Variable, list, tuple),
(int, float, np.ndarray, Variable, list, tuple),
'Normal',
)
check_type(
scale,
'scale',
(int, float, np.ndarray, tensor.Variable, list, tuple),
(int, float, np.ndarray, Variable, list, tuple),
'Normal',
)

Expand Down Expand Up @@ -174,9 +174,9 @@ def sample(self, shape=(), seed=0):
name = self.name + '_sample'
if -1 in batch_shape:
output_shape = shape + batch_shape
zero_tmp = tensor.fill_constant_batch_size_like(
self.loc + self.scale, batch_shape + shape, self.dtype, 0.0
)
fill_shape = list(batch_shape + shape)
fill_shape[0] = paddle.shape(self.loc + self.scale)[0].item()
zero_tmp = paddle.full(fill_shape, 0.0, self.dtype)
zero_tmp_reshape = paddle.reshape(zero_tmp, output_shape)

zero_tmp_shape = paddle.shape(zero_tmp_reshape)
Expand Down Expand Up @@ -234,9 +234,10 @@ def entropy(self):
name = self.name + '_entropy'
batch_shape = list((self.loc + self.scale).shape)
if -1 in batch_shape:
zero_tmp = tensor.fill_constant_batch_size_like(
self.loc + self.scale, batch_shape, self.dtype, 0.0
)
fill_shape = list(batch_shape)
fill_shape[0] = paddle.shape(self.loc + self.scale)[0].item()
fill_dtype = (self.loc + self.scale).dtype
zero_tmp = paddle.full(fill_shape, 0.0, fill_dtype)
else:
zero_tmp = paddle.full(batch_shape, 0.0, self.dtype)
return paddle.add(
Expand Down
12 changes: 6 additions & 6 deletions python/paddle/distribution/uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from paddle import _C_ops
from paddle.distribution import distribution
from paddle.fluid.data_feeder import check_type, convert_dtype
from paddle.fluid.layers import tensor
from paddle.fluid.framework import Variable
from paddle.framework import in_dynamic_mode
from paddle.tensor import random

Expand Down Expand Up @@ -96,13 +96,13 @@ def __init__(self, low, high, name=None):
check_type(
low,
'low',
(int, float, np.ndarray, tensor.Variable, list, tuple),
(int, float, np.ndarray, Variable, list, tuple),
'Uniform',
)
check_type(
high,
'high',
(int, float, np.ndarray, tensor.Variable, list, tuple),
(int, float, np.ndarray, Variable, list, tuple),
'Uniform',
)

Expand Down Expand Up @@ -160,9 +160,9 @@ def sample(self, shape, seed=0):
batch_shape = list((self.low + self.high).shape)
if -1 in batch_shape:
output_shape = shape + batch_shape
zero_tmp = tensor.fill_constant_batch_size_like(
self.low + self.high, batch_shape + shape, self.dtype, 0.0
)
fill_shape = list(batch_shape + shape)
fill_shape[0] = paddle.shape(self.low + self.high)[0].item()
zero_tmp = paddle.full(fill_shape, 0.0, self.dtype)
uniform_random_tmp = random.uniform_random_batch_size_like(
zero_tmp,
zero_tmp.shape,
Expand Down
3 changes: 0 additions & 3 deletions python/paddle/fluid/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from .nn import *
from . import io
from .io import *
from . import tensor
from .tensor import *
from . import math_op_patch
from .math_op_patch import *
from .learning_rate_scheduler import *
Expand All @@ -27,5 +25,4 @@
__all__ = []
__all__ += nn.__all__
__all__ += io.__all__
__all__ += tensor.__all__
__all__ += learning_rate_scheduler.__all__
3 changes: 1 addition & 2 deletions python/paddle/fluid/layers/learning_rate_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import paddle
from . import nn
from . import tensor
from ..framework import (
default_main_program,
Parameter,
Expand Down Expand Up @@ -488,7 +487,7 @@ def cosine_decay(learning_rate, step_each_epoch, epochs):
learning_rate = base_lr, step_each_epoch=10000, epochs=120)
"""
check_type(
learning_rate, 'learning_rate', (float, tensor.Variable), 'cosine_decay'
learning_rate, 'learning_rate', (float, Variable), 'cosine_decay'
)

with default_main_program()._lr_schedule_guard():
Expand Down
125 changes: 0 additions & 125 deletions python/paddle/fluid/layers/tensor.py

This file was deleted.

1 change: 0 additions & 1 deletion python/paddle/fluid/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
_LearningRateEpochDecay,
)
from paddle.fluid import core
from paddle.fluid.layers import tensor
from functools import reduce
from functools import cmp_to_key
from .wrapped_decorator import signature_safe_contextmanager
Expand Down
Loading