-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
add new flatten op test=develop #25393
Conversation
Thanks for your contribution! |
Thanks for your contribution! |
python/paddle/fluid/layers/nn.py
Outdated
@@ -9808,7 +9809,7 @@ def soft_relu(x, threshold=40.0, name=None): | |||
return out | |||
|
|||
|
|||
def flatten(x, axis=1, name=None): | |||
def flatten_2d(x, axis=1, name=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样会导致新版本发布后,老的代码跑不了了。
可以保持老的flatten不变,直接在paddle/tensor/manipulation.py下增加新的flatten的实现。(两个地方都用flatten作为函数名)
python/paddle/fluid/dygraph/nn.py
Outdated
|
||
inp_np = np.ones([5, 2, 3, 4]).astype('float32') | ||
with paddle.imperative.guard(): | ||
inp_np = to_variable(inp_np) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use paddle.enable_imperative
to enable imperative mode
|
||
Args: | ||
x (Variable): A tensor of rank >= axis. A tensor with type float32, | ||
float64, int8, int32, int64. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rank -> number of dimensions
to avoid confusion with the meaning: the number of linearly independent rows of a matrix
或者直接不提对tensor的维数的要求?
with type -> with data type
python/paddle/tensor/manipulation.py
Outdated
Returns: | ||
Variable: A tensor with the contents of the input tensor, with input \ | ||
axes flattened by indicated start axis and end axis. \ | ||
A Tensor with type same as input x. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start_axis and stop_axis
type -> data type
python/paddle/tensor/manipulation.py
Outdated
|
||
Raises: | ||
ValueError: If x is not a variable. | ||
ValueError: If axis is illegal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variable -> Variable
axis -> start_axis or stop_axis
python/paddle/tensor/manipulation.py
Outdated
out = helper.create_variable_for_type_inference(x.dtype) | ||
x_shape = helper.create_variable_for_type_inference(x.dtype) | ||
helper.append_op( | ||
type='flatten_new', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽管用户接触不到,但用flatten_new作为新引入的这个OP的名字可能不太合适,会给后续的维护带来理解上的困难。
考虑用flatten_contiguous_range
之类的?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for no_check_set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm (resolved conflict)
python/paddle/fluid/dygraph/nn.py
Outdated
out = self._helper.create_variable_for_type_inference(input.dtype) | ||
x_shape = self._helper.create_variable_for_type_inference(input.dtype) | ||
self._helper.append_op( | ||
type="flatten2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
升级成flatten_contiguous_range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New featuresPR changes
APIsDescribe
add new flatten opAccording to paddle 2.0 standard
1, add flatten api in manipulation file, kernal(named 'flatten_contiguous_range') to support flatten a tensor in a contiguous range of axes and related ut.
2, add Flatten class in imperative mode and related ut.