chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:40:42 +08:00
commit e25996e7db
15472 changed files with 3536181 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from . import rules # noqa: F401
from .decomp import decompose # noqa: F401
from .recompute import (
auto_recompute, # noqa: F401
)
File diff suppressed because it is too large Load Diff
+69
View File
@@ -0,0 +1,69 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from paddle.tensor import ( # noqa: F401
abs,
acos,
acosh,
add,
asin,
asinh,
atan,
atanh,
broadcast_shape,
broadcast_to,
concat,
cos,
cosh,
cumprod,
cumsum,
digamma,
divide,
erf,
erfinv,
exp,
expm1,
fill_constant,
full,
gather,
greater_equal,
lgamma,
log,
log1p,
logcumsumexp,
logit,
logsumexp,
max,
min,
multiply,
ones,
pow,
prod,
reshape,
rsqrt,
sign,
sin,
sinh,
sqrt,
subtract,
sum,
tan,
tanh,
tile,
uniform,
zeros,
)
from paddle.tensor.creation import assign, zeros_like # noqa: F401
from paddle.tensor.manipulation import cast # noqa: F401
from paddle.tensor.math import maximum, minimum # noqa: F401
File diff suppressed because it is too large Load Diff
+74
View File
@@ -0,0 +1,74 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import inspect
class Registry:
"""A general registry object."""
__slots__ = ['name', 'rules']
def __init__(self, name):
self.name = name
self.rules = {}
def register(self, op_type, rule):
assert isinstance(op_type, str)
assert inspect.isfunction(rule)
assert op_type not in self.rules, (
f'name "{op_type}" should not be registered before.'
)
self.rules[op_type] = rule
def lookup(self, op_type):
return self.rules.get(op_type)
_decomposition_ops = Registry('decomposition')
def register_decomp(op_type):
"""
Decorator for registering the lower function for an original op into sequence of primitive ops.
Args:
op_type(str): The op name
Returns:
wrapper: Inner wrapper function
Examples:
.. code-block:: pycon
>>> from paddle.decomposition import register
>>> @register.register_decomp('softmax')
>>> def softmax(x, axis):
... molecular = exp(x)
... denominator = broadcast_to(sum(molecular, axis=axis, keepdim=True), x.shape)
... res = divide(molecular, denominator)
... return res
"""
if not isinstance(op_type, str):
raise TypeError(f'op_type must be str, but got {type(op_type)}.')
def wrapper(f):
_decomposition_ops.register(op_type, f)
return f
return wrapper
def get_decomp_rule(op_type):
_lowerrule = _decomposition_ops.lookup(op_type)
return _lowerrule
+34
View File
@@ -0,0 +1,34 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .primitives import * # noqa: F403
from .register import register_decomp
# TODO(kevincheng2): python implementation of prim feature,
# now it has been sunk to c++, waiting for further deletion.
@register_decomp('pd_op.unsqueeze')
def unsqueeze(x, axis):
"""define composite rule of op unsqueeze"""
"""using reshape to implement unsqueeze op"""
axis = axis.get_defining_op().attrs()["value"]
x_shape = list(x.shape)
axis_list = list(axis)
for i in axis_list:
if i < 0:
i += len(x_shape) + 1
x_shape = [*x_shape[:i], 1, *x_shape[i:]]
out = reshape(x, x_shape)
return [out, None]