diff --git a/docs/guides/06_distributed_training/cluster_quick_start_cn.rst b/docs/guides/06_distributed_training/cluster_quick_start_cn.rst new file mode 100644 index 00000000000..d95471fb4dd --- /dev/null +++ b/docs/guides/06_distributed_training/cluster_quick_start_cn.rst @@ -0,0 +1,12 @@ +.. _cluster_quick_start: + +分布式训练快速开始 +================== + +一、快速开始-数据并行 +------------------------------- + + + +二、ParameterServer 训练快速开始 +------------------------------- diff --git a/docs/guides/06_distributed_training/cluster_quick_start_fl_ps_cn.rst b/docs/guides/06_distributed_training/cluster_quick_start_fl_ps_cn.rst new file mode 100755 index 00000000000..d1b6d283535 --- /dev/null +++ b/docs/guides/06_distributed_training/cluster_quick_start_fl_ps_cn.rst @@ -0,0 +1,247 @@ + +.. _cluster_quick_start_fl_ps: + +快速开始-联邦参数服务器 +------------------------- + +* 在传统的搜索、推荐场景中,为了训练一个全局的模型,通常需要收集所有用户的原始数据并上传至服务端,这样的做法往往存在用户隐私泄露问题。 +* 联邦学习使得模型训练的整个过程中,用户的原始数据始终保留在用户(Client)本地,服务端(Server)和用户之间通过共享加密的或不包含隐私信息的中间参数的方式,进行模型训练和参数更新,进而在保护用户隐私的前提下构建一个有效的机器学习模型 +* 推荐模型在联邦场景下如何更快、更好地进行训练越来越受到工业界和学术界的关注。 + +本示例将向你展示百度飞桨联邦参数服务器(FL-PS)的能力、教你如何使用它以及在它基础上做二次开发。 + +1.1 任务介绍 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +本节将采用推荐领域非常经典的模型 NCF 为例,介绍如何使用飞桨分布式完成 FL-PS 训练任务。 + +FL-PS 训练基于飞桨静态图,在这之前,请用户了解下 NCF 模型的单机静态图训练示例以及本地单机模拟分布式的使用方法:\ `https://github.com/PaddlePaddle/PaddleRec/tree/master/models/recall/ncf`_\。 + +在传统 PS 基础上,通过生成异构数据集、开启中心调度功能(Coordinator)进行 Client 选择、自定义配置 Client 端私有稀疏参数和 Server 端公共稀疏参数等手段,提升 FL-PS 的训练精度和效率。 + +更多使用细节请阅读 \FL-PS 帮助文档:`https://github.com/PaddlePaddle/PaddleRec/blob/master/models/recall/ncf/fl_ps_help.md`_\. + +本功能依赖 PaddlePaddle2.4 及以上版本的飞桨开源框架,或者用户从 PaddlePaddle develop 分支进行源码编译。 + +1.2 操作方法 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +FL-PS 训练主要包括如下几个部分: + + 1. 准备样本,构建 dataset + 2. 准备配置文件,设定分布式策略 + 3. 加载模型 + 4. 开始训练 + +用户可从 FL-PS 训练脚本 `https://github.com/PaddlePaddle/PaddleRec/blob/master/tools/static_fl_trainer.py` 入手梳理详细流程。 + +1.2.1 准备样本 +"""""""""""" + +* 在 PaddleRec/datasets/movielens_pinterest_NCF 目录中执行: sh run.sh,获取初步处理过的训练数据(big_train)和测试数据(test_data) +* 从 MovieLens 官网 `https://grouplens.org/datasets/movielens/1m/` 下载 ml-1m 数据集,获取 users.dat 文件(可自定义存储路径,但需要和 gen_heter_data.py 脚本中路径保持一致),后续用于构造异构数据集(按 zipcode 的首位数字划分) +* 在 PaddleRec/datasets/movielens_pinterest_NCF/fl_data 中新建目录 fl_test_data 和 fl_train_data,用于存放每个 client 上的训练数据集和测试数据集 +* 在 PaddleRec/datasets/movielens_pinterest_NCF/fl_data 目录中执行: python gen_heter_data.py,生成 10 份训练数据 + * 总样本数 4970844(按 1:4 补充负样本):0 - 518095,1 - 520165,2 - 373605,3 - 315550,4 - 483779,5 - 495635,6 - 402810,7 - 354590,8 - 262710,9 - 1243905 + * 样本数据每一行表示:物品 id,用户 id,标签 + +.. code-block:: python + + def init_reader(self): + self.train_dataset, self.train_file_list = get_reader(self.input_data, + config) + self.test_dataset, self.test_file_list = get_infer_reader( + self.input_data, config) + + if self.role is not None: + self.fl_client = MyFLClient() + self.fl_client.set_basic_config(self.role, self.config, + self.metrics) + else: + raise ValueError("self.role is none") + + self.fl_client.set_train_dataset_info(self.train_dataset, + self.train_file_list) + self.fl_client.set_test_dataset_info(self.test_dataset, + self.test_file_list) + + example_nums = 0 + self.count_method = self.config.get("runner.example_count_method", + "example") + if self.count_method == "example": + example_nums = get_example_num(self.train_file_list) + elif self.count_method == "word": + example_nums = get_word_num(self.train_file_list) + else: + raise ValueError( + "Set static_benchmark.example_count_method for example / word for example count." + ) + self.fl_client.set_train_example_num(example_nums) + +1.2.2 配置文件 +"""""""""""" + +所有的配置参数均写在文件 `config_fl.yaml` 里: + +.. code-block:: python + + runner: + sync_mode: "geo" # 可选, string: sync/async/geo + #with_coodinator: 1 # 1 表示开启中心调度功能 + geo_step: 100 # 必选, int, 在 geo 模式下控制本地的迭代次数 + split_file_list: True # 可选, bool, 若每个节点上都拥有全量数据,则需设置为 True + thread_num: 1 # 多线程配置 + + # reader 类型,分布式下推荐 QueueDataset + reader_type: "QueueDataset" # DataLoader / QueueDataset / RecDataset + pipe_command: "python queuedataset_reader.py" # QueueDataset 模式下的数据 pipe 命令 + dataset_debug: False # QueueDataset 模式下 Profiler 开关 + + train_data_dir: "../../../datasets/movielens_pinterest_NCF/fl_data/fl_train_data" + train_reader_path: "movielens_reader" # importlib format + train_batch_size: 512 + model_save_path: "output_model_ncf" + + use_gpu: False + epochs: 2 + print_interval: 50 + + test_data_dir: "../../../datasets/movielens_pinterest_NCF/fl_data/fl_test_data" + infer_reader_path: "movielens_reader" # importlib format + infer_batch_size: 1 + infer_load_path: "output_model_ncf" + infer_start_epoch: 2 + infer_end_epoch: 3 + + need_dump: True + dump_fields_path: "/home/wangbin/the_one_ps/ziyoujiyi_PaddleRec/PaddleRec/models/recall/ncf" + dump_fields: ['item_input', 'user_input'] + dump_param: [] + local_sparse: ['embedding_0.w_0'] + remote_sparse: ['embedding_1.w_0'] + + hyper_parameters: + optimizer: + class: adam + learning_rate: 0.001 + num_users: 6040 + num_items: 3706 + mf_dim: 8 + mode: "NCF_MLP" # optional: NCF_NeuMF, NCF_GMF, NCF_MLP + fc_layers: [64, 32, 16, 8] + +1.2.3 加载模型 +"""""""""""" + +.. code-block:: python + + def init_network(self): + self.model = get_model(self.config) + self.input_data = self.model.create_feeds() + self.metrics = self.model.net(self.input_data) + self.model.create_optimizer(get_strategy(self.config)) ## get_strategy + if self.pure_bf16: + self.model.optimizer.amp_init(self.place) + +1.2.4 开始训练 +"""""""""""" + +有了训练脚本后,我们就可以用 ``fleetrun`` 指令运行分布式任务了。 ``fleetrun`` 是飞桨封装的分布式启动命令,命令参数 ``server_num`` , ``worker_num``, ``coordinator_num``分别为服务节点、训练节点、中心调度节点的数量(目前只支持一个 Coordinator 节点)。在本例中,服务节点有 1 个,训练节点有 10 个。运行训练脚本之前,请确保所使用的端口没有被占用 + +接着,进入 PaddleRec 目录:PaddleRec/models/recall/ncf, + +1. 使用 Coordinator 功能 + +* 首先将 config_fl.yaml 中的参数 ``local_sparse`` 和 ``remote_sparse`` 配置注释掉,参数 ``with_coodinator`` 置为 1 + +.. code-block:: bash + + fleetrun --worker_num=10 --workers="127.0.0.1:9000,127.0.0.1:9001,127.0.0.1:9002,127.0.0.1:9003,127.0.0.1:9004,127.0.0.1:9005,127.0.0.1:9006,127.0.0.1:9007,127.0.0.1:9008,127.0.0.1:9009" --server_num=1 --servers="127.0.0.1:10000" --coordinator_num=1 --coordinators="127.0.0.1:10001" ../../../tools/static_fl_trainer.py -m config_fl.yaml + +* 详细运行日志信息保存在 log/workerlog.*, log/serverlog.* , log/coordinatorlog.* 里,以下是运行成功时 coordinator 进程打印的部分信息: + +.. code-block:: bash + + >>> all trainer endpoints: ['127.0.0.1:9000', '127.0.0.1:9001', '127.0.0.1:9002', '127.0.0.1:9003', '127.0.0.1:9004', '127.0.0.1:9005', '127.0.0.1:9006', '127.0.0.1:9007', '127.0.0.1:9008', '127.0.0.1:9009'] + I0921 10:29:35.962728 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 0 + I0921 10:29:35.962761 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 1 + I0921 10:29:35.962771 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 2 + I0921 10:29:35.962779 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 3 + I0921 10:29:35.962786 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 4 + I0921 10:29:35.962792 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 5 + I0921 10:29:35.962797 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 6 + I0921 10:29:35.962802 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 7 + I0921 10:29:35.962810 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 8 + I0921 10:29:35.962815 45248 coordinator_client.cc:123] fl-ps > coordinator connect to fl_client: 9 + I0921 10:29:35.962828 45248 communicator.cc:1536] fl-ps > StartCoordinatorClient finish! + I0921 10:29:35.965075 45248 server.cpp:1066] Server[paddle::distributed::CoordinatorService] is serving on port=10001. + I0921 10:29:35.965721 45248 coordinator_client.cc:167] fl-ps > coordinator service addr: 127.0.0.1, 10001, 0 + I0921 10:29:35.965732 45248 communicator.cc:1547] fl-ps > StartCoordinatorServer finished! + 2022-09-21 10:29:35,965 INFO [coordinator.py:344] fl-ps > running make_fl_strategy(loop) in coordinator + + 2022-09-21 10:29:35,965 - INFO - fl-ps > running make_fl_strategy(loop) in coordinator + + I0921 10:29:55.610915 45534 coordinator_client.cc:45] fl-ps > recv from client id: 9, msg_type: 200 + I0921 10:29:55.610915 45540 coordinator_client.cc:45] fl-ps > recv from client id: 5, msg_type: 200 + I0921 10:29:55.610915 45539 coordinator_client.cc:45] fl-ps > recv from client id: 7, msg_type: 200 + I0921 10:29:55.610915 45538 coordinator_client.cc:45] fl-ps > recv from client id: 8, msg_type: 200 + I0921 10:29:55.610915 45533 coordinator_client.cc:45] fl-ps > recv from client id: 2, msg_type: 200 + +2. 使用稀疏参数切分功能 + +* 首先将 config_fl.yaml 中的 ``with_coodinator`` 注释掉,放开参数 ``local_sparse`` 和 ``remote_sparse`` 配置 + +.. code-block:: bash + + fleetrun --worker_num=10 --workers="127.0.0.1:9000,127.0.0.1:9001,127.0.0.1:9002,127.0.0.1:9003,127.0.0.1:9004,127.0.0.1:9005,127.0.0.1:9006,127.0.0.1:9007,127.0.0.1:9008,127.0.0.1:9009" --server_num=1 --servers="127.0.0.1:10000" ../../../tools/static_fl_trainer.py -m config_fl.yaml + +* 详细运行日志信息保存在 log/workerlog.*, log/serverlog.* 里,以下是运行成功时 worker 进程打印的部分信息: + +.. code-block:: bash + + time: [2022-09-21 09:58:58], batch: [50], Epoch 0 Var Loss[1]:[0.609486], Epoch 0 Var Auc[1]:[0.500178] + time: [2022-09-21 09:58:58], batch: [100], Epoch 0 Var Loss[1]:[0.501269], Epoch 0 Var Auc[1]:[0.500078] + time: [2022-09-21 09:58:58], batch: [150], Epoch 0 Var Loss[1]:[0.49927], Epoch 0 Var Auc[1]:[0.500261] + time: [2022-09-21 09:58:59], batch: [200], Epoch 0 Var Loss[1]:[0.498443], Epoch 0 Var Auc[1]:[0.501497] + time: [2022-09-21 09:58:59], batch: [250], Epoch 0 Var Loss[1]:[0.499356], Epoch 0 Var Auc[1]:[0.501259] + time: [2022-09-21 09:58:59], batch: [300], Epoch 0 Var Loss[1]:[0.498732], Epoch 0 Var Auc[1]:[0.502684] + time: [2022-09-21 09:59:00], batch: [350], Epoch 0 Var Loss[1]:[0.500202], Epoch 0 Var Auc[1]:[0.50294] + time: [2022-09-21 09:59:00], batch: [400], Epoch 0 Var Loss[1]:[0.498004], Epoch 0 Var Auc[1]:[0.504768] + time: [2022-09-21 09:59:01], batch: [450], Epoch 0 Var Loss[1]:[0.498487], Epoch 0 Var Auc[1]:[0.504689] + + +1.3 二次开发 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +用户可以基于 Paddle develop 分支进行 FL-PS 的二次开发: + +1.3.1 编译安装 +"""""""""""" + +.. code-block:: bash + + 1)去 https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/develop/install/compile/linux-compile.html 找到 develop/Linux/源码编译/CPU/ 的开发镜像,在 docker 中开发 + 2)在 Paddle 根目录下,新建 build 目录 + 3)cd build + 4)cmake .. -DPY_VERSION=3.8 -DWITH_GPU=OFF -DCMAKE_BUILD_TYPE=Release -DWITH_DISTRIBUTE=ON -DWITH_PSCORE=ON -WITH_AVX=OFF -DWITH_TESTING=OFF -DWITH_FLPS=ON + 5) make -j + 6)python -m pip install python/dist/paddlepaddle-0.0.0-cp38-cp38m-linux_x86_64.whl -U + + +1.3.2 Coordinator 模块 +"""""""""""" + +用户可以基于文件 `Paddle/python/paddle/distributed/ps/coordinator.py` 中定义的相关基类进行继承开发,用户自定义的各种 Client 选择算法均可以用 python 代码实现,从类 `ClientSelectorBase` 继承。 + +1.3.3 构造自定义异构数据集 +"""""""""""" + +参考脚本 `gen_heter_data.py` 写法。 + + +备注:本教程主要介绍了横向联邦 PS 的使用方法,关于纵向联邦 PS 的使用,请参考\ `https://github.com/PaddlePaddle/Paddle/blob/develop/test/ps/test_fl_ps.py`_\,使用 1.3.1 节的编译命令,再执行下述命令即可 + +.. code-block:: bash + ctest -R test_fl_ps -V + +由于该单测需要从网上下载数据集,运行时请确保数据成功下载下来。 diff --git a/docs/guides/06_distributed_training/fleet_api_howto_cn.rst b/docs/guides/06_distributed_training/fleet_api_howto_cn.rst new file mode 100644 index 00000000000..b3d5be7a094 --- /dev/null +++ b/docs/guides/06_distributed_training/fleet_api_howto_cn.rst @@ -0,0 +1,275 @@ + +使用 FleetAPI 进行分布式训练 +========================== + +FleetAPI 设计说明 +----------------- + +Fleet 是 PaddlePaddle 分布式训练的高级 API。Fleet 的命名出自于 PaddlePaddle,象征一个舰队中的多只双桨船协同工作。Fleet 的设计在易用性和算法可扩展性方面做出了权衡。用户可以很容易从单机版的训练程序,通过添加几行代码切换到分布式训练程序。此外,分布式训练的算法也可以通过 Fleet +API 接口灵活定义。 + +Fleet API 快速上手示例 +--------------------- + +下面会针对 Fleet +API 最常见的两种使用场景,用一个模型做示例,目的是让用户有快速上手体验的模板。 + + +* + 假设我们定义 MLP 网络如下: + + .. code-block:: python + + import paddle + + def mlp(input_x, input_y, hid_dim=128, label_dim=2): + fc_1 = paddle.static.nn.fc(input=input_x, size=hid_dim, act='tanh') + fc_2 = paddle.static.nn.fc(input=fc_1, size=hid_dim, act='tanh') + prediction = paddle.static.nn.fc(input=[fc_2], size=label_dim, act='softmax') + cost = paddle.static.nn.cross_entropy(input=prediction, label=input_y) + avg_cost = paddle.static.nn.mean(x=cost) + return avg_cost + +* + 定义一个在内存生成数据的 Reader 如下: + + .. code-block:: python + + import numpy as np + + def gen_data(): + return {"x": np.random.random(size=(128, 32)).astype('float32'), + "y": np.random.randint(2, size=(128, 1)).astype('int64')} + +* + 单机 Trainer 定义 + + .. code-block:: python + + import paddle + from nets import mlp + from utils import gen_data + + input_x = paddle.static.data(name="x", shape=[None, 32], dtype='float32') + input_y = paddle.static.data(name="y", shape=[None, 1], dtype='int64') + + cost = mlp(input_x, input_y) + optimizer = paddle.optimizer.SGD(learning_rate=0.01) + optimizer.minimize(cost) + place = paddle.CUDAPlace(0) + + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) + step = 1001 + for i in range(step): + cost_val = exe.run(feed=gen_data(), fetch_list=[cost.name]) + print("step%d cost=%f" % (i, cost_val[0])) + +* + Parameter Server 训练方法 + + 参数服务器方法对于大规模数据,简单模型的并行训练非常适用,我们基于单机模型的定义给出使用 Parameter Server 进行训练的示例如下: + + .. code-block:: python + + import paddle + paddle.enable_static() + + import paddle.distributed.fleet.base.role_maker as role_maker + import paddle.distributed.fleet as fleet + + from nets import mlp + from utils import gen_data + + input_x = paddle.static.data(name="x", shape=[None, 32], dtype='float32') + input_y = paddle.static.data(name="y", shape=[None, 1], dtype='int64') + + cost = mlp(input_x, input_y) + optimizer = paddle.optimizer.SGD(learning_rate=0.01) + + role = role_maker.PaddleCloudRoleMaker() + fleet.init(role) + + strategy = paddle.distributed.fleet.DistributedStrategy() + strategy.a_sync = True + + optimizer = fleet.distributed_optimizer(optimizer, strategy) + optimizer.minimize(cost) + + if fleet.is_server(): + fleet.init_server() + fleet.run_server() + + elif fleet.is_worker(): + place = paddle.CPUPlace() + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) + + step = 1001 + for i in range(step): + cost_val = exe.run( + program=paddle.static.default_main_program(), + feed=gen_data(), + fetch_list=[cost.name]) + print("worker_index: %d, step%d cost = %f" % + (fleet.worker_index(), i, cost_val[0])) + +* + Collective 训练方法 + + Collective Training 通常在 GPU 多机多卡训练中使用,一般在复杂模型的训练中比较常见,我们基于上面的单机模型定义给出使用 Collective 方法进行分布式训练的示例如下: + + .. code-block:: python + + import paddle + paddle.enable_static() + + import paddle.distributed.fleet.base.role_maker as role_maker + import paddle.distributed.fleet as fleet + + from nets import mlp + from utils import gen_data + + input_x = paddle.static.data(name="x", shape=[None, 32], dtype='float32') + input_y = paddle.static.data(name="y", shape=[None, 1], dtype='int64') + + cost = mlp(input_x, input_y) + optimizer = paddle.optimizer.SGD(learning_rate=0.01) + role = role_maker.PaddleCloudRoleMaker(is_collective=True) + fleet.init(role) + + optimizer = fleet.distributed_optimizer(optimizer) + optimizer.minimize(cost) + place = paddle.CUDAPlace(0) + + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) + + step = 1001 + for i in range(step): + cost_val = exe.run( + program=paddle.static.default_main_program(), + feed=gen_data(), + fetch_list=[cost.name]) + print("worker_index: %d, step%d cost = %f" % + (fleet.worker_index(), i, cost_val[0])) + + +Fleet API 相关的接口说明 +----------------------- + +Fleet API 接口 +^^^^^^^^^^^^^ + + +* init(role_maker=None) + + * fleet 初始化,需要在使用 fleet 其他接口前先调用,用于定义多机的环境配置 + +* is_worker() + + * Parameter Server 训练中使用,判断当前节点是否是 Worker 节点,是则返回 True,否则返回 False + +* is_server(model_dir=None) + + * Parameter Server 训练中使用,判断当前节点是否是 Server 节点,是则返回 True,否则返回 False + +* init_server() + + * Parameter Server 训练中,fleet 加载 model_dir 中保存的模型相关参数进行 parameter + server 的初始化 + +* run_server() + + * Parameter Server 训练中使用,用来启动 server 端服务 + +* init_worker() + + * Parameter Server 训练中使用,用来启动 worker 端服务 + +* stop_worker() + + * 训练结束后,停止 worker + +* distributed_optimizer(optimizer, strategy=None) + + * 分布式优化算法装饰器,用户可带入单机 optimizer,并配置分布式训练策略,返回一个分布式的 optimizer + +RoleMaker +^^^^^^^^^ + + +* + PaddleCloudRoleMaker + + + * + 描述:PaddleCloudRoleMaker 是一个高级封装,支持使用 paddle.distributed.launch 或者 paddle.distributed.launch_ps 启动脚本 + + * + Parameter Server 训练示例: + + .. code-block:: python + + import paddle + paddle.enable_static() + + import paddle.distributed.fleet.base.role_maker as role_maker + import paddle.distributed.fleet as fleet + + role = role_maker.PaddleCloudRoleMaker() + fleet.init(role) + + * + 启动方法: + + .. code-block:: python + + python -m paddle.distributed.launch_ps --worker_num 2 --server_num 2 trainer.py + + * + Collective 训练示例: + + .. code-block:: python + + import paddle + paddle.enable_static() + + import paddle.distributed.fleet.base.role_maker as role_maker + import paddle.distributed.fleet as fleet + + role = role_maker.PaddleCloudRoleMaker(is_collective=True) + fleet.init(role) + + * + 启动方法: + + .. code-block:: python + + python -m paddle.distributed.launch trainer.py + +* + UserDefinedRoleMaker + + + * + 描述:用户自定义节点的角色信息,IP 和端口信息 + + * + 示例: + + .. code-block:: python + + import paddle + paddle.enable_static() + + import paddle.distributed.fleet.base.role_maker as role_maker + import paddle.distributed.fleet as fleet + + role = role_maker.UserDefinedRoleMaker( + current_id=0, + role=role_maker.Role.SERVER, + worker_num=2, + server_endpoints=["127.0.0.1:36011", "127.0.0.1:36012"]) + + fleet.init(role) diff --git a/docs/guides/advanced/visualdl_cn.md b/docs/guides/advanced/visualdl_cn.md new file mode 100644 index 00000000000..3de1f8ded86 --- /dev/null +++ b/docs/guides/advanced/visualdl_cn.md @@ -0,0 +1,300 @@ +# VisualDL 工具简介 + + +

+ +

+ + + +VisualDL 是飞桨可视化分析工具,以丰富的图表呈现训练参数变化趋势、模型结构、数据样本、直方图、PR 曲线及高维数据分布。可帮助用户更清晰直观地理解深度学习模型训练过程及模型结构,进而实现高效的模型优化。 + +具体功能使用方式请参见**VisualDL 使用指南**。项目正处于高速迭代中,敬请期待新组件的加入。 + +VisualDL 支持浏览器种类:Chrome(81 和 83)、Safari 13、Firefox(77 和 78)、Edge(Chromium 版)。 + +VisualDL 原生支持 python 的使用, 通过在模型的 Python 配置中添加几行代码,便可为训练过程提供丰富的可视化支持。 + + + +## 目录 + +* [核心亮点](#核心亮点) +* [安装方式](#安装方式) +* [使用方式](#使用方式) +* [可视化功能概览](#可视化功能概览) +* [开源贡献](#开源贡献) +* [更多细节](#更多细节) +* [技术交流](#技术交流) + + + +## 核心亮点 + +### 简单易用 + +API 设计简洁易懂,使用简单。模型结构一键实现可视化。 + +### 功能丰富 + +功能覆盖标量、数据样本、图结构、直方图、PR 曲线及数据降维可视化。 + +### 高兼容性 + +全面支持 Paddle、ONNX、Caffe 等市面主流模型结构可视化,广泛支持各类用户进行可视化分析。 + +### 全面支持 + +与飞桨服务平台及工具组件全面打通,为您在飞桨生态系统中提供最佳使用体验。 + + + +## 安装方式 + +### 使用 pip 安装 + +```shell +pip install --upgrade --pre visualdl +``` + +### 使用代码安装 + +``` +git clone https://github.com/PaddlePaddle/VisualDL.git +cd VisualDL + +python setup.py bdist_wheel +pip install --upgrade dist/visualdl-*.whl +``` + +需要注意,官方自 2020 年 1 月 1 日起不再维护 Python2,为了保障代码可用性,VisualDL 现仅支持 Python3 + +## 使用方式 + +VisualDL 将训练过程中的数据、参数等信息储存至日志文件中后,启动面板即可查看可视化结果。 + +### 1. 记录日志 + +VisualDL 的后端提供了 Python SDK,可通过 LogWriter 定制一个日志记录器,接口如下: + +```python +class LogWriter(logdir=None, + comment='', + max_queue=10, + flush_secs=120, + filename_suffix='', + write_to_disk=True, + **kwargs) +``` + +#### 接口参数 + +| 参数 | 格式 | 含义 | +| --------------- | ------- | ------------------------------------------------------------ | +| logdir | string | 日志文件所在的路径,VisualDL 将在此路径下建立日志文件并进行记录,如果不填则默认为`runs/${CURRENT_TIME}` | +| comment | string | 为日志文件夹名添加后缀,如果制定了 logdir 则此项无效 | +| max_queue | int | 日志记录消息队列的最大容量,达到此容量则立即写入到日志文件 | +| flush_secs | int | 日志记录消息队列的最大缓存时间,达到此时间则立即写入到日志文件 | +| filename_suffix | string | 为默认的日志文件名添加后缀 | +| write_to_disk | boolean | 是否写入到磁盘 | + +#### 示例 + +设置日志文件并记录标量数据: + +```python +from visualdl import LogWriter + +# 在`./log/scalar_test/train`路径下建立日志文件 +with LogWriter(logdir="./log/scalar_test/train") as writer: + # 使用 scalar 组件记录一个标量数据 + writer.add_scalar(tag="acc", step=1, value=0.5678) + writer.add_scalar(tag="acc", step=2, value=0.6878) + writer.add_scalar(tag="acc", step=3, value=0.9878) +``` + +### 2. 启动面板 + +在上述示例中,日志已记录三组标量数据,现可启动 VisualDL 面板查看日志的可视化结果,共有两种启动方式: + +#### 在命令行启动 + +使用命令行启动 VisualDL 面板,命令格式如下: + +```python +visualdl --logdir --host --port --cache-timeout --language --public-path --api-only +``` + +参数详情: + +| 参数 | 意义 | +| --------------- | ------------------------------------------------------------ | +| --logdir | 设定日志所在目录,可以指定多个目录,VisualDL 将遍历并且迭代寻找指定目录的子目录,将所有实验结果进行可视化 | +| --model | 设定模型文件路径(非文件夹路径),VisualDL 将在此路径指定的模型文件进行可视化,目前可支持 PaddlePaddle、ONNX、Keras、Core ML、Caffe 等多种模型结构,详情可查看[graph 支持模型种类]([https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--%E7%BD%91%E7%BB%9C%E7%BB%93%E6%9E%84%E7%BB%84%E4%BB%B6](https://github.com/PaddlePaddle/VisualDL/blob/develop/docs/components/README.md#Graph--网络结构组件)) | +| --host | 设定 IP,默认为`127.0.0.1` | +| --port | 设定端口,默认为`8040` | +| --cache-timeout | 后端缓存时间,在缓存时间内前端多次请求同一 url,返回的数据从缓存中获取,默认为 20 秒 | +| --language | VisualDL 面板语言,可指定为'EN'或'ZH',默认为浏览器使用语言 | +| --public-path | VisualDL 面板 URL 路径,默认是'/app',即访问地址为'http://<host>:<port>/app' | +| --api-only | 是否只提供 API,如果设置此参数,则 VisualDL 不提供页面展示,只提供 API 服务,此时 API 地址为'http://<host>:<port>/<public_path>/api';若没有设置 public_path 参数,则默认为'http://<host>:<port>/api' | + +针对上一步生成的日志,启动命令为: + +``` +visualdl --logdir ./log +``` + +#### 在 Python 脚本中启动 + +支持在 Python 脚本中启动 VisualDL 面板,接口如下: + +```python +visualdl.server.app.run(logdir, + host="127.0.0.1", + port=8080, + cache_timeout=20, + language=None, + public_path=None, + api_only=False, + open_browser=False) +``` + +请注意:除`logdir`外,其他参数均为不定参数,传递时请指明参数名。 + +接口参数具体如下: + +| 参数 | 格式 | 含义 | +| ------------- | ------------------------------------------------ | ------------------------------------------------------------ | +| logdir | string 或 list[string_1, string_2, ... , string_n] | 日志文件所在的路径,VisualDL 将在此路径下递归搜索日志文件并进行可视化,可指定单个或多个路径 | +| model | string | 模型文件路径(非文件夹路径),VisualDL 将在此路径指定的模型文件进行可视化 | +| host | string | 指定启动服务的 ip,默认为`127.0.0.1` | +| port | int | 启动服务端口,默认为`8040` | +| cache_timeout | int | 后端缓存时间,在缓存时间内前端多次请求同一 url,返回的数据从缓存中获取,默认为 20 秒 | +| language | string | VisualDL 面板语言,可指定为'en'或'zh',默认为浏览器使用语言 | +| public_path | string | VisualDL 面板 URL 路径,默认是'/app',即访问地址为'http://:/app' | +| api_only | boolean | 是否只提供 API,如果设置此参数,则 VisualDL 不提供页面展示,只提供 API 服务,此时 API 地址为'http://://api';若没有设置 public_path 参数,则默认为 http://:/api' | +| open_browser | boolean | 是否打开浏览器,设置为 True 则在启动后自动打开浏览器并访问 VisualDL 面板,若设置 api_only,则忽略此参数 | + +针对上一步生成的日志,我们的启动脚本为: + +```python +from visualdl.server import app + +app.run(logdir="./log") +``` + +在使用任意一种方式启动 VisualDL 面板后,打开浏览器访问 VisualDL 面板,即可查看日志的可视化结果,如图: + +

+ +

+ + + +## 可视化功能概览 + +### Scalar + +以图表形式实时展示训练过程参数,如 loss、accuracy。让用户通过观察单组或多组训练参数变化,了解训练过程,加速模型调优。具有两大特点: + +#### 动态展示 + +在启动 VisualDL 后,LogReader 将不断增量的读取日志中数据并供前端调用展示,因此能够在训练中同步观测指标变化,如下图: + +

+ +

+ + + +#### 多实验对比 + +只需在启动 VisualDL 时将每个实验日志所在路径同时传入即可,每个实验中相同 tag 的指标将绘制在一张图中同步呈现,如下图: + +

+ +

+ + + +### Image + +实时展示训练过程中的图像数据,用于观察不同训练阶段的图像变化,进而深入了解训练过程及效果。 + +

+ +

+ + + +### Audio + +实时查看训练过程中的音频数据,监控语音识别与合成等任务的训练过程。 + +

+ +

+ + + +### Graph + +一键可视化模型的网络结构。可查看模型属性、节点信息、节点输入输出等,并支持节点搜索,辅助用户快速分析模型结构与了解数据流向。 + +

+ +

+ + + +### Histogram + +以直方图形式展示 Tensor(weight、bias、gradient 等)数据在训练过程中的变化趋势。深入了解模型各层效果,帮助开发者精准调整模型结构。 + +- Offset 模式 + +

+ +

+ + + +- Overlay 模式 + +

+ +

+ + + +### PR Curve + +精度-召回率曲线,帮助开发者权衡模型精度和召回率之间的平衡,设定最佳阈值。 + +

+ +

+ + +### High Dimensional + +将高维数据进行降维展示,目前支持 T-SNE、PCA 两种降维方式,用于深入分析高维数据间的关系,方便用户根据数据特征进行算法优化。 + +

+ +

+ +## 开源贡献 + +VisualDL 是由 [PaddlePaddle](https://www.paddlepaddle.org/) 和 [ECharts](https://echarts.apache.org/) 合作推出的开源项目。 +Graph 相关功能由 [Netron](https://github.com/lutzroeder/netron) 提供技术支持。 +欢迎所有人使用,提意见以及贡献代码。 + + +## 更多细节 + +想了解更多关于 VisualDL 可视化功能的使用详情介绍,请查看**VisualDL 使用指南**。 + +## 技术交流 + +欢迎您加入 VisualDL 官方 QQ 群:1045783368 与飞桨团队以及其他用户共同针对 VisualDL 进行讨论与交流。 diff --git a/docs/guides/advanced/visualdl_en.md b/docs/guides/advanced/visualdl_en.md new file mode 100755 index 00000000000..6aa671f8a3b --- /dev/null +++ b/docs/guides/advanced/visualdl_en.md @@ -0,0 +1,263 @@ +# Introduction to VisualDL Toolset + +

+ +

+ +## Introduction +VisualDL is a deep learning visualization tool that can help design deep learning jobs. +It includes features such as scalar, parameter distribution, model structure and image visualization. +Currently it is being developed at a high pace. +New features will be continuously added. + +At present, most DNN frameworks use Python as their primary language. VisualDL supports Python by nature. +Users can get plentiful visualization results by simply add a few lines of Python code into their model before training. + +Besides Python SDK, VisualDL was writen in C++ on the low level. It also provides C++ SDK that +can be integrated into other platforms. + + +## Component +VisualDL provides following components: + +- scalar +- histogram +- image +- audio +- graph +- high dimensional + +### Scalar +Scalar can be used to show the trends of error during training. + +

+ +

+ +### Histogram +Histogram can be used to visualize parameter distribution and trends for any tensor. + +

+ +

+ +### Image +Image can be used to visualize any tensor or intermediate generated image. + +

+ +

+ +### Audio +Audio can be used to play input audio samples or generated audio samples. + +### Graph + +VisualDL graph supports displaying paddle model, furthermore is compatible with ONNX ([Open Neural Network Exchange](https://github.com/onnx/onnx)), +Cooperated with Python SDK, VisualDL can be compatible with most major DNN frameworks, including +PaddlePaddle, PyTorch and MXNet. + +

+ +

+ +To display the paddle model, all you have to do is: + +1. call the `fluid.io.save_inference_model()`interface to save paddle model +2. use `visualdl --model_pb [paddle_model_dir]` to load paddle model in command line + + +### High Dimensional +High Dimensional can be used to visualize data embeddings by projecting high-dimensional data into 2D / 3D. + +

+ +

+ +## Quick Start +To give the VisualDL a quick test, please use the following commands. + +``` +# Install the VisualDL. Preferably under a virtual environment or anaconda. +pip install --upgrade visualdl + +# run a demo, vdl_create_scratch_log will create logs for testing. +vdl_create_scratch_log +visualdl --logdir=scratch_log --port=8080 + +# visit http://127.0.0.1:8080 +``` + +If you encounter the error `TypeError: __init__() got an unexpected keyword argument 'file'`, that is due to protobuf version is not 3.5+,simply run `pip install --upgrade protobuf` will fix the issue. + +If you run into any other issues in above steps, it could be error caused by environmental issues by different python or pip versions. +Following installation methods might fix the issues. + +## Install with Virtualenv + +[Virtualenv](https://virtualenv.pypa.io/en/stable/) creates isolated Python environment that prevents interfering +by other Python programs on the same machine and make sure Python and pip are located properly. + +On macOS, install pip and virtualenv by: +``` +sudo easy_install pip +pip install --upgrade virtualenv +``` + +On Linux, install pip and virtualenv by: +``` +sudo apt-get install python3-pip python3-dev python-virtualenv +``` + +Then create a Virtualenv environment by one of following command: +``` +virtualenv -p python3 ~/vdl for Python 3.x +``` + +```~/vdl``` will be your Virtualenv directory, you may choose to install anywhere. + +Activate your Virtualenv environment by: +``` +source ~/vdl/bin/activate +``` + +Now you should be able to install VisualDL and run our demo: + +``` +pip install --upgrade visualdl + +# run a demo, vdl_create_scratch_log will create logs for testing. +vdl_create_scratch_log +visualdl --logdir=scratch_log --port=8080 + +# visit http://127.0.0.1:8080 +``` + +If you still have issues installing VisualDL from Virtualenv, try following installation method. + + +## Install with Anaconda + +Anaconda is a python distribution, with installation and package management tools. Also it is an environment manager, +which provides the facility to create different python environments, each with their own settings. + +Follow the instructions on the [Anaconda download site](https://www.anaconda.com/download) to download and install Anaconda. +Download Python 3.6 version command-Line installer. + +Create a conda environment named ```vdl``` or anything you want by: +``` +conda create -n vdl pip python=2.7 # or python=3.3, etc. +``` + +Activate the conda environment by: +``` +source activate vdl +``` + +Now you should be able to install VisualDL and run our demo: + +``` +pip install --upgrade visualdl + +# run a demo, vdl_create_scratch_log will create logs for testing. +vdl_create_scratch_log +visualdl --logdir=scratch_log --port=8080 + +# visit http://127.0.0.1:8080 +``` + +If you still have issues installing VisualDL, try installing from sources as in following section. + + +### Install from source +``` +#Preferably under a virtualenv or anaconda. +git clone https://github.com/PaddlePaddle/VisualDL.git +cd VisualDL + +python setup.py bdist_wheel +pip install --upgrade dist/visualdl-*.whl +``` + +If there are still issues regarding the ```pip install```, you can still start Visual DL by starting the dev server +[here](https://github.com/PaddlePaddle/VisualDL/tree/develop/docs#%E5%AE%89%E8%A3%85%E6%96%B9%E5%BC%8F) + + +## SDK +VisualDL provides both Python SDK and C++ SDK in order to fit more use cases. + + +### Python SDK +VisualDL now supports both Python 2 and Python 3. +Below is an example of creating a simple Scalar component and inserting data from different timestamps: + +```python +import random +from visualdl import LogWriter + +logdir = "./tmp" +logger = LogWriter(logdir, sync_cycle=10000) + +# mark the components with 'train' label. +with logger.mode("train"): + # create a scalar component called 'scalars/scalar0' + scalar0 = logger.scalar("scalars/scalar0") + +# add some records during DL model running. +for step in range(100): + scalar0.add_record(step, random.random()) +``` + +### C++ SDK +Here is the C++ SDK identical to the Python SDK example above: + +```c++ +#include +#include +#include "visualdl/logic/sdk.h" + +namespace vs = visualdl; +namespace cp = visualdl::components; + +int main() { + const std::string dir = "./tmp"; + vs::LogWriter logger(dir, 10000); + + logger.SetMode("train"); + auto tablet = logger.AddTablet("scalars/scalar0"); + + cp::Scalar scalar0(tablet); + + for (int step = 0; step < 1000; step++) { + float v = (float)std::rand() / RAND_MAX; + scalar0.AddRecord(step, v); + } + + return 0; +} +``` + +## Launch Visual DL +After some logs have been generated during training, users can launch Visual DL application to see real-time data visualization by: + + +``` +visualdl --logdir +``` + +visualDL also supports following optional parameters: + +- `--host` set IP +- `--port` set port +- `-m / --model_pb` specify ONNX format for model file to view graph + + +### Contribute + +VisualDL is initially created by [PaddlePaddle](http://www.paddlepaddle.org/) and +[ECharts](http://echarts.baidu.com/). +We welcome everyone to use, comment and contribute to VisualDL :) + +## More details + +For more details about how to use VisualDL, please take a look at [documents](https://github.com/PaddlePaddle/VisualDL/tree/develop/demo) diff --git a/docs/guides/jit/basic_usage_en.md b/docs/guides/jit/basic_usage_en.md new file mode 100644 index 00000000000..647e19d57b2 --- /dev/null +++ b/docs/guides/jit/basic_usage_en.md @@ -0,0 +1,473 @@ +# 基本用法 + + +## 一、 @to_static 概览 + +动静转换(@to_static)通过解析 Python 代码(抽象语法树,下简称:AST) 实现一行代码即可转为静态图功能,即只需在待转化的函数前添加一个装饰器 ``@paddle.jit.to_static`` 。 + +如下是一个使用 @to_static 装饰器的 ``Model`` 示例: + +```python +import paddle +from paddle.jit import to_static + +class SimpleNet(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + # 方式一:装饰 forward 函数(支持训练) + @to_static + def forward(self, x, y): + out = self.linear(x) + out = out + y + return out + +net = SimpleNet() +# 方式二:(推荐)仅做预测模型导出时,推荐此种用法 +net = paddle.jit.to_static(net) # 动静转换 +``` + +动转静 @to_static 除了支持预测模型导出,还兼容转为静态图子图训练。仅需要在 ``forward`` 函数上添加此装饰器即可,不需要修改任何其他的代码。 + +基本执行流程如下: + + + + +### 1.1 动态图 layer 生成 Program + +上述样例中的 ``forward`` 函数包含两行组网代码: ``Linear`` 和 ``add`` 操作。以 ``Linear`` 为例,在 Paddle 的框架底层,每个 Paddle 的组网 API 的实现包括两个分支: + +```python + +class Linear(...): + def __init__(self, ...): + # ...(略) + + def forward(self, input): + + if in_dygraph_mode(): # 动态图分支 + core.ops.matmul(input, self.weight, pre_bias, ...) + return out + else: # 静态图分支 + self._helper.append_op(type="matmul", inputs=inputs, ...) # <----- 生成一个 Op + if self.bias is not None: + self._helper.append_op(type='elementwise_add', ...) # <----- 生成一个 Op + + return out +``` + +动态图 ``layer`` 生成 ``Program`` ,其实是开启 ``paddle.enable_static()`` 时,在静态图下逐行执行用户定义的组网代码,依次添加(对应 ``append_op`` 接口) 到默认的主 Program(即 ``main_program`` ) 中。 + +### 1.2 动态图 Tensor 转为静态图 Variable + +上面提到,所有的组网代码都会在静态图模式下执行,以生成完整的 ``Program`` 。**但静态图 ``append_op`` 有一个前置条件必须满足:** + +> **前置条件**:append_op() 时,所有的 inputs,outputs 必须都是静态图的 Variable 类型,不能是动态图的 Tensor 类型。 + + +**原因**:静态图下,操作的都是**描述类单元**:计算相关的 ``OpDesc`` ,数据相关的 ``VarDesc`` 。可以分别简单地理解为 ``Program`` 中的 ``Op`` 和 ``Variable`` 。 + +因此,在动转静时,我们在需要在**某个统一的入口处**,将动态图 ``Layers`` 中 ``Tensor`` 类型(包含具体数据)的 ``Weight`` 、``Bias`` 等变量转换为**同名的静态图 ``Variable``**。 + ++ ParamBase → Parameters ++ VarBase → Variable + +技术实现上,我们选取了框架层面两个地方作为类型**转换的入口**: + ++ ``Paddle.nn.Layer`` 基类的 ``__call__`` 函数 + ```python + def __call__(self, *inputs, **kwargs): + # param_guard 会对将 Tensor 类型的 Param 和 buffer 转为静态图 Variable + with param_guard(self._parameters), param_guard(self._buffers): + # ... forward_pre_hook 逻辑 + + outputs = self.forward(*inputs, **kwargs) # 此处为 forward 函数 + + # ... forward_post_hook 逻辑 + + return outpus + ``` + ++ ``Block.append_op`` 函数中,生成 ``Op`` 之前 + ```python + def append_op(self, *args, **kwargs): + if in_dygraph_mode(): + # ... (动态图分支) + else: + inputs=kwargs.get("inputs", None) + outputs=kwargs.get("outputs", None) + # param_guard 会确保将 Tensor 类型的 inputs 和 outputs 转为静态图 Variable + with param_guard(inputs), param_guard(outputs): + op = Operator( + block=self, + desc=op_desc, + type=kwargs.get("type", None), + inputs=inputs, + outputs=outputs, + attrs=kwargs.get("attrs", None)) + ``` + + +以上,是动态图转为静态图的两个核心逻辑,总结如下: + ++ 动态图 ``layer`` 调用在动转静时会走底层 ``append_op`` 的分支,以生成 ``Program`` ++ 动态图 ``Tensor`` 转为静态图 ``Variable`` ,并确保编译期的 ``InferShape`` 正确执行 + + +## 二、 输入层 InputSpec + + +静态图下,模型起始的 Placeholder 信息是通过 ``paddle.static.data`` 来指定的,并以此作为编译期的 ``InferShape`` 推导起点。 + +```python +import paddle +# 开启静态图模式 +paddle.enable_static() + +# placeholder 信息 +x = paddle.static.data(shape=[None, 10], dtype='float32', name='x') +y = paddle.static.data(shape=[None, 3], dtype='float32', name='y') + +out = paddle.static.nn.fc(x, 3) +out = paddle.add(out, y) +``` + + +动转静代码示例,通过 ``InputSpec`` 设置 ``Placeholder`` 信息: + +```python +import paddle +from paddle.jit import to_static + +class SimpleNet(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + # 方式一:在函数定义处装饰 + @to_static + def forward(self, x, y): + out = self.linear(x) + out = out + y + return out + +net = SimpleNet() + +# 方式二:(推荐)仅做预测模型导出时,推荐此种用法 +x_spec = InputSpec(shape=[None, 10], name='x') +y_spec = InputSpec(shape=[3], name='y') + +net = paddle.jit.to_static(net, input_spec=[x_spec, y_spec]) # 动静转换 +``` + + +在导出模型时,需要显式地指定输入 ``Tensor`` 的**签名信息**,优势是: + + ++ 可以指定某些维度为 ``None`` , 如 ``batch_size`` ,``seq_len`` 维度 ++ 可以指定 Placeholder 的 ``name`` ,方面预测时根据 ``name`` 输入数据 + +> 注:InputSpec 接口的高阶用法,请参看 [【官方文档】InputSpec 功能介绍](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/04_dygraph_to_static/input_spec_cn.html) + + +## 三、函数转写 + +在 NLP、CV 领域中,一个模型常包含层层复杂的子函数调用,动转静中是如何实现**只需装饰最外层的 ``forward`` 函数**,就能递归处理所有的函数? + +如下是一个模型样例: + +```python +import paddle +from paddle.jit import to_static + +class SimpleNet(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + @to_static + def forward(self, x, y): + out = self.my_fc(x) # <---- self.other_func + out = add_two(out, y) # <---- other plain func + return out + + def my_fc(self, x): + out = self.linear(x) + return out + +# 此函数可以在任意文件 +def add_two(x, y): + out = x + y + return out + +net = SimpleNet() +# 查看转写的代码内容 +paddle.jit.set_code_level(100) + +x = paddle.zeros([2,10], 'float32') +y = paddle.zeros([3], 'float32') + +out = net(x, y) +``` + +可以通过 ``paddle.jit.set_code_level(100)`` 在执行时打印代码转写的结果到终端,转写代码如下: + +```python +def forward(self, x, y): + out = paddle.jit.dy2static.convert_call(self.my_fc)(x) + out = paddle.jit.dy2static.convert_call(add_two)(out, y) + return out + +def my_fc(self, x): + out = paddle.jit.dy2static.convert_call(self.linear)(x) + return out + +def add_two(x, y): + out = x + y + return out +``` + + +如上所示,所有的函数调用都会被转写如下形式: + +```python + out = paddle.jit.dy2static.convert_call( self.my_fc )( x ) + ^ ^ ^ ^ + | | | | +返回列表 convert_call 原始函数 参数列表 +``` + +即使函数定义分布在不同的文件中, ``convert_call`` 函数也会递归地处理和转写所有嵌套的子函数。 + +## 四、控制流转写 + +控制流 ``if/for/while`` 的转写和处理是动转静中比较重要的模块,也是动态图模型和静态图模型实现上差别最大的一部分。 + +**转写上有两个基本原则:** + ++ **并非**所有动态图中的 ``if/for/while`` 都会转写为 ``cond_op/while_op`` ++ **只有**控制流的判断条件**依赖了 ``Tensor`` **(如 ``shape`` 或 ``value`` ),才会转写为对应 Op + + + + + + +### 4.1 IfElse + +首先,无论是否会转写为 ``cond_op`` ,动转静都会首先都会对代码进行处理,**转写为 ``cond`` 接口可以接受的写法** + +**示例一:不依赖 Tensor 的控制流** + +```python +def not_depend_tensor_if(x, label=None): + out = x + 1 + if label is not None: # <----- python bool 类型 + out = paddle.nn.functional.cross_entropy(out, label) + return out + +print(to_static(not_depend_tensor_ifw).code) +# 转写后的代码: +""" +def not_depend_tensor_if(x, label=None): + out = x + 1 + + def true_fn_1(label, out): # true 分支 + out = paddle.nn.functional.cross_entropy(out, label) + return out + + def false_fn_1(out): # false 分支 + return out + + out = paddle.jit.dy2static.convert_ifelse(label is not None, true_fn_1, + false_fn_1, (label, out), (out,), (out,)) + + return out +""" +``` + + +**示例二:依赖 Tensor 的控制流** + +```python +def depend_tensor_if(x): + if paddle.mean(x) > 5.: # <---- Bool Tensor 类型 + out = x - 1 + else: + out = x + 1 + return out + +print(to_static(depend_tensor_if).code) +# 转写后的代码: +""" +def depend_tensor_if(x): + out = paddle.jit.dy2static.data_layer_not_check(name='out', shape=[-1], + dtype='float32') + + def true_fn_0(x): # true 分支 + out = x - 1 + return out + + def false_fn_0(x): # false 分支 + out = x + 1 + return out + + out = paddle.jit.dy2static.convert_ifelse(paddle.mean(x) > 5.0, + true_fn_0, false_fn_0, (x,), (x,), (out,)) + + return out +""" +``` + + +规范化代码之后,所有的 ``IfElse`` 均转为了如下形式: + +```python + out = convert_ifelse(paddle.mean(x) > 5.0, true_fn_0, false_fn_0, (x,), (x,), (out,)) + ^ ^ ^ ^ ^ ^ ^ ^ + | | | | | | | | + 输出 convert_ifelse 判断条件 true 分支 false 分支 分支输入 分支输入 输出 +``` + + +``convert_ifelse`` 是框架底层的函数,在逐行执行用户代码生成 ``Program`` 时,执行到此处时,会根据**判断条件**的类型( ``bool`` 还是 ``Bool Tensor`` ),自适应决定是否转为 ``cond_op`` 。 + +```python +def convert_ifelse(pred, true_fn, false_fn, true_args, false_args, return_vars): + + if isinstance(pred, Variable): # 触发 cond_op 的转换 + return _run_paddle_cond(pred, true_fn, false_fn, true_args, false_args, + return_vars) + else: # 正常的 python if + return _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args) +``` + + +### 4.2 For/While + +``For/While`` 也会先进行代码层面的规范化,在逐行执行用户代码时,才会决定是否转为 ``while_op``。 + +示例一:不依赖 Tensor 的控制流 + +```python +def not_depend_tensor_while(x): + a = 1 + + while a < 10: # <---- a is python scalar + x = x + 1 + a += 1 + + return x + +print(to_static(not_depend_tensor_while).code) +""" +def not_depend_tensor_while(x): + a = 1 + + def while_condition_0(a, x): + return a < 10 + + def while_body_0(a, x): + x = x + 1 + a += 1 + return a, x + + [a, x] = paddle.jit.dy2static.convert_while_loop(while_condition_0, + while_body_0, [a, x]) + + return x +""" +``` + + + +示例二:依赖 Tensor 的控制流 + +```python +def depend_tensor_while(x): + bs = paddle.shape(x)[0] + + for i in range(bs): # <---- bas is a Tensor + x = x + 1 + + return x + +print(to_static(depend_tensor_while).code) +""" +def depend_tensor_while(x): + bs = paddle.shape(x)[0] + i = 0 + + def for_loop_condition_0(x, i, bs): + return i < bs + + def for_loop_body_0(x, i, bs): + x = x + 1 + i += 1 + return x, i, bs + + [x, i, bs] = paddle.jit.dy2static.convert_while_loop(for_loop_condition_0, + for_loop_body_0, [x, i, bs]) + return x +""" +``` + + +``convert_while_loop`` 的底层的逻辑同样会根据**判断条件是否为``Variable``**来决定是否转为 ``while_op`` + +## 五、 Parameters 与 Buffers + +**什么是 ``Buffers`` 变量?** + ++ **Parameters**:``persistable`` 为 ``True`` ,且每个 batch 都被 Optimizer 更新的变量 ++ **Buffers**:``persistable`` 为 ``True`` ,``is_trainable = False`` ,不参与更新,但与预测相关;如 ``BatchNorm`` 层中的均值和方差 + +在动态图模型代码中,若一个 ``paddle.to_tensor`` 接口生成的 ``Tensor`` 参与了最终预测结果的的计算,则此 ``Tensor`` 需要在转换为静态图预测模型时,也需要作为一个 ``persistable`` 的变量保存到 ``.pdparam`` 文件中。 + +**举一个例子(错误写法):** + +```python +import paddle +from paddle.jit import to_static + +class SimpleNet(paddle.nn.Layer): + def __init__(self, mask): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + # mask value,此处不会保存到预测模型文件中 + self.mask = mask # 假设为 [0, 1, 1] + + def forward(self, x, y): + out = self.linear(x) + out = out + y + mask = paddle.to_tensor(self.mask) # <----- 每次执行都转为一个 Tensor + out = out * mask + return out +``` + + +**推荐的写法是:** + +```python +class SimpleNet(paddle.nn.Layer): + def __init__(self, mask): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + # 此处的 mask 会当做一个 buffer Tensor,保存到 .pdparam 文件 + self.mask = paddle.to_tensor(mask) # 假设为 [0, 1, 1] + + def forward(self, x, y): + out = self.linear(x) + out = out + y + out = out * self.mask # <---- 直接使用 self.mask + return out +``` + + +总结一下 ``buffers`` 的用法: + ++ 若某个非 ``Tensor`` 数据需要当做 ``Persistable`` 的变量序列化到磁盘,则最好在 ``__init__`` 中调用 ``self.XX= paddle.to_tensor(xx)`` 接口转为 ``buffer`` 变量 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.BoolTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.BoolTensor.md new file mode 100644 index 00000000000..12f1fcc09c4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.BoolTensor.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ] torch.BoolTensor + +### [torch.BoolTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.BoolTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='bool', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'bool'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ByteTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ByteTensor.md new file mode 100644 index 00000000000..e0920c87463 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ByteTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.ByteTensor + +### [torch.ByteTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.ByteTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='uint8', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'uint8'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.DoubleTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.DoubleTensor.md new file mode 100644 index 00000000000..b9a3208d925 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.DoubleTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.DoubleTensor + +### [torch.DoubleTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.DoubleTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float64', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float64'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.FloatTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.FloatTensor.md new file mode 100644 index 00000000000..fd17a906ee4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.FloatTensor.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ] torch.FloatTensor + +### [torch.FloatTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.FloatTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float32', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float32'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.HalfTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.HalfTensor.md new file mode 100644 index 00000000000..5c5c5dd697f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.HalfTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.HalfTensor + +### [torch.HalfTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.HalfTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float16', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float16'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.IntTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.IntTensor.md new file mode 100644 index 00000000000..7a04e0ae881 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.IntTensor.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ] torch.IntTensor + +### [torch.IntTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.IntTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int32', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int32'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.LongTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.LongTensor.md new file mode 100644 index 00000000000..40a291b023e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.LongTensor.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ] torch.LongTensor + +### [torch.LongTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.LongTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int64', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int64'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ShortTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ShortTensor.md new file mode 100644 index 00000000000..ced1c8d2fa4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.ShortTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.ShortTensor + +### [torch.ShortTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.ShortTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int16', place='cpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int16'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tenosr.dtype.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tenosr.dtype.md new file mode 100644 index 00000000000..d916f6f95fb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tenosr.dtype.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.dtype + +### [torch.Tensor.dtype](https://pytorch.org/docs/stable/generated/torch.Tensor.type.html#torch-tensor-type) + +```python +torch.Tensor.dtype +``` + +### [paddle.Tensor.dtype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dtype) + +```python +paddle.Tensor.dtype +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.H.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.H.md new file mode 100644 index 00000000000..0c6954dc3a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.H.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ] torch.Tensor.H + +### [torch.Tensor.H](https://pytorch.org/docs/stable/tensors.html?#torch.Tensor.H) + +```python +torch.Tensor.H +``` + +Paddle 无此 API,需要组合实现。 +PyTorch 中等于 x.transpose(0, 1).conj(),Paddle 中 transpose 参数 perm 为转换后的维度位置。 +该 API 仅针对 2D。 + +### 转写示例 + +```python +# PyTorch 写法 +y = x.H + +# Paddle 写法 +y = x.transpose(perm=[1, 0]).conj() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.T__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.T__upper.md new file mode 100644 index 00000000000..425070aa60d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.T__upper.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.T + +### [torch.Tensor.T](https://pytorch.org/docs/stable/tensors.html#torch.Tensor.T) + +```python +torch.Tensor.T +``` + +### [paddle.Tensor.T](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor) + +```python +paddle.Tensor.T +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs.md new file mode 100644 index 00000000000..2f741a1c093 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.abs + +### [torch.Tensor.abs](https://pytorch.org/docs/stable/generated/torch.Tensor.abs.html#torch.Tensor.abs) + +```python +torch.Tensor.abs() +``` + +### [paddle.Tensor.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#abs-name-none) + +```python +paddle.Tensor.abs() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs_.md new file mode 100644 index 00000000000..1b1612d6950 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.abs_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.abs_ + +### [torch.Tensor.abs_](https://pytorch.org/docs/stable/generated/torch.Tensor.abs_.html) + +```python +torch.Tensor.abs_() +``` + +### [paddle.Tensor.abs_]() + +```python +paddle.Tensor.abs_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.absolute.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.absolute.md new file mode 100644 index 00000000000..576479b0faa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.absolute.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.absolute + +### [torch.Tensor.absolute](https://pytorch.org/docs/stable/generated/torch.Tensor.absolute.html#torch-tensor-absolute) + +```python +torch.Tensor.absolute() +``` + +### [paddle.Tensor.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#abs-name-none) + +```python +paddle.Tensor.abs() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acos_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acos_.md new file mode 100644 index 00000000000..2ee47a6cd4d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acos_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.acos_ + +### [torch.Tensor.acos_](https://pytorch.org/docs/stable/generated/torch.Tensor.acos_.html) + +```python +torch.Tensor.acos_() +``` + +### [paddle.Tensor.acos_]() + +```python +paddle.Tensor.acos_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh.md new file mode 100644 index 00000000000..baf87967dcd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.acosh + +### [torch.Tensor.acosh](https://pytorch.org/docs/stable/generated/torch.Tensor.acosh.html?highlight=acosh#torch.Tensor.acosh) + +```python +torch.Tensor.acosh() +``` + +### [paddle.Tensor.acosh]() + +```python +paddle.Tensor.acosh(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh_.md new file mode 100644 index 00000000000..d9b7acc4078 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.acosh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.acosh_ + +### [torch.Tensor.acosh_](https://pytorch.org/docs/stable/generated/torch.Tensor.acosh_.html) + +```python +torch.Tensor.acosh_() +``` + +### [paddle.Tensor.acosh_]() + +```python +paddle.Tensor.acosh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add.md new file mode 100644 index 00000000000..a83ce1b2664 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.Tensor.add + +### [torch.Tensor.add](https://pytorch.org/docs/stable/generated/torch.Tensor.add.html#torch.Tensor.add) + +```python +torch.Tensor.add(other, *, alpha=1) +``` + +### [paddle.Tensor.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#add-y-name-none) + +```python +paddle.Tensor.add(y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| other | y | 输入的 Tensor,仅参数名不一致。 | +| alpha | - | 表示 other 的乘数,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### alpha:other 的乘数 + +```python +# PyTorch 写法 +y = torch.tensor([3, 5]).add(torch.tensor([2, 3]), alpha=2) + +# Paddle 写法 +y = paddle.to_tensor([3, 5]).add(2 * paddle.to_tensor([2, 3])) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add_.md new file mode 100644 index 00000000000..cd81be5f0e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.add_.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.Tensor.add\_ + +### [torch.Tensor.add\_](https://pytorch.org/docs/stable/generated/torch.Tensor.add_.html#torch.Tensor.add_) + +```python +torch.Tensor.add_(other, *, alpha=1) +``` + +### [paddle.Tensor.add\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id3) + +```python +paddle.Tensor.add_(y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| other | y | 输入的 Tensor,仅参数名不一致。 | +| alpha | - | 表示 other 的乘数,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### alpha:other 的乘数 + +```python +# PyTorch 写法 +torch.tensor([3, 5]).add_(torch.tensor([2, 3]), alpha=2) + +# Paddle 写法 +paddle.to_tensor([3, 5]).add_(2 * paddle.to_tensor([2, 3])) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addbmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addbmm.md new file mode 100644 index 00000000000..f5776672cbb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addbmm.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.Tensor.addbmm + +### [torch.Tensor.addbmm](https://pytorch.org/docs/stable/generated/torch.Tensor.addbmm.html#torch.Tensor.addbmm) + +```python +torch.Tensor.addbmm(batch1, batch2, *, beta=1, alpha=1) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.addbmm(batch1, batch2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.sum(paddle.bmm(batch1, batch2), axis=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcdiv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcdiv.md new file mode 100644 index 00000000000..cb94ea59559 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcdiv.md @@ -0,0 +1,23 @@ +## [ 组合替代实现 ]torch.Tensor.addcdiv + +### [torch.Tensor.addcdiv](https://pytorch.org/docs/stable/generated/torch.Tensor.addcdiv.html#torch.Tensor.addcdiv) + +```python +torch.Tensor.addcdiv(tensor1, tensor2, *, value=1) +``` + +用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相除,再加上输入 `input` ,公式为: + +$ out = input + value * (tensor1 / tensor2) $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.addcdiv(tensor1, tensor2, value=value) + +# Paddle 写法 +y = input + value * tensor1 / tensor2 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcmul.md new file mode 100644 index 00000000000..c7f327ecb12 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addcmul.md @@ -0,0 +1,22 @@ +## [ 组合替代实现 ]torch.Tensor.addcmul + +### [torch.Tensor.addcmul](https://pytorch.org/docs/stable/generated/torch.Tensor.addcmul.html#torch.Tensor.addcmul) +```python +torch.Tensor.addcmul(tensor1, tensor2, *, value=1) +``` + +用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相乘,再加上输入 `input` ,公式为: + +$ out = input + value * tensor1 * tensor2 $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.addcmul(tensor1, tensor2, value=value) + +# Paddle 写法 +y = input + value * tensor1 * tensor2 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm.md new file mode 100644 index 00000000000..3e31dff7d08 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.Tensor.addmm + +### [torch.Tensor.addmm](https://pytorch.org/docs/stable/generated/torch.Tensor.addmm.html) + +```python +torch.Tensor.addmm(mat1, mat2, *, beta=1, alpha=1) +``` + +### [paddle.Tensor.addmm]() + +```python +paddle.Tensor.addmm(x, y, alpha=1.0, beta=1.0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| mat1 | x | 表示输入的 Tensor,仅参数名不一致。 | +| mat2 | y | 表示输入的 Tensor,仅参数名不一致。 | +| beta | beta | 乘以 input 的标量。| +| alpha | alpha | 乘以 x*y 的标量。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm_.md new file mode 100644 index 00000000000..148320a7fa3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmm_.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.Tensor.addmm_ + +### [torch.Tensor.addmm_](https://pytorch.org/docs/stable/generated/torch.Tensor.addmm_.html) + +```python +torch.Tensor.addmm_(mat1, mat2, *, beta=1, alpha=1) +``` + +### [paddle.Tensor.addmm_]() + +```python +paddle.Tensor.addmm_(x, y, alpha=1.0, beta=1.0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| mat1 | x | 表示输入的 Tensor,仅参数名不一致。 | +| mat2 | y | 表示输入的 Tensor,仅参数名不一致。 | +| alpha | alpha | 乘以 x*y 的标量,数据类型支持 float32、float64,默认值为 1.0。| +| beta | beta | 乘以 input 的标量,数据类型支持 float32、float64,默认值为 1.0。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmv.md new file mode 100644 index 00000000000..8f752852f85 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addmv.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.Tensor.addmv + +### [torch.Tensor.addmv](https://pytorch.org/docs/stable/generated/torch.Tensor.addmv.html#torch.Tensor.addmv) +```python +torch.Tensor.addmv(mat, vec, beta=1, alpha=1, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.addmv(mat, vec, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.mm(mat, vec) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addr.md new file mode 100644 index 00000000000..41340c3e235 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.addr.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.addr + +### [torch.Tensor.addr](https://pytorch.org/docs/stable/generated/torch.Tensor.addr.html#torch.Tensor.addr) + +```python +torch.Tensor.addr(vec1, vec2, beta=1, alpha=1) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.addr(vec1, vec2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.outer(vec1, vec2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.adjoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.adjoint.md new file mode 100644 index 00000000000..8c331a1d9c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.adjoint.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.Tensor.adjoint + +### [torch.Tensor.adjoint](https://pytorch.org/docs/stable/generated/torch.Tensor.adjoint.html#torch.Tensor.adjoint) +```python +torch.Tensor.adjoint() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.adjoint() + +# Paddle 写法 +y = paddle.conj(paddle.transpose(input, perm=[0, 2, 1])) + +# 注:假设 input 为 3D Tensor, paddle 需要对 input 的后两维转置。 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.all.md new file mode 100644 index 00000000000..e8aa80a3bc1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.all.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.Tensor.all + +### [torch.Tensor.all](https://pytorch.org/docs/stable/generated/torch.Tensor.all.html?highlight=torch+tensor+all#torch.Tensor.all) + +```python +torch.Tensor.all(dim=None, keepdim=False) +``` + +### [paddle.Tensor.all](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#all-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.all(axis=None, + keepdim=False, + name=None) +``` + +其中 Paddle 与 PyTorch 运算 Tensor 所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| 运算 Tensor | 运算 Tensor | PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写。 | +| dim | axis | 表示运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 | + +### 转写示例 +#### 运算 Tensor:调用类方法的 Tensor +```python +# PyTorch 写法 +y = x.all() + +# Paddle 写法 +y = x.astype('bool').all() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.allclose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.allclose.md new file mode 100644 index 00000000000..88155d7d6c1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.allclose.md @@ -0,0 +1,37 @@ +## [ 参数不一致 ]torch.Tensor.allclose + +### [torch.Tensor.allclose](https://pytorch.org/docs/stable/generated/torch.Tensor.allclose.html) + +```python +torch.Tensor.allclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) +``` + +### [paddle.Tensor.allclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#allclose-y-rtol-1e-05-atol-1e-08-equal-nan-false-name-none) + +```python +paddle.Tensor.allclose(y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,返回类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | -- | +| other | y | 输入 Tensor,仅参数名不一致。 | +| rtol | rtol | 相对容差。 | +| atol | atol | 绝对容差。 | +| equal_nan | equal_nan | 如果设置为 True,则两个 NaN 数值将被视为相等。 | +| 返回值 | 返回值 | PyTorch 返回值为标量, Paddle 返回值 0D Tensor。| + +### 转写示例 + +#### 返回值 + +```python +# PyTorch 写法 +x.allclose(y) + +# Paddle 写法 +x.allclose(y).item() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amax.md new file mode 100644 index 00000000000..6c10d1956b3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amax.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.amax + +### [torch.Tensor.amax](https://pytorch.org/docs/stable/generated/torch.Tensor.amax.html) + +```python +torch.Tensor.amax(dim=None, keepdim=False) +``` + +### [paddle.Tensor.amax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#amax-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.amax(axis=None, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------ | +| dim | axis | 求最大值运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amin.md new file mode 100644 index 00000000000..fc9aa8da9dd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.amin.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.amin + +### [torch.Tensor.amin](https://pytorch.org/docs/stable/generated/torch.Tensor.amin.html) + +```python +torch.Tensor.amin(dim=None, keepdim=False) +``` + +### [paddle.Tensor.amin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#amin-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.amin(axis=None, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------ | +| dim | axis | 求最小值运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.aminmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.aminmax.md new file mode 100644 index 00000000000..ac723d0c8eb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.aminmax.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.Tensor.aminmax + +### [torch.Tensor.aminmax](https://pytorch.org/docs/stable/generated/torch.Tensor.aminmax.html#torch.Tensor.aminmax) + +```python +torch.Tensor.aminmax(*, dim=None, keepdim=False) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +input.aminmax(dim=-1, keepdim=True) + +# Paddle 写法 +y = tuple([paddle.amin(input, axis=-1, keepdim=True), paddle.amax(input, axis=-1, keepdim=True)]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.angle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.angle.md new file mode 100644 index 00000000000..cdf56c127f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.angle.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.angle + +### [torch.Tensor.angle](https://pytorch.org/docs/stable/generated/torch.Tensor.angle.html) + +```python +torch.Tensor.angle() +``` + +### [paddle.Tensor.angle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#angle-name-none) + +```python +paddle.Tensor.angle(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.any.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.any.md new file mode 100644 index 00000000000..23928793ee6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.any.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.Tensor.any + +### [torch.Tensor.any](https://pytorch.org/docs/stable/generated/torch.Tensor.any.html?highlight=torch+tensor+any#torch.Tensor.any) + +```python +torch.Tensor.any(dim=None, keepdim=False) +``` + +### [paddle.Tensor.any](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#any-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.any(axis=None, + keepdim=False, + name=None) +``` + +其中 Paddle 与 PyTorch 运算 Tensor 所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| 运算 Tensor | 运算 Tensor | PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写。 | +| dim | axis | 表示运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 | + +### 转写示例 +#### 运算 Tensor:调用类方法的 Tensor +```python +# PyTorch 写法 +y = x.any() + +# Paddle 写法 +y = x.astype('bool').any() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.apply_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.apply_.md new file mode 100644 index 00000000000..204bf4266c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.apply_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.apply_ +### [torch.Tensor.apply_](https://pytorch.org/docs/stable/generated/torch.Tensor.apply_.html) + +```python +torch.Tensor.apply_(callable) +``` + +### [paddle.Tensor.apply_]() + +```python +paddle.Tensor.apply_(callable) +``` + + +两者功能不同,pytorch 只支持 Inplace 操作,且只对 CPU tensor 才能使用。Paddle 版本可以在 GPU 下运行同时也有 outplace 版本。两者参数一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------|--------------|-----------| +| callable | callable | 一个被调用的函数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos.md new file mode 100644 index 00000000000..90db3a8e878 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arccos + +### [torch.Tensor.arccos](https://pytorch.org/docs/stable/generated/torch.Tensor.arccos.html) + +```python +torch.Tensor.arccos() +``` + +### [paddle.Tensor.acos]() + +```python +paddle.Tensor.acos() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos_.md new file mode 100644 index 00000000000..1287cebc408 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccos_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arccos_ + +### [torch.Tensor.arccos_](https://pytorch.org/docs/stable/generated/torch.Tensor.arccos_.html) + +```python +torch.Tensor.arccos_() +``` + +### [paddle.Tensor.acos_]() + +```python +paddle.Tensor.acos_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh.md new file mode 100644 index 00000000000..ee8ae8c3673 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.arccosh + +### [torch.Tensor.arccosh](https://pytorch.org/docs/stable/generated/torch.Tensor.arccosh.html?highlight=arccosh#torch.Tensor.arccosh) + +```python +torch.Tensor.arccosh() +``` + +### [paddle.Tensor.acosh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/acosh_cn.html#acosh) + +```python +paddle.Tensor.acosh(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh_.md new file mode 100644 index 00000000000..8e4df71b701 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arccosh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arccosh_ + +### [torch.Tensor.arccosh_](https://pytorch.org/docs/stable/generated/torch.Tensor.arccosh_.html) + +```python +torch.Tensor.arccosh_() +``` + +### [paddle.Tensor.acosh_]() + +```python +paddle.Tensor.acosh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin.md new file mode 100644 index 00000000000..b55a58f780d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arcsin + +### [torch.Tensor.arcsin](https://pytorch.org/docs/stable/generated/torch.Tensor.arcsin.html) + +```python +torch.Tensor.arcsin() +``` + +### [paddle.Tensor.arcsin]() + +```python +paddle.Tensor.arcsin() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin_.md new file mode 100644 index 00000000000..5b3aad6d5d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsin_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arcsin_ + +### [torch.Tensor.arcsin_](https://pytorch.org/docs/stable/generated/torch.Tensor.arcsin_.html) + +```python +torch.Tensor.arcsin_() +``` + +### [paddle.Tensor.asin_]() + +```python +paddle.Tensor.asin_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh.md new file mode 100644 index 00000000000..3cf89877718 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.arcsinh + +### [torch.Tensor.arcsinh](https://pytorch.org/docs/stable/generated/torch.Tensor.arcsinh) + +```python +torch.Tensor.arcsinh() +``` + +### [paddle.Tensor.asinh]() + +```python +paddle.Tensor.asinh() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh_.md new file mode 100644 index 00000000000..d49ec7a110c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arcsinh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arcsinh_ + +### [torch.Tensor.arcsinh_](https://pytorch.org/docs/stable/generated/torch.Tensor.arcsinh_.html) + +```python +torch.Tensor.arcsinh_() +``` + +### [paddle.Tensor.asinh_]() + +```python +paddle.Tensor.asinh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan.md new file mode 100644 index 00000000000..8bea6a95b93 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.arctan + +### [torch.Tensor.arctan](https://pytorch.org/docs/stable/generated/torch.Tensor.arctan.html) + +```python +torch.Tensor.arctan() +``` + +### [paddle.Tensor.arctan]() + +```python +paddle.Tensor.arctan() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan2.md new file mode 100644 index 00000000000..7d078eb4f0b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan2.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.arctan2 + +### [torch.Tensor.arctan2](https://pytorch.org/docs/stable/generated/torch.arctan2.html#torch.arctan2) + +```python +torch.Tensor.arctan2(other) +``` + +### [paddle.Tensor.atan2]() + +```python +paddle.Tensor.atan2(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan_.md new file mode 100644 index 00000000000..5c5a08969a1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctan_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arctan_ + +### [torch.Tensor.arctan_](https://pytorch.org/docs/stable/generated/torch.Tensor.arctan_.html) + +```python +torch.Tensor.arctan_() +``` + +### [paddle.Tensor.atan_]() + +```python +paddle.Tensor.atan_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md new file mode 100644 index 00000000000..f3da848166e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arctanh + +### [torch.Tensor.arctanh](https://pytorch.org/docs/stable/generated/torch.Tensor.arctanh.html#torch.Tensor.arctanh) + +```python +torch.Tensor.arctanh() +``` + +### [paddle.Tensor.atanh]() + +```python +paddle.Tensor.atanh() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md new file mode 100644 index 00000000000..74279293b62 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.arctanh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.arctanh_ + +### [torch.Tensor.arctanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.arctanh_.html) + +```python +torch.Tensor.arctanh_() +``` + +### [paddle.Tensor.atanh_]() + +```python +paddle.Tensor.atanh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmax.md new file mode 100644 index 00000000000..3d8efe05b8b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmax.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.argmax + +### [torch.Tensor.argmax](https://pytorch.org/docs/stable/generated/torch.Tensor.argmax.html) + +```python +torch.Tensor.argmax(dim=None, keepdim=False) +``` + +### [paddle.Tensor.argmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#argmax-axis-none-keepdim-false-dtype-int64-name-none) + +```python +paddle.Tensor.argmax(axis=None, keepdim=False, dtype=int64, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| - | dtype | 指定返回类型,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmin.md new file mode 100644 index 00000000000..9445d4f67a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argmin.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.argmin + +### [torch.Tensor.argmin](https://pytorch.org/docs/stable/generated/torch.Tensor.argmin.html) + +```python +torch.Tensor.argmin(dim=None, keepdim=False) +``` + +### [paddle.Tensor.argmin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#argmin-axis-none-keepdim-false-dtype-int64-name-none) + +```python +paddle.Tensor.argmin(axis=None, keepdim=False, dtype=int64, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argsort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argsort.md new file mode 100644 index 00000000000..c7297688930 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argsort.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.argsort + +### [torch.Tensor.argsort](https://pytorch.org/docs/stable/generated/torch.Tensor.argsort.html) + +```python +torch.Tensor.argsort(dim=-1, descending=False) +``` + +### [paddle.Tensor.argsort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#argsort-axis-1-descending-false-name-none) + +```python +paddle.Tensor.argsort(axis=-1, descending=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| descending | descending | 指定算法排序的方向。如果设置为 True,算法按照降序排序。如果设置为 False 或者不设置,按照升序排序。默认值为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argwhere.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argwhere.md new file mode 100644 index 00000000000..668dc9236df --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.argwhere.md @@ -0,0 +1,20 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.argwhere +### [torch.Tensor.argwhere](https://pytorch.org/docs/stable/generated/torch.Tensor.argwhere.html#torch.Tensor.argwhere) + +```python +torch.Tensor.argwhere() +``` + +### [paddle.Tensor.nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#nonzero-as-tuple-false) + +```python +paddle.Tensor.nonzero(as_tuple=False) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| - | as_tuple | 返回格式。是否以 1-D Tensor 构成的元组格式返回。 PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.as_strided.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.as_strided.md new file mode 100644 index 00000000000..4993959e973 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.as_strided.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.Tensor.as_strided +### [torch.Tensor.as_strided](https://pytorch.org/docs/stable/generated/torch.Tensor.as_strided.html?highlight=as_strided#torch.Tensor.as_strided) + +```python +torch.Tensor.as_strided(size, + stride, + storage_offset=None) +``` + +### [paddle.Tensor.as_strided](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#as-strided-x-shape-stride-offset-0-name-none) + +```python +paddle.Tensor.as_strided(shape, + stride, + offset=0, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | shape | 表示输出 Tensor 的维度, 仅参数名不一致。 | +| stride | stride | 表示输出 Tensor 的 stride。 | +| storage_offset | offset | 表示偏移量, 仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asin_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asin_.md new file mode 100644 index 00000000000..7ed8422423e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asin_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.asin_ + +### [torch.Tensor.asin_](https://pytorch.org/docs/stable/generated/torch.Tensor.asin_.html) + +```python +torch.Tensor.asin_() +``` + +### [paddle.Tensor.asin_]() + +```python +paddle.Tensor.asin_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh.md new file mode 100644 index 00000000000..f8c9859ff6a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.asinh + +### [torch.Tensor.asinh](https://pytorch.org/docs/stable/generated/torch.Tensor.asinh) + +```python +torch.Tensor.asinh() +``` + +### [paddle.Tensor.asinh]() + +```python +paddle.Tensor.asinh() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh_.md new file mode 100644 index 00000000000..ebba6f478c5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.asinh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.asinh_ + +### [torch.Tensor.asinh_](https://pytorch.org/docs/stable/generated/torch.Tensor.asinh_) + +```python +torch.Tensor.asinh_() +``` + +### [paddle.Tensor.asinh_]() + +```python +paddle.Tensor.asinh_() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atan_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atan_.md new file mode 100644 index 00000000000..1e873f7afa1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atan_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.atan_ + +### [torch.Tensor.atan_](https://pytorch.org/docs/stable/generated/torch.Tensor.atan_.html) + +```python +torch.Tensor.atan_() +``` + +### [paddle.Tensor.atan_]() + +```python +paddle.Tensor.atan_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md new file mode 100644 index 00000000000..5489807bbc2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.atanh + +### [torch.Tensor.atanh](https://pytorch.org/docs/stable/generated/torch.Tensor.atanh.html#torch.Tensor.atanh) + +```python +torch.Tensor.atanh() +``` + +### [paddle.Tensor.atanh]() + +```python +paddle.Tensor.atanh() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md new file mode 100644 index 00000000000..8e7f20a39ee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.atanh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.atanh_ + +### [torch.Tensor.atanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.atanh_.html#torch.Tensor.atanh_) + +```python +torch.Tensor.atanh_() +``` + +### [paddle.Tensor.atanh_]() + +```python +paddle.Tensor.atanh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.backward.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.backward.md new file mode 100644 index 00000000000..fa34837d8ff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.backward.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ] torch.Tensor.backward + +### [torch.Tensor.backward](https://pytorch.org/docs/stable/generated/torch.Tensor.backward.html#torch.Tensor.backward) + +```python +torch.Tensor.backward(gradient=None, retain_graph=None, create_graph=False, inputs=None) +``` + +### [paddle.Tensor.backward](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#backward-grad-tensor-none-retain-graph-false) + +```python +paddle.Tensor.backward(grad_tensor=None, retain_graph=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| gradient | grad_tensor | 当前 Tensor 的初始梯度值。仅参数名不一致。 | +| retain_graph | retain_graph | 是否保留计算图。 | +| create_graph | - | 是否创建梯度图,Paddle 无此参数,暂无转写方式。 | +| inputs | - | 计算的起始输入 tensor,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.baddbmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.baddbmm.md new file mode 100644 index 00000000000..89e106788e3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.baddbmm.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.Tensor.baddbmm + +### [torch.Tensor.baddbmm](https://pytorch.org/docs/stable/generated/torch.Tensor.baddbmm.html#torch.Tensor.baddbmm) + +```python +torch.Tensor.baddbmm(batch1, batch2, beta=1, alpha=1) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.baddbmm(batch1, batch2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.bmm(batch1, batch2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md new file mode 100644 index 00000000000..9cd8cb8393e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.Tensor.bernoulli + +### [torch.Tensor.bernoulli](https://pytorch.org/docs/stable/generated/torch.Tensor.bernoulli.html#torch.Tensor.bernoulli) + +```python +torch.Tensor.bernoulli(*, generator=None) +``` + +### [paddle.Tensor.bernoulli]() + +```python +paddle.Tensor.bernoulli(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([0.2, 0.6, 0.8]) +y = x.bernoulli() + +# paddle 写法 +x = paddle.to_tensor([0.2, 0.6, 0.8]) +y = x.bernoulli() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli_.md new file mode 100644 index 00000000000..d944e47c0ae --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bernoulli_.md @@ -0,0 +1,28 @@ +## [ 组合替代实现 ]torch.Tensor.bernoulli_ + +### [torch.Tensor.bernoulli_](https://pytorch.org/docs/stable/generated/torch.Tensor.bernoulli_.html#torch.Tensor.bernoulli_) + +```python +torch.Tensor.bernoulli_(p=0.5, *, generator=None) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 +#### p:输入概率,类型为 tensor 时 +```python +# PyTorch 写法 +input.bernoulli_(p=x) + +# Paddle 写法 +paddle.assign(paddle.bernoulli(paddle.broadcast_to(x, input.shape)), input) +``` + +#### p:输入概率,类型为 float 时 +```python +# PyTorch 写法 +input.bernoulli_(p=x) + +# Paddle 写法 +tensor = paddle.to_tensor([x]) +paddle.assign(paddle.bernoulli(paddle.broadcast_to(tensor, input.shape)), input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md new file mode 100644 index 00000000000..f5e0c40ab27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bfloat16.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.bfloat16 + +### [torch.Tensor.bfloat16](https://pytorch.org/docs/stable/generated/torch.Tensor.bfloat16.html#torch.Tensor.bfloat16) + +```python +torch.Tensor.bfloat16(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('bfloat16') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bincount.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bincount.md new file mode 100644 index 00000000000..9dea4341dbf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bincount.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.Tensor.bincount + +### [torch.Tensor.bincount](https://pytorch.org/docs/stable/generated/torch.Tensor.bincount.html) + +```python +torch.Tensor.bincount(weights=None, minlength=0) +``` + +### [paddle.Tensor.bincount](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#bincount-weights-none-minlength-0) + +```python +paddle.Tensor.bincount(weights=None, minlength=0) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | -- | +| weights | weights | 输入 Tensor 中每个元素的权重。 | +| minlength | minlength | 输出 Tensor 的最小长度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and.md new file mode 100644 index 00000000000..6c0e4f56349 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_and + +### [torch.Tensor.bitwise_and](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_and.html) + +```python +torch.Tensor.bitwise_and(other) +``` + +### [paddle.Tensor.bitwise_and]() + +```python +paddle.Tensor.bitwise_and(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and_.md new file mode 100644 index 00000000000..63ca084a097 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_and_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_and_ + +### [torch.Tensor.bitwise_and_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_and_.html) + +```python +torch.Tensor.bitwise_and_(other) +``` + +### [paddle.Tensor.bitwise_and_]() + +```python +paddle.Tensor.bitwise_and_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not.md new file mode 100644 index 00000000000..fc3f4b62ec3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.bitwise_not + +### [torch.Tensor.bitwise_not](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_not.html) + +```python +torch.Tensor.bitwise_not() +``` + +### [paddle.Tensor.bitwise_not]() + +```python +paddle.Tensor.bitwise_not() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not_.md new file mode 100644 index 00000000000..9f584e77d3d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_not_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.bitwise_not_ + +### [torch.Tensor.bitwise_not_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_not_.html) + +```python +torch.Tensor.bitwise_not_() +``` + +### [paddle.Tensor.bitwise_not_]() + +```python +paddle.Tensor.bitwise_not_() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or.md new file mode 100644 index 00000000000..b7c92cbb19f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_or + +### [torch.Tensor.bitwise_or](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_or.html) + +```python +torch.Tensor.bitwise_or(other) +``` + +### [paddle.Tensor.bitwise_or]() + +```python +paddle.Tensor.bitwise_or(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or_.md new file mode 100644 index 00000000000..11d24e17291 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_or_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_or_ + +### [torch.Tensor.bitwise_or_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_or_.html) + +```python +torch.Tensor.bitwise_or_(other) +``` + +### [paddle.Tensor.bitwise_or_]() + +```python +paddle.Tensor.bitwise_or_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor.md new file mode 100644 index 00000000000..165c3fb3bd0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_xor + +### [torch.Tensor.bitwise_xor](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_xor.html) + +```python +torch.Tensor.bitwise_xor(other) +``` + +### [paddle.Tensor.bitwise_xor]() + +```python +paddle.Tensor.bitwise_xor(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor_.md new file mode 100644 index 00000000000..83bee8b1b0d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bitwise_xor_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bitwise_xor_ + +### [torch.Tensor.bitwise_xor_](https://pytorch.org/docs/stable/generated/torch.Tensor.bitwise_xor_.html) + +```python +torch.Tensor.bitwise_xor_(other) +``` + +### [paddle.Tensor.bitwise_xor_]() + +```python +paddle.Tensor.bitwise_xor_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bmm.md new file mode 100644 index 00000000000..966a3056e5c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bmm.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.bmm + +### [torch.Tensor.bmm](https://pytorch.org/docs/stable/generated/torch.Tensor.bmm.html) + +```python +torch.Tensor.bmm(mat2) +``` + +### [paddle.Tensor.bmm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#bmm-y-name-none) + +```python +paddle.Tensor.bmm(y, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| mat2 | y | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md new file mode 100644 index 00000000000..fc2df0abf10 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.bool.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.bool + +### [torch.Tensor.bool](https://pytorch.org/docs/stable/generated/torch.Tensor.bool.html#torch.Tensor.bool) + +```python +torch.Tensor.bool(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('bool') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.broadcast_to.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.broadcast_to.md new file mode 100644 index 00000000000..b4e0fb9b997 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.broadcast_to.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.broadcast_to + +### [torch.Tensor.broadcast\_to](https://pytorch.org/docs/stable/generated/torch.Tensor.broadcast_to.html) + +```python +torch.Tensor.broadcast_to(size) +``` + +### [paddle.Tensor.broadcast\_to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#broadcast-to-shape-name-none) + +```python +paddle.Tensor.broadcast_to(shape, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| size | shape | 给定输入 x 扩展后的形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md new file mode 100644 index 00000000000..8692fe861f0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.byte.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.byte + +### [torch.Tensor.byte](https://pytorch.org/docs/stable/generated/torch.Tensor.byte.html#torch.Tensor.byte) + +```python +torch.Tensor.byte(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('uint8') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cdouble.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cdouble.md new file mode 100644 index 00000000000..761a765f2c9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cdouble.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.Tensor.cdouble + +### [torch.Tensor.cdouble](https://pytorch.org/docs/stable/generated/torch.Tensor.cdouble.html?highlight=torch+tensor+cdouble#torch.Tensor.cdouble) + +```python +torch.Tensor.cdouble(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('complex128') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil.md new file mode 100644 index 00000000000..a339165042b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.ceil + +### [torch.Tensor.ceil](https://pytorch.org/docs/stable/generated/torch.Tensor.ceil.html) + +```python +torch.Tensor.ceil() +``` + +### [paddle.Tensor.ceil](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#ceil-name-none) + +```python +paddle.Tensor.ceil(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil_.md new file mode 100644 index 00000000000..5a4f8382bee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ceil_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.ceil_ + +### [torch.Tensor.ceil\_](https://pytorch.org/docs/stable/generated/torch.Tensor.ceil_.html) + +```python +torch.Tensor.ceil_() +``` + +### [paddle.Tensor.ceil\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id7) + +```python +paddle.Tensor.ceil_(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cfloat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cfloat.md new file mode 100644 index 00000000000..c78f9be3273 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cfloat.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.Tensor.cfloat + +### [torch.Tensor.cfloat](https://pytorch.org/docs/stable/generated/torch.Tensor.cfloat.html?highlight=torch+tensor+cfloat#torch.Tensor.cfloat) + +```python +torch.Tensor.cfloat(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('complex64') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md new file mode 100644 index 00000000000..ae1841b49b2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.char.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.char + +### [torch.Tensor.char](https://pytorch.org/docs/stable/generated/torch.Tensor.char.html#torch.Tensor.char) + +```python +torch.Tensor.char(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('int8') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky.md new file mode 100644 index 00000000000..bc8687baebd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.cholesky + +### [torch.Tensor.cholesky](https://pytorch.org/docs/stable/generated/torch.Tensor.cholesky.html) + +```python +torch.Tensor.cholesky(upper=False) +``` + +### [paddle.Tensor.cholesky](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cholesky-upper-false-name-none) + +```python +paddle.Tensor.cholesky(upper=False, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| upper | upper | 指示是否返回上三角矩阵或下三角矩阵。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_inverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_inverse.md new file mode 100644 index 00000000000..015f522b432 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_inverse.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ]torch.Tensor.cholesky_inverse + +### [torch.Tensor.cholesky_inverse](https://pytorch.org/docs/stable/generated/torch.cholesky_inverse.html#torch.cholesky_inverse) +```python +torch.Tensor.cholesky_inverse(upper=False) +``` + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +```python +# PyTorch 写法 +y = u.cholesky_inverse(upper) + +# Python 写法 +ut = paddle.transpose(u, perm=[1, 0]) +if upper: + y = paddle.linalg.inv(paddle.matmul(ut, u)) +else: + y = paddle.inverse(paddle.matmul(u, ut)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_solve.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_solve.md new file mode 100644 index 00000000000..e84e60e32ed --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cholesky_solve.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.cholesky_solve + +### [torch.Tensor.cholesky_solve](https://pytorch.org/docs/stable/generated/torch.Tensor.cholesky_solve.html#torch-tensor-cholesky-solve) + +```python +torch.Tensor.cholesky_solve(input2, upper=False) +``` + +### [paddle.Tensor.cholesky_solve]() + +```python +paddle.Tensor.cholesky_solve(y, upper=False, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------- | +| input2 | y | 表示线性方程中 A 矩阵的 Cholesky 分解矩阵 u。仅参数名不一致。 | +| upper | upper | 表示输入 x 是否是上三角矩阵,True 为上三角矩阵,False 为下三角矩阵。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.chunk.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.chunk.md new file mode 100644 index 00000000000..b863d198058 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.chunk.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.Tensor.chunk + +### [torch.Tensor.chunk](https://pytorch.org/docs/stable/generated/torch.Tensor.chunk.html?highlight=chunk#torch.Tensor.chunk) + +```python +torch.Tensor.chunk(chunks, dim=0) +``` + +### [paddle.Tensor.chunk](paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#chunk-chunks-axis-0-name-none) + +```python +paddle.Tensor.chunk(chunks, axis=0, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|------------| ------------ | ------------------------------------------------------ | +| chunks | chunks | 表示将输入 Tensor 划分成多少个相同大小的子 Tensor。 | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp.md new file mode 100644 index 00000000000..4208b04e294 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.clamp + +### [torch.Tensor.clamp](https://pytorch.org/docs/stable/generated/torch.Tensor.clamp.html?highlight=clamp#torch.Tensor.clamp) + +```python +torch.Tensor.clamp(min=None, max=None) +``` + +### [paddle.Tensor.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#clip-min-none-max-none-name-none) + +```python +paddle.Tensor.clip(min=None, max=None, name=None) +``` + +两者功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| min | min | 裁剪的最小值,输入中小于该值的元素将由该元素代替。 | +| max | max | 裁剪的最大值,输入中大于该值的元素将由该元素代替。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp_.md new file mode 100644 index 00000000000..aa17b4657b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clamp_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.clamp_ + +### [torch.Tensor.clamp_](https://pytorch.org/docs/stable/generated/torch.Tensor.clamp_.html?highlight=clamp_#torch.Tensor.clamp_) + +```python +torch.Tensor.clamp_(min=None, max=None) +``` + +### [paddle.Tensor.clip_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id6) + +```python +paddle.Tensor.clip_(min=None, max=None, name=None) +``` + +两者功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|---------------------------| +| min | min | 裁剪的最小值,输入中小于该值的元素将由该元素代替。 | +| max | max | 裁剪的最大值,输入中大于该值的元素将由该元素代替。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip.md new file mode 100644 index 00000000000..d4d5dd45fbd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.clip + +### [torch.Tensor.clip](https://pytorch.org/docs/stable/generated/torch.Tensor.clip.html?highlight=clip#torch.Tensor.clip) + +```python +torch.Tensor.clip(min=None, max=None) +``` + +### [paddle.Tensor.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#clip-min-none-max-none-name-none) + +```python +paddle.Tensor.clip(min=None, max=None, name=None) +``` + +两者功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| min | min | 裁剪的最小值,输入中小于该值的元素将由该元素代替。 | +| max | max | 裁剪的最大值,输入中大于该值的元素将由该元素代替。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip_.md new file mode 100644 index 00000000000..3ccde9df1e8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clip_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.clip_ + +### [torch.Tensor.clip_](https://pytorch.org/docs/stable/generated/torch.Tensor.clip_.html?highlight=clip_#torch.Tensor.clip_) + +```python +torch.Tensor.clip_(min=None, max=None) +``` + +### [paddle.Tensor.clip_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id6) + +```python +paddle.Tensor.clip_(min=None, max=None, name=None) +``` + +两者功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|---------------------------| +| min | min | 裁剪的最小值,输入中小于该值的元素将由该元素代替。 | +| max | max | 裁剪的最大值,输入中大于该值的元素将由该元素代替。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md new file mode 100644 index 00000000000..c5c32fa46ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.clone.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.clone + +### [torch.Tensor.clone](https://pytorch.org/docs/stable/generated/torch.Tensor.clone.html#torch.Tensor.clone) + +```python +torch.Tensor.clone(*, memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.clone](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#clone) + +```python +paddle.Tensor.clone() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.coalesce.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.coalesce.md new file mode 100644 index 00000000000..28c6e9fc8d4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.coalesce.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.coalesce + +### [torch.Tensor.coalesce](https://pytorch.org/docs/stable/generated/torch.Tensor.coalesce.html#torch-tensor-coalesce) + +```python +torch.Tensor.coalesce() +``` + +### [paddle.Tensor.coalesce](https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/Tensor/coalesce_en.html) + +```python +paddle.Tensor.coalesce(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj.md new file mode 100644 index 00000000000..d65a19fb1db --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.conj + +### [torch.Tensor.conj](https://pytorch.org/docs/stable/generated/torch.Tensor.conj.html?highlight=conj#torch.Tensor.conj) + +```python +torch.Tensor.conj() +``` + +### [paddle.Tensor.conj](paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#conj-name-none) + +```python +paddle.Tensor.conj(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj_physical.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj_physical.md new file mode 100644 index 00000000000..cdb7ccea165 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.conj_physical.md @@ -0,0 +1,14 @@ +## [无参数]torch.Tensor.conj_physical +### [torch.Tensor.conj_physical](https://pytorch.org/docs/stable/generated/torch.Tensor.conj_physical.html#torch.Tensor.conj_physical) + +```python +torch.Tensor.conj_physical() +``` + +### [paddle.Tensor.conj](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#conj-name-none) + +```python +paddle.Tensor.conj(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.contiguous.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.contiguous.md new file mode 100644 index 00000000000..311475f7d82 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.contiguous.md @@ -0,0 +1,9 @@ +## [ 可删除 ] torch.Tensor.contiguous + +### [torch.Tensor.contiguous](https://pytorch.org/docs/stable/generated/torch.Tensor.contiguous.html) + +```python +torch.Tensor.contiguous(memory_format=torch.contiguous_format) +``` + +判断 Tensor 是否是 contiguous 的,PaddlePaddle 的 Tensor 默认是 contiguous 的, 因此可直接删除该 API。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md new file mode 100644 index 00000000000..a07a4e059ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.copy_.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ] torch.Tensor.copy_ + +### [torch.Tensor.copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.copy_.html#torch.Tensor.copy_) + +```python +torch.Tensor.copy_(src, non_blocking=False) +``` + +### [paddle.assign](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/assign_cn.html#assign) + +```python +paddle.assign(x, output=None) +``` + +两者功能类似,torch 参数多,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| src | x | 待复制的 tensor,仅参数名不一致。 | +| non_blocking | - | 用于控制 cpu 和 gpu 数据的异步复制。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | output | 输出 Tensor,PyTorch 无此参数,Paddle 需将其设置为调用 copy_类方法的 Tensor 。 | + + +### 转写示例 + +```python +# torch 写法 +y.copy_(x) + +# paddle 写法 +paddle.assign(x, output=y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.corrcoef.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.corrcoef.md new file mode 100644 index 00000000000..53165ee5aab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.corrcoef.md @@ -0,0 +1,21 @@ +## [仅 paddle 参数更多]torch.Tensor.corrcoef + +### [torch.Tensor.corrcoef](https://pytorch.org/docs/stable/generated/torch.Tensor.corrcoef.html#torch.Tensor.corrcoef) + +```python +torch.Tensor.corrcoef() +``` + +### [paddle.Tensor.corrcoef]() + +```python +paddle.Tensor.corrcoef(rowvar=True) +``` + +仅 paddle 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------------- | +| - | rowvar | 以行或列作为一个观测变量,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos.md new file mode 100644 index 00000000000..7fa2ad9d0e7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.cos + +### [torch.Tensor.cos](https://pytorch.org/docs/stable/generated/torch.Tensor.cos.html?highlight=cos#torch.Tensor.cos) + +```python +torch.Tensor.cos() +``` + +### [paddle.Tensor.cos](paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#cos-name-none) + +```python +paddle.Tensor.cos(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos_.md new file mode 100644 index 00000000000..de11597e90f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cos_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.cos_ + +### [torch.Tensor.cos_](https://pytorch.org/docs/stable/generated/torch.Tensor.cos_.html) + +```python +torch.Tensor.cos_() +``` + +### [paddle.Tensor.cos_]() + +```python +paddle.Tensor.cos_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh.md new file mode 100644 index 00000000000..ba796782f6f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.cosh + +### [torch.Tensor.cosh](https://pytorch.org/docs/stable/generated/torch.Tensor.cosh.html?highlight=cosh#torch.Tensor.cosh) + +```python +torch.Tensor.cosh() +``` + +### [paddle.Tensor.cosh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cosh-name-none) + +```python +paddle.Tensor.cosh(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh_.md new file mode 100644 index 00000000000..379f2cd21de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cosh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.cosh_ + +### [torch.Tensor.cosh_](https://pytorch.org/docs/stable/generated/torch.Tensor.cosh_.html) + +```python +torch.Tensor.cosh_() +``` + +### [paddle.Tensor.cosh_]() + +```python +paddle.Tensor.cosh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.count_nonzero.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.count_nonzero.md new file mode 100644 index 00000000000..24df4729f2c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.count_nonzero.md @@ -0,0 +1,21 @@ +## [仅 paddle 参数更多]torch.Tensor.count_nonzero +### [torch.Tensor.count_nonzero](https://pytorch.org/docs/stable/generated/torch.Tensor.count_nonzero.html#torch.Tensor.count_nonzero) + +```python +torch.Tensor.count_nonzero(dim=None) +``` + +### [paddle.Tensor.count_nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#count-nonzero-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.count_nonzero(axis=None, keepdim=False, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| - | keepdim | 是否在输出 Tensor 中保留减小的维度, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cov.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cov.md new file mode 100644 index 00000000000..f2ded12b6e9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cov.md @@ -0,0 +1,27 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.cov +### [torch.Tensor.cov](https://pytorch.org/docs/stable/generated/torch.Tensor.cov.html#torch.Tensor.cov) + +```python +torch.Tensor.cov(*, correction=1, fweights=None, aweights=None) +``` + +### [paddle.Tensor.cov]() + +```python +paddle.Tensor.cov(rowvar=True, + ddof=True, + fweights=None, + aweights=None, + name=None) +``` + +仅 paddle 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| correction | ddof | 样本量和样本自由度之间的差异, 若为 True ,返回无偏估计结果;若为 False ,返回普通平均值计算结果。 | +| fweights | fweights | 表示每一个观测向量的重复次数。 | +| aweights | aweights | 表示每一个观测向量的重要性。 | +| - | rowvar | 以行或列作为一个观测变量, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cpu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cpu.md new file mode 100644 index 00000000000..6d46abff064 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cpu.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.Tensor.cpu + +### [torch.Tensor.cpu](https://pytorch.org/docs/stable/generated/torch.Tensor.cpu.html?highlight=torch+tensor+cpu#torch.Tensor.cpu) + +```python +torch.Tensor.cpu(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.cpu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cpu) + +```python +paddle.Tensor.cpu() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cross.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cross.md new file mode 100644 index 00000000000..aa392a05f23 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cross.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.cross + +### [torch.Tensor.cross](https://pytorch.org/docs/stable/generated/torch.Tensor.cross.html?highlight=cross#torch.Tensor.cross) + +```python +torch.Tensor.cross(other, dim=None) +``` + +### [paddle.Tensor.cross](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cross-y-axis-none-name-none) + +```python +paddle.Tensor.cross(y, axis=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | +| dim | axis | 沿此维度进行向量积操作,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md new file mode 100644 index 00000000000..0504298c46f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cuda.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.Tensor.cuda + +### [torch.Tensor.cuda](https://pytorch.org/docs/stable/generated/torch.Tensor.cuda.html#torch.Tensor.cuda) + +```python +torch.Tensor.cuda(device=None, non_blocking=False, memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.cuda](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cuda-device-id-none-blocking-false) + +```python +paddle.Tensor.cuda(device_id=None, blocking=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------------------ | +| device | device_id | 目标 GPU 设备,仅参数名不一致。 | +| non_blocking | blocking | 是否同步或异步拷贝,PyTorch 和 Paddle 取值相反,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummax.md new file mode 100644 index 00000000000..cc6d2596d4e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummax.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.cummax + +### [torch.Tensor.cummax](https://pytorch.org/docs/stable/generated/torch.Tensor.cummax.html?highlight=cummax#torch.Tensor.cummax) + +```python +torch.Tensor.cummax(dim) +``` + +### [paddle.Tensor.cummax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cummax-x-axis-none-dtype-int64-name-none) + +```python +paddle.Tensor.cummax(axis=None, dtype=None, name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| dim | axis | 需要累加的维度,仅参数名不一致。 | +| - | dtype | 输出 Tensor 的数据类型。PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummin.md new file mode 100644 index 00000000000..c60aa4e25bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cummin.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.cummin + +### [torch.Tensor.cummin](https://pytorch.org/docs/stable/generated/torch.Tensor.cummin.html?highlight=cummin#torch.Tensor.cummin) + +```python +torch.Tensor.cummin(dim) +``` + +### [paddle.Tensor.cummin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cummin-x-axis-none-dtype-int64-name-none) + +```python +paddle.Tensor.cummin(axis=None, dtype=None, name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| dim | axis | 需要累加的维度,仅参数名不一致。 | +| - | dtype | 输出 Tensor 的数据类型。PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod.md new file mode 100644 index 00000000000..099c3c8b559 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.Tensor.cumprod + +### [torch.Tensor.cumprod](https://pytorch.org/docs/stable/generated/torch.Tensor.cumprod.html?highlight=cumprod#torch.Tensor.cumprod) + +```python +torch.Tensor.cumprod(dim, dtype=None) +``` + +### [paddle.Tensor.cumprod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cumprod_cn.html#cumprod) + +```python +paddle.Tensor.cumprod(dim=None, dtype=None, name=None) +``` + +两者功能一致且参数用法一致, 具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------------------------------------------- | +| dim | dim | 指明需要累乘的维度。 | +| dtype | dtype | 返回张量所需的数据类型。dtype 如果指定,则在执行操作之前将输入张量转换为指定的 dtype,这对于防止数据类型溢出很有用。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod_.md new file mode 100644 index 00000000000..59a6d5a500e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumprod_.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.Tensor.cumprod_ + +### [torch.Tensor.cumprod_](https://pytorch.org/docs/stable/generated/torch.Tensor.cumprod_.html) + +```python +torch.Tensor.cumprod_(dim, *, dtype=None) +``` + +### [paddle.Tensor.cumprod_]() + +```python +paddle.Tensor.cumprod_(dim=None, dtype=None) +``` + +两者功能一致且参数用法一致, 具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------------------------------------------- | +| dim | dim | 指明需要累乘的维度。 | +| dtype | dtype | 返回张量所需的数据类型。dtype 如果指定,则在执行操作之前将输入张量转换为指定的 dtype,这对于防止数据类型溢出很有用。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum.md new file mode 100644 index 00000000000..839c4143e39 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.cumsum + +### [torch.Tensor.cumsum](https://pytorch.org/docs/stable/generated/torch.Tensor.cumsum.html?highlight=cumsum#torch.Tensor.cumsum) + +```python +torch.Tensor.cumsum(dim, dtype=None) +``` + +### [paddle.Tensor.cumsum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#cumsum-axis-none-dtype-none-name-none) + +```python +paddle.Tensor.cumsum(axis=None, dtype=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| dim | axis | 需要累加的维度,仅参数名不一致。 | +| dtype | dtype | 输出 Tensor 的数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum_.md new file mode 100644 index 00000000000..188fd423774 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.cumsum_.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.cumsum_ + +### [torch.Tensor.cumsum_](https://pytorch.org/docs/stable/generated/torch.Tensor.cumsum_.html) + +```python +torch.Tensor.cumsum_(dim, dtype=None) +``` + +### [paddle.Tensor.cumsum_]() + +```python +paddle.Tensor.cumsum_(axis=None, dtype=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| dim | axis | 需要累加的维度,仅参数名不一致。 | +| dtype | dtype | 输出 Tensor 的数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.deg2rad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.deg2rad.md new file mode 100644 index 00000000000..9eeb45e7625 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.deg2rad.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.deg2rad + +### [torch.Tensor.deg2rad](https://pytorch.org/docs/stable/generated/torch.Tensor.deg2rad.html?highlight=deg2rad#torch.Tensor.deg2rad) + +```python +torch.Tensor.deg2rad() +``` + +### [paddle.Tensor.deg2rad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#deg2rad-x-name-none) + +```python +paddle.Tensor.deg2rad(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.det.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.det.md new file mode 100644 index 00000000000..74f06706c3e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.det.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.det + +### [torch.Tensor.det](https://pytorch.org/docs/stable/generated/torch.Tensor.det.html?highlight=det#torch.Tensor.det) + +```python +torch.Tensor.det() +``` + +### [paddle.Tensor.det]() + +```python +paddle.Tensor.det(name=None) +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach.md new file mode 100644 index 00000000000..ed4eb65bd99 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.detach + +### [torch.Tensor.detach](https://pytorch.org/docs/stable/generated/torch.Tensor.detach.html?highlight=detach#torch.Tensor.detach) + +```python +torch.Tensor.detach() +``` + +### [paddle.Tensor.detach](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#detach) + +```python +paddle.Tensor.detach() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach_.md new file mode 100644 index 00000000000..b617fd4b4fb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.detach_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.detach_ + +### [torch.Tensor.detach_](https://pytorch.org/docs/stable/generated/torch.Tensor.detach_.html) + +```python +torch.Tensor.detach_() +``` + +### [paddle.Tensor.detach_]() + +```python +paddle.Tensor.detach_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.device.md new file mode 100644 index 00000000000..9871c685288 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.device.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.device + +### [torch.Tensor.device](https://pytorch.org/docs/stable/generated/torch.Tensor.device.html) + +```python +torch.Tensor.device +``` + +### [paddle.Tensor.place](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#place) + +```python +paddle.Tensor.place +``` + +两者功能一致,均无参数,都用来查看一个 Tensor 的设备位置。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag.md new file mode 100644 index 00000000000..57085204e82 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.diag + +### [torch.Tensor.diag](https://pytorch.org/docs/stable/generated/torch.Tensor.diag.html?highlight=diag#torch.Tensor.diag) + +```python +torch.Tensor.diag(diagonal=0) +``` + +### [paddle.Tensor.diag](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diag_cn.html#diag) + +```python +paddle.Tensor.diag(offset=0, padding_value=0, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------- | -------------------------------------------------------------------------------------- | +| - | x | 输入的 Tensor,paddle 参数更多。 | +| diagonal | offset | 考虑的对角线:正值表示上对角线,0 表示主对角线,负值表示下对角线,仅参数名不一致。 | +| - | padding_value | 使用此值来填充指定对角线以外的区域,仅在输入为一维 Tensor 时生效,默认值为 0。torch 无此参数,paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag_embed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag_embed.md new file mode 100644 index 00000000000..7c40903ce44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diag_embed.md @@ -0,0 +1,23 @@ +## [ 参数完全一致 ]torch.Tensor.diag_embed + +### [torch.Tensor.diag\_embed](https://pytorch.org/docs/stable/generated/torch.Tensor.diag_embed.html) + +```python +torch.Tensor.diag_embed(offset=0, dim1=-2, dim2=-1) +``` + +### [paddle.Tensor.diag\_embed]() + +```python +paddle.Tensor.diag_embed(offset=0, dim1=-2, dim2=-1, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| offset | offset | 从指定的二维平面中获取对角线的位置。 | +| dim1 | dim1 | 填充对角线的二维平面的第一维。 | +| dim2 | dim2 | 填充对角线的二维平面的第二维。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagflat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagflat.md new file mode 100644 index 00000000000..0ccfed7b68f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagflat.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.diagflat + +### [torch.Tensor.diagflat](https://pytorch.org/docs/stable/generated/torch.Tensor.diagflat.html?highlight=diagflat#torch.Tensor.diagflat) + +```python +torch.Tensor.diagflat(offset=0) +``` + +### [paddle.Tensor.diagflat]() + +```python +paddle.Tensor.diagflat(offset=0, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------ | +| offset | offset | 对角线偏移量。正值表示上对角线,0 表示主对角线,负值表示下对角线。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal.md new file mode 100644 index 00000000000..060e17ce132 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.diagonal + +### [torch.Tensor.diagonal](https://pytorch.org/docs/stable/generated/torch.Tensor.diagonal.html?highlight=diagonal#torch.Tensor.diagonal) + +```python +torch.Tensor.diagonal(offset=0, dim1=0, dim2=1) +``` + +### [paddle.Tensor.diagonal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#diagonal-offset-0-axis1-0-axis2-1-name-none) + +```python +paddle.Tensor.diagonal(offset=0, axis1=0, axis2=1, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------- | +| offset | offset | 从指定的二维平面中获取对角线的位置,默认值为 0,既主对角线,仅参数名不一致。 | +| dim1 | axis1 | 获取对角线的二维平面的第一维,默认值为 0,仅参数名不一致。 | +| dim2 | axis2 | 获取对角线的二维平面的第二维,默认值为 1,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal_scatter.md new file mode 100644 index 00000000000..6ed33ec78a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diagonal_scatter.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ] torch.Tensor.diagonal_scatter + +### [torch.Tensor.diagonal_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.diagonal_scatter.html?highlight=diagonal_scatter#torch.Tensor.diagonal_scatter) + +```python +torch.Tensor.diagonal_scatter(input, src, offset=0, dim1=0, dim2=1) +``` + +### [paddle.Tensor.diagonal_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#diagonal-scatter-x-y-offset-0-axis1-0-axis2-1-name-none) + +```python +paddle.Tensor.diagonal_scatter(x, y, offset=0, axis1=0, axis2=1) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| input | x | 输入张量,被嵌入的张量,仅参数名不一致。 | +| src | y | 用于嵌入的张量,仅参数名不一致。 | +| offset | offset | 从指定的二维平面嵌入对角线的位置,默认值为 0,即主对角线。 | +| dim1 | axis1 | 对角线的第一个维度,默认值为 0,仅参数名不一致。 | +| dim2 | axis2 | 对角线的第二个维度,默认值为 1,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diff.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diff.md new file mode 100644 index 00000000000..bc5ec9e3847 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.diff.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.Tensor.diff + +### [torch.Tensor.diff](https://pytorch.org/docs/stable/generated/torch.Tensor.diff.html?highlight=diff#torch.Tensor.diff) + +```python +torch.Tensor.diff(n=1, dim=- 1, prepend=None, append=None) +``` + +### [paddle.Tensor.diff](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diff_cn.html#diff) + +```python +paddle.Tensor.diff(n=1, axis=-1, prepend=None, append=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| n | n | 需要计算前向差值的次数,目前仅支持 n=1,默认值为 1。 | +| dim | axis | 沿着哪一维度计算前向差值,默认值为-1,也即最后一个维度,仅参数名不一致。 | +| prepend | prepend | 在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的前面,它的维度需要和输入一致,并且除了 axis 维外,其他维度的形状也要和输入一致,默认值为 None。 | +| append | append | 在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的后面,它的维度需要和输入一致,并且除了 axis 维外,其他维度的形状也要和输入一致,默认值为 None。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma.md new file mode 100644 index 00000000000..d513320178a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.digamma + +### [torch.Tensor.digamma](https://pytorch.org/docs/stable/generated/torch.Tensor.digamma.html?highlight=digamma#torch.Tensor.digamma) + +```python +torch.Tensor.digamma() +``` + +### [paddle.Tensor.digamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#digamma-name-none) + +```python +paddle.Tensor.digamma(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma_.md new file mode 100644 index 00000000000..1083b86f574 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.digamma_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.digamma_ + +### [torch.Tensor.digamma_](https://pytorch.org/docs/stable/generated/torch.Tensor.digamma_.html) + +```python +torch.Tensor.digamma_() +``` + +### [paddle.Tensor.digamma_]() + +```python +paddle.Tensor.digamma_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dim.md new file mode 100644 index 00000000000..6a6be99f557 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dim.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.dim + +### [torch.Tensor.dim](https://pytorch.org/docs/stable/generated/torch.Tensor.dim.html?highlight=dim#torch.Tensor.dim) + +```python +torch.Tensor.dim() +``` + +### [paddle.Tensor.dim](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dim) + +```python +paddle.Tensor.dim() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dist.md new file mode 100644 index 00000000000..9ee04654414 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dist.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.dist + +### [torch.Tensor.dist](https://pytorch.org/docs/stable/generated/torch.Tensor.dist.html?highlight=dist#torch.Tensor.dist) + +```python +torch.Tensor.dist(other, p=2) +``` + +### [paddle.Tensor.dist](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dist-y-p-2) + +```python +paddle.Tensor.dist(y, p=2) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | +| p | p | 需要计算的范数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md new file mode 100644 index 00000000000..00dbbd6bfe7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.div + +### [torch.Tensor.div](https://pytorch.org/docs/stable/generated/torch.Tensor.div.html#torch.Tensor.div) + +```python +torch.Tensor.div(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#divide-y-name-none) + +```python +paddle.Tensor.divide(y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.div(y, rounding_mode='floor') # 向下取整 +z2 = x.div(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide(y).floor() # 向下取整 +z2 = x.divide(y).trunc() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div_.md new file mode 100644 index 00000000000..811a90f0325 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.div_.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.div_ + +### [torch.Tensor.div_](https://pytorch.org/docs/stable/generated/torch.Tensor.div_.html) + +```python +torch.Tensor.div_(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide_]() + +```python +paddle.Tensor.divide_(y) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式,可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要转写。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.div_(y, rounding_mode='floor') # 向下取整 +z2 = x.div_(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide_(y).floor_() # 向下取整 +z2 = x.divide_(y).trunc_() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md new file mode 100644 index 00000000000..560f7e44a41 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.divide + +### [torch.Tensor.divide](https://pytorch.org/docs/stable/generated/torch.Tensor.divide.html#torch.Tensor.divide) + +```python +torch.Tensor.divide(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#divide-y-name-none) + +```python +paddle.Tensor.divide(y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.divide(y, rounding_mode='floor') # 向下取整 +z2 = x.divide(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide(y).floor() # 向下取整 +z2 = x.divide(y).trunc() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide_.md new file mode 100644 index 00000000000..eb876ded163 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.divide_.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ] torch.Tensor.divide_ + +### [torch.Tensor.divide_](https://pytorch.org/docs/stable/generated/torch.Tensor.divide_.html) + +```python +torch.Tensor.divide_(other, *, rounding_mode=None) +``` + +### [paddle.Tensor.divide_]() + +```python +paddle.Tensor.divide_(y) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 用于指定在执行截断除法时的舍入模式。可选值为 'floor'(向下取整) 或 'trunc'(向零取整)。 Paddle 无此参数,需要转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 | + +### 转写示例 + +```python +# torch 写法 +x = torch.tensor([4, 8, 12], dtype=torch.float32) +y = torch.tensor([3, 4, 5], dtype=torch.float32) +z1 = x.divide_(y, rounding_mode='floor') # 向下取整 +z2 = x.divide_(y, rounding_mode='trunc') # 向零取整 + +# paddle 写法 +x = paddle.to_tensor([4, 8, 12], dtype='float32') +y = paddle.to_tensor([3, 4, 5], dtype='float32') +z1 = x.divide_(y).floor_() # 向下取整 +z2 = x.divide_(y).trunc_() # 向零取整 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dot.md new file mode 100644 index 00000000000..3fb36f220e7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dot.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.dot + +### [torch.Tensor.dot](https://pytorch.org/docs/stable/generated/torch.Tensor.dot.html?highlight=dot#torch.Tensor.dot) + +```python +torch.Tensor.dot(tensor) +``` + +### [paddle.Tensor.dot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dot-y-name-none) + +```python +paddle.Tensor.dot(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| tensor | y | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md new file mode 100644 index 00000000000..79ada02593c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.double.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.double + +### [torch.Tensor.double](https://pytorch.org/docs/stable/generated/torch.Tensor.double.html#torch-Tensor-double) + +```python +torch.Tensor.double(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('float64') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dsplit.md new file mode 100644 index 00000000000..9db6885457c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.dsplit.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.dsplit + +### [torch.Tensor.dsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.dsplit.html) + +```python +torch.Tensor.dsplit(split_size_or_sections) +``` + +### [paddle.Tensor.dsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dsplit-num_or_indices-name-none) + +```python +paddle.Tensor.dsplit(num_or_indices, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| split_size_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.element_size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.element_size.md new file mode 100644 index 00000000000..aecc7d2e0da --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.element_size.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.element_size + +### [torch.Tensor.element_size](https://pytorch.org/docs/stable/generated/torch.Tensor.element_size.html?highlight=element_size#torch.Tensor.element_size) + +```python +torch.Tensor.element_size() +``` + +### [paddle.Tensor.element_size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#element-size) + +```python +paddle.Tensor.element_size() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq.md new file mode 100644 index 00000000000..f70202cbab2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.eq + +### [torch.Tensor.eq](https://pytorch.org/docs/stable/generated/torch.Tensor.eq.html?highlight=eq#torch.Tensor.eq) + +```python +torch.Tensor.eq(other) +``` + +### [paddle.Tensor.equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#equal-y-name-none) + +```python +paddle.Tensor.equal(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq_.md new file mode 100644 index 00000000000..ca92cf9ad5b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.eq_.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.eq_ + +### [torch.Tensor.eq_](https://pytorch.org/docs/stable/generated/torch.Tensor.eq_.html) + +```python +torch.Tensor.eq_(other) +``` + +### [paddle.Tensor.equal_]() + +```python +paddle.Tensor.equal_(y) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.eq_(2) + +# Paddle 写法 +result = x.equal_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.equal.md new file mode 100644 index 00000000000..5d97d633e75 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.equal.md @@ -0,0 +1,34 @@ +## [ 仅参数名不一致 ]torch.Tensor.equal + +### [torch.Tensor.equal](https://pytorch.org/docs/stable/generated/torch.Tensor.equal.html?highlight=equal#torch.Tensor.equal) + +```python +torch.Tensor.equal(other) +``` + +### [paddle.Tensor.equal_all](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#equal-all-y-name-none) + +```python +paddle.Tensor.equal_all(y, name=None) +``` + +两者功能一致,但参数用法不一致,其中 torch 返回值是 `bool`,paddle 返回值是数据类型为 `bool` 的 Tensor,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | + +## 转写示例 +```Python +# torch 中的写法 +x = torch.as_tensor([1, 2, 3, 4]) +y = torch.as_tensor([1, 2, 3, 5]) +x.equal(y) + +# paddle 中的写法 +x = paddle.to_tensor([1, 2, 3, 4]) +y = paddle.to_tensor([1, 2, 3, 5]) +x.equal_all(y).item() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf.md new file mode 100644 index 00000000000..8ba9293846b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.erf + +### [torch.Tensor.erf](https://pytorch.org/docs/stable/generated/torch.Tensor.erf.html?highlight=erf#torch.Tensor.erf) + +```python +torch.Tensor.erf() +``` + +### [paddle.Tensor.erf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#erf-name-none) + +```python +paddle.Tensor.erf(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf_.md new file mode 100644 index 00000000000..de29125dcf8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erf_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.erf_ + +### [torch.Tensor.erf_](https://pytorch.org/docs/stable/generated/torch.Tensor.erf_.html) + +```python +torch.Tensor.erf_() +``` + +### [paddle.erf_]() + +```python +paddle.erf_(x) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfc.md new file mode 100644 index 00000000000..e8444889565 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfc.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.erfc + +### [torch.Tensor.erfc](https://pytorch.org/docs/stable/generated/torch.Tensor.erfc.html) + +```python +torch.Tensor.erfc() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = x.erfc() + +# Paddle 写法 +y = 1 - x.erf() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv.md new file mode 100644 index 00000000000..69e0709bbe3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.erfinv + +### [torch.Tensor.erfinv](https://pytorch.org/docs/stable/generated/torch.Tensor.erfinv.html?highlight=erfinv#torch.Tensor.erfinv) + +```python +torch.Tensor.erfinv() +``` + +### [paddle.Tensor.erfinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#erfinv-x-name-none) + +```python +paddle.Tensor.erfinv(name=None) +``` + +两者功能一致. diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv_.md new file mode 100644 index 00000000000..d74fb066f95 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.erfinv_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.erfinv\_ + +### [torch.Tensor.erfinv\_](https://pytorch.org/docs/stable/generated/torch.Tensor.erfinv_.html?highlight=erfinv_#torch.Tensor.erfinv_) + +```python +torch.Tensor.erfinv_() +``` + +### [paddle.Tensor.erfinv\_]() + +```python +paddle.Tensor.erfinv_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp.md new file mode 100644 index 00000000000..f467acc6c86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.exp + +### [torch.Tensor.exp](https://pytorch.org/docs/stable/generated/torch.Tensor.exp.html?highlight=exp#torch.Tensor.exp) + +```python +torch.Tensor.exp() +``` + +### [paddle.Tensor.exp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#exp-name-none) + +```python +paddle.Tensor.exp(name=None) +``` + +两者功能一致。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp_.md new file mode 100644 index 00000000000..ead52ba998b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exp_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.exp\_ + +### [torch.Tensor.exp\_](https://pytorch.org/docs/stable/generated/torch.Tensor.exp_.html?highlight=exp_#torch.Tensor.exp_) + +```python +torch.Tensor.exp_() +``` + +### [paddle.Tensor.exp\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id7) + +```python +paddle.Tensor.exp_(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand.md new file mode 100644 index 00000000000..e38ae9345c0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.Tensor.expand +### [torch.Tensor.expand](https://pytorch.org/docs/stable/generated/torch.Tensor.expand.html?highlight=expand#torch.Tensor.expand) + +```python +torch.Tensor.expand(*size) +``` + +### [paddle.Tensor.expand](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#expand-shape-name-none) + +```python +paddle.Tensor.expand(shape, name=None) +``` + +两者功能一致,仅参数名不一致,具体差异如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | shape | 扩张后的维度,size 是可变参数,paddle 是 list/tuple | + +### 转写示例 +#### size: 扩张后的维度 +```python +# torch 写法 +x.expand(3, 4) + +# paddle 写法 +x.expand(shape=[3, 4]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand_as.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand_as.md new file mode 100644 index 00000000000..ff732e2a693 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expand_as.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.expand_as + +### [torch.Tensor.expand_as](https://pytorch.org/docs/stable/generated/torch.Tensor.expand_as.html?highlight=expand_as) + +```python +torch.Tensor.expand_as(other) +``` + +### [paddle.Tensor.expand_as](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#expand-as-y-name-none) + +```python +paddle.Tensor.expand_as(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------ | +| other | y | 给定输入扩展后的形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1.md new file mode 100644 index 00000000000..23366f17fa7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.expm1 + +### [torch.Tensor.expm1](https://pytorch.org/docs/stable/generated/torch.Tensor.expm1.html#torch.Tensor.expm1) + +```python +torch.Tensor.expm1() +``` + +### [paddle.Tensor.expm1]() + +```python +paddle.Tensor.expm1(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1_.md new file mode 100644 index 00000000000..616322be50e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.expm1_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.expm1_ + +### [torch.Tensor.expm1_](https://pytorch.org/docs/stable/generated/torch.Tensor.expm1_.html) + +```python +torch.Tensor.expm1_() +``` + +### [paddle.expm1_]() + +```python +paddle.expm1_(x) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exponential_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exponential_.md new file mode 100644 index 00000000000..119ef5c5192 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.exponential_.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.Tensor.exponential\_ + +### [torch.Tensor.exponential\_](https://pytorch.org/docs/stable/generated/torch.Tensor.exponential_.html#torch.Tensor.exponential_) + +```python +torch.Tensor.exponential_(lambd=1, *, generator=None) +``` + +### [paddle.Tensor.exponential\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#exponential-lam-1-0-name-none) + +```python +paddle.Tensor.exponential_(lam=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ----------------------------------------------------------------------------------- | +| lambd | lam | 指数分布的 λ 参数,仅参数名不一致。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_.md new file mode 100644 index 00000000000..6cad52624cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.fill\_ + +### [torch.Tensor.fill\_](https://pytorch.org/docs/stable/generated/torch.Tensor.fill_.html?highlight=fill_#torch.Tensor.fill_) + +```python +torch.Tensor.fill_(value) +``` + +### [paddle.Tensor.fill\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#fill-x-value-name-none) + +```python +paddle.Tensor.fill_(value, name=None) +``` + +两者功能一致且参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------- | +| value | value | 输入 value 值修改原始 Tensor 元素。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_diagonal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_diagonal_.md new file mode 100644 index 00000000000..b034172e01e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fill_diagonal_.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.fill_diagonal_ + +### [torch.Tensor.fill_diagonal_](https://pytorch.org/docs/stable/generated/torch.Tensor.fill_diagonal_.html?highlight=fill_diagonal_#torch.Tensor.fill_diagonal_) + +```python +torch.Tensor.fill_diagonal_(fill_value, wrap=False) +``` + +### [paddle.Tensor.fill_diagonal_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#fill-diagonal-x-value-offset-0-wrap-false-name-none) + +```python +paddle.Tensor.fill_diagonal_(value, offset=0, wrap=False, name=None) +``` + +两者功能一致且参数用法一致,paddle 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------- | +| fill_value | value | 以输入 value 值修改原始 Tensor 对角线元素,仅参数名不一致。 | +| - | offset | 所选取对角线相对原始主对角线位置的偏移量,正向右上方偏移,负向左下方偏移,默认为 0。PyTorch 无此参数, Paddle 保持默认即可。 | +| wrap | wrap | 对于 2 维 Tensor,height>width 时是否循环填充,默认为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fix.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fix.md new file mode 100644 index 00000000000..033c587481a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fix.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.fix + +### [torch.Tensor.fix](https://pytorch.org/docs/stable/generated/torch.Tensor.fix.html?highlight=fix#torch.Tensor.fix) + +```python +torch.Tensor.fix() +``` + +### [paddle.Tensor.trunc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#trunc-name-none) + +```python +paddle.Tensor.trunc(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flatten.md new file mode 100644 index 00000000000..093db48771d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flatten.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.flatten + +### [torch.Tensor.flatten](https://pytorch.org/docs/stable/generated/torch.Tensor.flatten.html?highlight=flatten#torch.Tensor.flatten) + +```python +torch.Tensor.flatten(start_dim=0, end_dim=- 1) +``` + +### [paddle.Tensor.flatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#flatten-start-axis-0-stop-axis-1-name-none) + +```python +paddle.Tensor.flatten(start_axis=0, stop_axis=-1, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ------------------------------ | +| start_dim | start_axis | 展开的起始维度,仅参数名不一致。 | +| end_dim | stop_axis | 展开的结束维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flip.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flip.md new file mode 100644 index 00000000000..728bbef4069 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flip.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.flip + +### [torch.Tensor.flip](https://pytorch.org/docs/stable/generated/torch.Tensor.flip.html?highlight=flip#torch.Tensor.flip) + +```python +torch.Tensor.flip(dims) +``` + +### [paddle.Tensor.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#flip-axis-name-none) + +```python +paddle.Tensor.flip(axis, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------- | +| dims | axis | 需要翻转的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fliplr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fliplr.md new file mode 100644 index 00000000000..5ad27794162 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fliplr.md @@ -0,0 +1,33 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.fliplr + +### [torch.Tensor.fliplr](https://pytorch.org/docs/stable/generated/torch.Tensor.fliplr.html?highlight=fliplr#torch.Tensor.fliplr) + +```python +torch.Tensor.fliplr() +``` + +### [paddle.Tensor.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#flip-axis-name-none) + +```python +paddle.Tensor.flip(axis, name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------- | +| - | axis | 指定进行翻转的轴,PyTorch 无此参数,Paddle 中可以指定 `axis=1` 来对应 PyTorch。| + +### 转写示例 + +```Python +# torch 版本直接向左/右翻转张量 +torch_x = torch.randn(3, 4) +torch_x.fliplr() + +# paddle 版本直接向左/右翻转张量 +paddle_x = paddle.randn([3, 4]) +paddle_x.flip(axis=1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flipud.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flipud.md new file mode 100644 index 00000000000..ab48dca83dd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.flipud.md @@ -0,0 +1,33 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.flipud + +### [torch.Tensor.flipud](https://pytorch.org/docs/stable/generated/torch.Tensor.flipud.html?highlight=flipud#torch.Tensor.flipud) + +```python +torch.Tensor.flipud() +``` + +### [paddle.Tensor.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#flip-axis-name-none) + +```python +paddle.Tensor.flip(axis, name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------- | +| - | axis | 指定进行翻转的轴,PyTorch 无此参数,Paddle 中可以指定 `axis=0` 来对应 PyTorch。| + +### 转写示例 + +```Python +# torch 版本直接向上/下翻转张量 +torch_x = torch.randn(3, 4) +torch_x.flipud() + +# paddle 版本直接向上/下翻转张量 +paddle_x = paddle.randn([3, 4]) +paddle_x.flip(axis=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float.md new file mode 100644 index 00000000000..ac017cb07f9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.float + +### [torch.Tensor.float](https://pytorch.org/docs/stable/generated/torch.Tensor.float.html?highlight=float#torch.Tensor.float) + +```python +torch.Tensor.float(memory_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('float32') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power.md new file mode 100644 index 00000000000..1c8ad5b3f4c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.Tensor.float_power + +### [torch.Tensor.float_power](https://pytorch.org/docs/stable/generated/torch.Tensor.float_power.html#torch.Tensor.float_power) + +```python +torch.Tensor.float_power(exponent) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = x.float_power(2) + +# Paddle 写法 +y = x.cast(paddle.float64).pow(2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power_.md new file mode 100644 index 00000000000..c994d34531f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.float_power_.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.Tensor.float_power_ + +### [torch.Tensor.float_power_](https://pytorch.org/docs/stable/generated/torch.Tensor.float_power_.html#torch.Tensor.float_power_) + +```python +torch.Tensor.float_power_(exponent) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = x.float_power_(2) + +# Paddle 写法 +y = x.cast_(paddle.float64).pow_(2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor.md new file mode 100644 index 00000000000..7a21c5a6cd6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.floor + +### [torch.Tensor.floor](https://pytorch.org/docs/stable/generated/torch.Tensor.floor.html?highlight=floor#torch.Tensor.floor) + +```python +torch.Tensor.floor() +``` + +### [paddle.Tensor.floor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/floor_cn.html#floor) + +```python +paddle.Tensor.floor(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_.md new file mode 100644 index 00000000000..aaf8f0d32d7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.floor\_ + +### [torch.Tensor.floor\_](https://pytorch.org/docs/stable/generated/torch.Tensor.floor_.html?highlight=floor_#torch.Tensor.floor_) + +```python +torch.Tensor.floor_() +``` + +### [paddle.Tensor.floor\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id10) + +```python +paddle.Tensor.floor_(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide.md new file mode 100644 index 00000000000..36baba2c8db --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.floor_divide + +### [torch.Tensor.floor_divide](https://pytorch.org/docs/stable/generated/torch.Tensor.floor_divide.html?highlight=floor_divide#torch.Tensor.floor_divide) + +```python +torch.Tensor.floor_divide(other) +``` + +### [paddle.Tensor.floor_divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#floor-divide-y-name-none) + +```python +paddle.Tensor.floor_divide(y, name=None) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| other | y | 多维 Tensor,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.floor_divide(other=2.) + +# Paddle 写法 +result = x.floor_divide(y=paddle.to_tensor(2.)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide_.md new file mode 100644 index 00000000000..812bff6595b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.floor_divide_.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.floor_divide_ + +### [torch.Tensor.floor_divide_](https://pytorch.org/docs/stable/generated/torch.Tensor.floor_divide_.html) + +```python +torch.Tensor.floor_divide_(other) +``` + +### [paddle.Tensor.floor_divide_]() + +```python +paddle.Tensor.floor_divide_(y) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| other | y | 多维 Tensor,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.floor_divide_(other=2.) + +# Paddle 写法 +result = x.floor_divide_(y=paddle.to_tensor(2.)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmax.md new file mode 100644 index 00000000000..19bdae5efa4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmax.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.fmax + +### [torch.Tensor.fmax](https://pytorch.org/docs/stable/generated/torch.Tensor.fmax.html?highlight=fmax#torch.Tensor.fmax) + +```python +torch.Tensor.fmax(other) +``` + +### [paddle.Tensor.fmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fmax_cn.html#fmax) + +```python +paddle.Tensor.fmax(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------- | +| other | y | 输入的第二个 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmin.md new file mode 100644 index 00000000000..c6167263ca1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmin.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.fmin + +### [torch.Tensor.fmin](https://pytorch.org/docs/stable/generated/torch.Tensor.fmin.html?highlight=fmin#torch.Tensor.fmin) + +```python +torch.Tensor.fmin(other) +``` + +### [paddle.Tensor.fmin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fmin_cn.html#fmin) + +```python +paddle.Tensor.fmin(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------- | +| other | y | 输入的第二个 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmod.md new file mode 100644 index 00000000000..98772dead4c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.fmod.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.fmod + +### [torch.Tensor.fmod](https://pytorch.org/docs/stable/generated/torch.Tensor.fmod.html#torch.Tensor.fmod) + +```python +torch.Tensor.fmod(other) +``` + +### [paddle.Tensor.mod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#mod-y-name-none) + +```python +paddle.Tensor.mod(y, name=None) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------- | +| other | y | 多维 Tensor,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.fmod(other=2.) + +# Paddle 写法 +result = x.mod(y=paddle.to_tensor(2.)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac.md new file mode 100644 index 00000000000..6f06b20a9ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.frac + +### [torch.Tensor.frac](https://pytorch.org/docs/stable/generated/torch.Tensor.frac.html?highlight=frac#torch.Tensor.frac) + +```python +torch.Tensor.frac() +``` + +### [paddle.Tensor.frac](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#frac-name-none) + +```python +paddle.Tensor.frac(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac_.md new file mode 100644 index 00000000000..600a8458bfa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frac_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.frac_ + +### [torch.Tensor.frac_](https://pytorch.org/docs/stable/generated/torch.Tensor.frac_.html) + +```python +torch.Tensor.frac_() +``` + +### [paddle.Tensor.frac_]() + +```python +paddle.Tensor.frac_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frexp.md new file mode 100644 index 00000000000..50b323dffde --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.frexp.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.frexp + +### [torch.Tensor.frexp](https://pytorch.org/docs/stable/generated/torch.Tensor.frexp.html#torch-tensor-frexp) + +```python +torch.Tensor.frexp() +``` + +### [paddle.Tensor.frexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#frexp-x) + +```python +paddle.Tensor.frexp() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gather.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gather.md new file mode 100644 index 00000000000..a59c2eb6c1c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gather.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.gather + +### [torch.Tensor.gather](https://pytorch.org/docs/stable/generated/torch.Tensor.gather.html?highlight=gather#torch.Tensor.gather) + +```python +torch.Tensor.gather(dim, index) +``` + +### [paddle.Tensor.take_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#take-along-axis-arr-index-axis) + +```python +paddle.Tensor.take_along_axis(index, axis, broadcast=True) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------- | +| dim | index | 索引 Tensor,仅参数名不一致。 | +| index | axis | 指定 index 获取输入的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd.md new file mode 100644 index 00000000000..1fc3cab92bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.gcd + +### [torch.Tensor.gcd](https://pytorch.org/docs/stable/generated/torch.Tensor.gcd.html?highlight=torch+tensor+gcd#torch.Tensor.gcd) + +```python +torch.Tensor.gcd(other) +``` + +### [paddle.Tensor.gcd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#gcd-x-y-name-none) + +```python +paddle.Tensor.gcd(y, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd_.md new file mode 100644 index 00000000000..05f22e4f10a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gcd_.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.gcd_ + +### [torch.Tensor.gcd_](https://pytorch.org/docs/stable/generated/torch.Tensor.gcd_.html) + +```python +torch.Tensor.gcd_(other) +``` + +### [paddle.Tensor.gcd_]() + +```python +paddle.Tensor.gcd_(y) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge.md new file mode 100644 index 00000000000..4c429dd5f83 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.ge + +### [torch.Tensor.ge](https://pytorch.org/docs/stable/generated/torch.Tensor.ge.html?highlight=torch+tensor+ge#torch.Tensor.ge) + +```python +torch.Tensor.ge(other) +``` + +### [paddle.Tensor.greater_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#greater-equal-y-name-none) + +```python +paddle.Tensor.greater_equal(y, name=None) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.ge(other=2) + +# Paddle 写法 +result = x.greater_equal(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge_.md new file mode 100644 index 00000000000..82706618deb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ge_.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.ge_ + +### [torch.Tensor.ge_](https://pytorch.org/docs/stable/ge_nerated/torch.Tensor.ge_.html) + +```python +torch.Tensor.ge_(other) +``` + +### [paddle.Tensor.greater_equal_]() + +```python +paddle.Tensor.greater_equal_(y) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.ge_(other=2) + +# Paddle 写法 +result = x.greater_equal_(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ger.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ger.md new file mode 100644 index 00000000000..bfe64f31a49 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ger.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.ger + +### [torch.Tensor.ger](https://pytorch.org/docs/stable/generated/torch.Tensor.ger.html?highlight=torch+tensor+ger#torch.Tensor.ger) + +```python +torch.Tensor.ger(vec2) +``` + +### [paddle.Tensor.outer]() + +```python +paddle.Tensor.outer(y, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|--------------------------------|------------------------------| ------------------------------------------------------ | +| vec2 | y | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.get_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.get_device.md new file mode 100644 index 00000000000..9c72b9ebaaf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.get_device.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.get_device + +### [torch.Tensor.get_device](https://pytorch.org/docs/stable/generated/torch.Tensor.get_device.html?highlight=torch+tensor+get_device#torch.Tensor.get_device) + +```python +torch.Tensor.get_device() +``` + +### [paddle.Tensor.place.gpu_device_id]() + +```python +paddle.Tensor.place.gpu_device_id() +``` + +两者功能一致且无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.grad.md new file mode 100644 index 00000000000..133e0b3c6ff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.grad.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.grad + +### [torch.Tensor.grad](https://pytorch.org/docs/stable/generated/torch.Tensor.grad.html) + +```python +torch.Tensor.grad +``` + +### [paddle.Tensor.grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#grad) + +```python +paddle.Tensor.grad +``` + +两者功能一致,均无参数,都用来查看一个 Tensor 的梯度。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater.md new file mode 100644 index 00000000000..cce4bcc28b4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.greater + +### [torch.Tensor.greater](https://pytorch.org/docs/stable/generated/torch.Tensor.greater.html?highlight=torch+tensor+greater#torch.Tensor.greater) + +```python +torch.Tensor.greater(other) +``` + +### [paddle.Tensor.greater_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#greater-than-y-name-none) + +```python +paddle.Tensor.greater_than(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.greater(2) + +# Paddle 写法 +result = x.greater_than(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_.md new file mode 100644 index 00000000000..2541946f0a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.greater_ + +### [torch.Tensor.greater_](https://pytorch.org/docs/stable/generated/torch.Tensor.greater_.html) + +```python +torch.Tensor.greater_(other) +``` + +### [paddle.Tensor.greater_than_]() + +```python +paddle.Tensor.greater_than_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.greater_(2) + +# Paddle 写法 +result = x.greater_than_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal.md new file mode 100644 index 00000000000..13f6087f7bd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.greater_equal + +### [torch.Tensor.greater_equal](https://pytorch.org/docs/stable/generated/torch.Tensor.greater_equal.html?highlight=torch+tensor+greater_equal#torch.Tensor.greater_equal) + +```python +torch.Tensor.greater_equal(other) +``` + +### [paddle.Tensor.greater_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#greater-equal-y-name-none) + +```python +paddle.Tensor.greater_equal(y, name=None) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.greater_equal(other=2) + +# Paddle 写法 +result = x.greater_equal(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal_.md new file mode 100644 index 00000000000..8a4da98ea9c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.greater_equal_.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.Tensor.greater_equal_ + +### [torch.Tensor.greater_equal_](https://pytorch.org/docs/stable/generated/torch.Tensor.greater_equal_.html) + +```python +torch.Tensor.greater_equal_(other) +``` + +### [paddle.Tensor.greater_equal_]() + +```python +paddle.Tensor.greater_equal_(y) +``` + +其中,PyTorch 与 Paddle 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 输入的 Tensor ,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other +```python +# PyTorch 写法 +result = x.greater_equal_(other=2) + +# Paddle 写法 +result = x.greater_equal_(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt.md new file mode 100644 index 00000000000..ae207c82dd7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.gt + +### [torch.Tensor.gt](https://pytorch.org/docs/stable/generated/torch.Tensor.gt.html?highlight=torch+tensor+gt#torch.Tensor.gt) + +```python +torch.Tensor.gt(other) +``` + +### [paddle.Tensor.greater_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#greater-than-y-name-none) + +```python +paddle.Tensor.greater_than(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.gt(2) + +# Paddle 写法 +result = x.greater_than(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt_.md new file mode 100644 index 00000000000..b86ca1cc88d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.gt_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.gt_ + +### [torch.Tensor.gt_](https://pytorch.org/docs/stable/generated/torch.Tensor.gt_.html) + +```python +torch.Tensor.gt_(other) +``` + +### [paddle.Tensor.greater_than_]() + +```python +paddle.Tensor.greater_than_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.gt_(2) + +# Paddle 写法 +result = x.greater_than_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.half.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.half.md new file mode 100644 index 00000000000..194af0d7210 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.half.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.half + +### [torch.Tensor.half](https://pytorch.org/docs/stable/generated/torch.Tensor.half.html#torch.Tensor.half) + +```python +torch.Tensor.half(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('float16') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hardshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hardshrink.md new file mode 100644 index 00000000000..7afc12c0a0c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hardshrink.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.hardshrink + +### [torch.Tensor.hardshrink](https://pytorch.org/docs/stable/generated/torch.Tensor.hardshrink.html?highlight=torch+tensor+hardshrink#torch.Tensor.hardshrink) + +```python +torch.Tensor.hardshrink(lambd=0.5) +``` + +### [paddle.nn.functional.hardshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hardshrink_cn.html#hardshrink) + +```python +paddle.nn.functional.hardshrink(x, threshold=0.5, name=None) +``` + +仅参数名不一致,具体如下。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|-----------------------------------|------------------------------| ------------------------------------------------------ | +| lambd | threshold | Hardshrink 阈值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.heaviside.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.heaviside.md new file mode 100644 index 00000000000..ad36120a311 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.heaviside.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.heaviside + +### [torch.Tensor.heaviside](https://pytorch.org/docs/stable/generated/torch.Tensor.heaviside.html?highlight=torch+tensor+heaviside#torch.Tensor.heaviside) + +```python +torch.Tensor.heaviside(values) +``` + +### [paddle.Tensor.heaviside](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#heaviside-y-name-none) + +```python +paddle.Tensor.heaviside(y, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|-----------------------------------|------------------------------| ------------------------------------------------------ | +| values | y | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histc.md new file mode 100644 index 00000000000..18a31c82294 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histc.md @@ -0,0 +1,33 @@ +## [ 参数不一致 ]torch.Tensor.histc + +### [torch.Tensor.histc](https://pytorch.org/docs/stable/generated/torch.Tensor.histc.html?highlight=torch+tensor+histc#torch.Tensor.histc) + +```python +torch.Tensor.histc(bins=100, min=0, max=0) +``` + +### [paddle.Tensor.histogram](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#histogram-bins-100-min-0-max-0) + +```python +paddle.Tensor.histogram(bins=100, min=0, max=0, name=None) +``` + +返回 Tensor 的数据类型不一致,PyTorch 返回数据类型与输入 Tensor 一致, Paddle 默认返回 int64 类型。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|-----------------------------------|------------------------------| ------------------------------------------------------ | +| bins | bins | 直方图 bins(直条)的个数,默认为 100。 | +| min | min | range 的下边界(包含),默认为 0。 | +| max | max | range 的上边界(包含),默认为 0。 | + +### 转写示例 + +```python +# PyTorch 写法 +y = a.histc(bins=3, min=2, max=4) + +# Paddle 写法 +y = a.histogram(bins=3, min=2, max=4).astype(a.dtype) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histogram.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histogram.md new file mode 100644 index 00000000000..48fa4b3006b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.histogram.md @@ -0,0 +1,38 @@ +## [torch 参数更多]torch.Tensor.histogram + +### [torch.Tensor.histogram](https://pytorch.org/docs/stable/generated/torch.Tensor.histogram.html#torch.Tensor.histogram) + +```python +torch.Tensor.histogram(bins, *, range=None, weight=None, density=False) +``` + +### [paddle.Tensor.histogram](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#histogram-bins-100-min-0-max-0) + +```python +paddle.Tensor.histogram(bins=100, min=0, max=0) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------------------------- | +| bins | bins | 直方图 bins(直条)的个数。 | +| range | min, max | PyTorch 为 bins 的范围,类型为 float,Paddle 为 range 的下边界,上边界,类型为 int,需要转写。 | +| weight | - | 权重,Paddle 无此参数,暂无转写方式。 | +| density | - | 结果中每个 bin 是否包含权重数,Paddle 无此参数,暂无转写方式。 | + +### 转写示例 + +#### range 参数:bins 的范围 + +```python +# PyTorch 写法: +x = torch.tensor([1., 2, 1]) +y = x.histogram(bins=5, range=(0., 3.)) + +# Paddle 写法: +x = paddle.to_tensor([1, 2, 1]) +y = x.histogram(bins=5, min=0, max=3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hsplit.md new file mode 100644 index 00000000000..114ea061661 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hsplit.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.hsplit + +### [torch.Tensor.hsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.hsplit.html) + +```python +torch.Tensor.hsplit(split_size_or_sections) +``` + +### [paddle.Tensor.hsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#hsplit-num_or_indices-name-none) + +```python +paddle.Tensor.hsplit(num_or_indices, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| split_size_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot.md new file mode 100644 index 00000000000..29bdc4ba107 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.hypot + +### [torch.Tensor.hypot](https://pytorch.org/docs/stable/generated/torch.Tensor.hypot.html#torch.Tensor.hypot) + +```python +torch.Tensor.hypot(other) +``` + +### [paddle.Tensor.hypot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hypot_cn.html) + +```python +paddle.Tensor.hypot(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot_.md new file mode 100644 index 00000000000..763ae17fb82 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.hypot_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.hypot_ + +### [torch.Tensor.hypot_](https://pytorch.org/docs/stable/generated/torch.Tensor.hypot_.html#torch.Tensor.hypot_) + +```python +torch.Tensor.hypot_(other) +``` + +### [paddle.Tensor.hypot_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hypot__cn.html) + +```python +paddle.Tensor.hypot_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------- | +| other | y | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0.md new file mode 100644 index 00000000000..0f9b8498da4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.i0 + +### [torch.Tensor.i0](https://pytorch.org/docs/stable/generated/torch.Tensor.i0.html?highlight=i0#torch.Tensor.i0) + +```python +torch.Tensor.i0() +``` + +### [paddle.Tensor.i0](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#i0-x-name-none) + +```python +paddle.Tensor.i0(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0_.md new file mode 100644 index 00000000000..7168687d454 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.i0_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.i0_ + +### [torch.Tensor.i0_](https://pytorch.org/docs/stable/generated/torch.Tensor.i0_.html) + +```python +torch.Tensor.i0_() +``` + +### [paddle.Tensor.i0_]() + +```python +paddle.Tensor.i0_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.imag.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.imag.md new file mode 100644 index 00000000000..abf201782f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.imag.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.imag + +### [torch.Tensor.imag](https://pytorch.org/docs/stable/generated/torch.Tensor.imag.html) + +```python +torch.Tensor.imag +``` + +### [paddle.Tensor.imag](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#imag-name-none) + +```python +paddle.Tensor.imag +``` + +两者功能一致,均无参数,用于返回原复数 Tensor 的虚部数值。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add.md new file mode 100644 index 00000000000..ea6ad3dfdb8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.Tensor.index_add +### [torch.Tensor.index_add](https://pytorch.org/docs/stable/generated/torch.Tensor.index_add.html#torch.Tensor.index_add) + +```python +torch.Tensor.index_add(dim, index, source, *, alpha=1) +``` + +### [paddle.Tensor.index_add]() + +```python +paddle.Tensor.index_add(index, axis, value, name=None) +``` + +其中 PyTorch 与 Paddle 参数有差异,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| source | value | 被加的 Tensor,仅参数名不一致。 | +| alpha | - | source 的 缩放倍数, Paddle 无此参数,需要转写。Paddle 应将 alpha 和 source 的乘积作为 value。 | + + +### 转写示例 +#### alpha:source 的缩放倍数 +```python +# PyTorch 写法 +x.index_add(dim=1, index=index, source=source, alpha=alpha) + +# Paddle 写法 +x.index_add(index=index, axis=1, value=alpha*source) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add_.md new file mode 100644 index 00000000000..0a6541cbefc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_add_.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.Tensor.index_add_ +### [torch.Tensor.index_add_](https://pytorch.org/docs/stable/generated/torch.Tensor.index_add_.html#torch.Tensor.index_add_) + +```python +torch.Tensor.index_add_(dim, index, source, *, alpha=1) +``` + +### [paddle.Tensor.index_add_]() + +```python +paddle.Tensor.index_add_(index, axis, value) +``` + +其中 PyTorch 与 Paddle 参数有差异,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| source | value | 被加的 Tensor,仅参数名不一致。 | +| alpha | - | source 的 缩放倍数, Paddle 无此参数,需要转写。Paddle 应将 alpha 和 source 的乘积作为 value。 | + + +### 转写示例 +#### alpha:source 的缩放倍数 +```python +# PyTorch 写法 +x.index_add_(dim=1, index=index, source=source, alpha=alpha) + +# Paddle 写法 +x.index_add_(index=index, axis=1, value=alpha*source) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_copy_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_copy_.md new file mode 100644 index 00000000000..1429205fd9d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_copy_.md @@ -0,0 +1,29 @@ +## [ 组合替代实现 ]torch.Tensor.index_copy_ + +### [torch.Tensor.index_copy_](https://pytorch.org/docs/stable/generated/torch.Tensor.index_copy_.html) + +```python +torch.Tensor.index_copy_(dim, index, source) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法,dim=0 +y = x.index_copy_(0, index, source) + +# Paddle 写法 +y = x.scatter_(index, source) + +# PyTorch 写法,dim>0 +y = x.index_copy_(dim, index, source) + +# Paddle 写法 +times, temp_shape, temp_index = paddle.prod(paddle.to_tensor(x.shape[:dim])), x.shape, index +x, new_t = x.reshape([-1] + temp_shape[dim+1:]), source.reshape([-1] + temp_shape[dim+1:]) +for i in range(1, times): + temp_index= paddle.concat([temp_index, index+len(index)*i]) +y = x.scatter_(temp_index, new_t).reshape_(temp_shape) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill.md new file mode 100644 index 00000000000..64453f03a05 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill.md @@ -0,0 +1,31 @@ +## [ 仅参数名不一致 ]torch.Tensor.index_fill +### [torch.Tensor.index_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.index_fill.html?highlight=index_fill#torch.Tensor.index_fill) + +```python +torch.Tensor.index_fill(dim, index, value) +``` + +### [paddle.Tensor.index_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/index_fill_cn.html#index-fill) + +```python +paddle.Tensor.index_fill(index, axis, value, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| value | value | 填充的值。 | + +### 转写示例 +#### alpha:source 的缩放倍数 +```python +# PyTorch 写法 +x.index_fill(dim=1, index=index, value=1) + +# Paddle 写法 +x.index_fill(index=index, axis=1, value=1) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill_.md new file mode 100644 index 00000000000..f9481ead96e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_fill_.md @@ -0,0 +1,31 @@ +## [ 仅参数名不一致 ]torch.Tensor.index_fill_ +### [torch.Tensor.index_fill_](https://pytorch.org/docs/stable/generated/torch.Tensor.index_fill_.html?highlight=index_fill_#torch.Tensor.index_fill_) + +```python +torch.Tensor.index_fill_(dim, index, value) +``` + +### [paddle.Tensor.index_fill_]() + +```python +paddle.Tensor.index_fill_(index, axis, value, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| value | value | 填充的值。 | + +### 转写示例 +#### alpha:source 的缩放倍数 +```python +# PyTorch 写法 +x.index_fill_(dim=1, index=index, value=1) + +# Paddle 写法 +x.index_fill_(index=index, axis=1, value=1) diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put.md new file mode 100644 index 00000000000..6df21ecee94 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.index_put +### [torch.Tensor.index_put](https://pytorch.org/docs/stable/generated/torch.Tensor.index_put.html?highlight=index_put#torch.Tensor.index_put) + +```python +torch.Tensor.index_put(indices, values, accumulate=False) +``` + +### [paddle.Tensor.index_put](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/index_put_cn.html#index-put) + +```python +paddle.Tensor.index_put(indices, value, accumulate=False, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| indices | indices | 包含用来索引的 tensors 的元组。数据类型为 int32,int64,bool。 | +| values | value | 用来给 x 赋值的 Tensor,仅参数名不一致。 | +| accumulate | accumulate | 指定是否将 value 加到 x 的参数。 默认值为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put_.md new file mode 100644 index 00000000000..3e26d9ca671 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_put_.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.index_put_ +### [torch.Tensor.index_put_](https://pytorch.org/docs/stable/generated/torch.Tensor.index_put_.html#torch.Tensor.index_put_) + +```python +torch.Tensor.index_put_(indices, values, accumulate=False) +``` + +### [paddle.Tensor.index_put_]() + +```python +paddle.Tensor.index_put_(indices, value, accumulate=False) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| indices | indices | 包含用来索引的 tensors 的元组。数据类型为 int32,int64,bool。 | +| values | value | 用来给 x 赋值的 Tensor,仅参数名不一致。 | +| accumulate | accumulate | 指定是否将 value 加到 x 的参数。 默认值为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_select.md new file mode 100644 index 00000000000..5dfdf5ade8a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.index_select.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.index_select + +### [torch.Tensor.index\_select](https://pytorch.org/docs/stable/generated/torch.Tensor.index_select.html) + +```python +torch.Tensor.index_select(dim, index) +``` + +### [paddle.Tensor.index\_select](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#index-select-index-axis-0-name-none) + +```python +paddle.Tensor.index_select(index, axis=0, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| dim | axis | 索引轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.indices.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.indices.md new file mode 100644 index 00000000000..c7ae898022f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.indices.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.indices + +### [torch.Tensor.indices](https://pytorch.org/docs/stable/generated/torch.Tensor.indices.html#torch.Tensor.indices) + +```python +torch.Tensor.indices() +``` + +### [paddle.Tensor.indices](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/Overview_cn.html) + +```python +paddle.Tensor.indices() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inner.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inner.md new file mode 100644 index 00000000000..6645b6a85a1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inner.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.inner + +### [torch.Tensor.inner](https://pytorch.org/docs/stable/generated/torch.Tensor.inner.html) + +```python +torch.Tensor.inner(other) +``` + +### [paddle.Tensor.inner]() + +```python +paddle.Tensor.inner(y, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| other | y | 计算内积的第二个 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.int.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.int.md new file mode 100644 index 00000000000..add87c7f477 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.int.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.int + +### [torch.Tensor.int](https://pytorch.org/docs/stable/generated/torch.Tensor.int.html?highlight=int#torch.Tensor.int) + +```python +torch.Tensor.int(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('int32') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inverse.md new file mode 100644 index 00000000000..95d6a0a6b49 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.inverse.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.inverse + +### [torch.Tensor.inverse](https://pytorch.org/docs/stable/generated/torch.Tensor.inverse.html) + +```python +torch.Tensor.inverse() +``` + +### [paddle.Tensor.inverse]() + +```python +paddle.Tensor.inverse(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_complex.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_complex.md new file mode 100644 index 00000000000..a33ea65cf5d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_complex.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.is_complex + +### [torch.Tensor.is\_complex](https://pytorch.org/docs/stable/generated/torch.Tensor.is_complex.html) + +```python +torch.Tensor.is_complex() +``` + +### [paddle.Tensor.is\_complex](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#is-complex) + +```python +paddle.Tensor.is_complex() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md new file mode 100644 index 00000000000..e5b1adab428 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_contiguous.md @@ -0,0 +1,9 @@ +## [ 可删除 ]torch.Tensor.is_contiguous + +### [torch.Tensor.is_contiguous](https://pytorch.org/docs/stable/generated/torch.Tensor.is_contiguous.html#torch-tensor-is-contiguous) + +```python +torch.Tensor.is_contiguous(memory_format=torch.contiguous_format) +``` + +判断 Tensor 是否是 contiguous 的,PaddlePaddle 的 Tensor 默认是 contiguous 的, 因此可直接视作为 True。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md new file mode 100644 index 00000000000..a95be80ad47 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_cuda.md @@ -0,0 +1,21 @@ +## [组合替代实现] torch.Tensor.is_cuda + +### [torch.Tensor.is_cuda](https://pytorch.org/docs/stable/generated/torch.Tensor.is_cuda.html?highlight=is_cuda#torch.Tensor.is_cuda) + +```python +torch.Tensor.is_cuda +``` + +判断 Tensor 是否在 gpu 上,PaddlePaddle 目前无对应 API,可使用如下代码组合替代实现: + +### 转写示例 + +```python +# PyTorch 写法 +d = torch.Tensor([1,2,3]) +d.is_cuda + +# Paddle 写法 +d = paddle.to_tensor([1,2,3]) +"gpu" in str(d.place) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_floating_point.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_floating_point.md new file mode 100644 index 00000000000..20a76f76370 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_floating_point.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.is_floating_point + +### [torch.Tensor.is\_floating\_point](https://pytorch.org/docs/stable/generated/torch.Tensor.is_floating_point.html) + +```python +torch.Tensor.is_floating_point() +``` + +### [paddle.Tensor.is\_floating\_point](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#is-floating-point-x) + +```python +paddle.Tensor.is_floating_point() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_leaf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_leaf.md new file mode 100644 index 00000000000..938253dbdb4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_leaf.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.is_leaf + +### [torch.Tensor.is_leaf](https://pytorch.org/docs/stable/generated/torch.Tensor.is_leaf.html) + +```python +torch.Tensor.is_leaf +``` + +### [paddle.Tensor.is_leaf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#is-leaf) + +```python +paddle.Tensor.is_leaf +``` + +两者功能一致,均无参数,判断 Tensor 是否为叶子 Tensor。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_signed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_signed.md new file mode 100644 index 00000000000..af8149d1f81 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_signed.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.is_signed + +### [torch.Tensor.is_signed](https://pytorch.org/docs/stable/generated/torch.Tensor.is_signed.html#torch.Tensor.is_signed) + +```python +torch.Tensor.is_signed() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = x.is_signed() + +# Paddle 写法 +y = x.dtype not in [paddle.uint8] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md new file mode 100644 index 00000000000..1393779c8ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.is_sparse.md @@ -0,0 +1,27 @@ +## [ 无参数 ] torch.Tensor.is_sparse + +### [torch.Tensor.is_sparse](https://pytorch.org/docs/stable/generated/torch.Tensor.is_sparse.html) + +```python +torch.Tensor.is_sparse +``` + +### [paddle.Tensor.is_sparse](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html) + +```python +paddle.Tensor.is_sparse() +``` + +两者功能一致,但使用方式不一致,前者可以直接访问属性,后者需要调用方法,具体如下: + +### 转写示例 + +```python +# torch 版本可以直接访问属性 +# x = torch.rand(3) +# print(x.is_sparse) + +# Paddle 版本需要调用 +x = paddle.rand([3]) +print(x.is_sparse()) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isclose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isclose.md new file mode 100644 index 00000000000..4febf657ad7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isclose.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.Tensor.isclose + +### [torch.Tensor.isclose](https://pytorch.org/docs/stable/generated/torch.Tensor.isclose.html) + +```python +torch.Tensor.isclose(other, rtol=1e-05, atol=1e-08, equal_nan=False) +``` + +### [paddle.Tensor.isclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isclose-x-y-rtol-1e-05-atol-1e-08-equal-nan-false-name-none) + +```python +paddle.Tensor.isclose(y, rtol=1e-05, atol=1e-08, equal_nan=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | -- | +| other | y | 输入的 Tensor,仅参数名不一致。 | +| rtol | rtol | 相对容忍误差。 | +| atol | atol | 绝对容忍误差。 | +| equal_nan | equal_nan | 如果设置为 True,则两个 NaN 数值将被视为相等,默认值为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isfinite.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isfinite.md new file mode 100644 index 00000000000..1d07175ed18 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isfinite.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.isfinite + +### [torch.Tensor.isfinite](https://pytorch.org/docs/stable/generated/torch.Tensor.isfinite.html) + +```python +torch.Tensor.isfinite() +``` + +### [paddle.Tensor.isfinite](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isfinite-name-none) + +```python +paddle.Tensor.isfinite(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isinf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isinf.md new file mode 100644 index 00000000000..c5967c7331b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isinf.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.isinf + +### [torch.Tensor.isinf](https://pytorch.org/docs/stable/generated/torch.Tensor.isinf.html) + +```python +torch.Tensor.isinf() +``` + +### [paddle.Tensor.isinf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isinf-name-none) + +```python +paddle.Tensor.isinf(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isnan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isnan.md new file mode 100644 index 00000000000..ff1d617b4ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.isnan.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.isnan + +### [torch.Tensor.isnan](https://pytorch.org/docs/stable/generated/torch.Tensor.isnan.html) + +```python +torch.Tensor.isnan() +``` + +### [paddle.Tensor.isnan](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#isnan-name-none) + +```python +paddle.Tensor.isnan(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.istft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.istft.md new file mode 100644 index 00000000000..4d74910babb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.istft.md @@ -0,0 +1,37 @@ +## [ 参数完全一致 ]torch.Tensor.istft +### [torch.Tensor.istft](https://pytorch.org/docs/stable/generated/torch.Tensor.istft.html#torch.Tensor.istft) + +```python +torch.Tensor.istft(n_fft, hop_length=None, win_length=None, window=None, center=True, normalized=False, onesided=None, length=None, return_complex=False) +``` + +### [paddle.Tensor.istft]() + +```python +paddle.Tensor.istft(n_fft, + hop_length=None, + win_length=None, + window=None, + center=True, + normalized=False, + onesided=True, + length=None, + return_complex=False, + name=None) +``` + +两者功能一致且参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| n_fft | n_fft | 表示离散傅里叶变换的样本点个数。 | +| hop_length | hop_length | 表示相邻两帧偏移的样本点个数。 | +| win_length | win_length | 表示信号窗的长度。 | +| window | window | 表示长度为 win_length 的 Tensor 。 | +| center | center | 表示是否将输入信号进行补长。 | +| normalized | normalized | 表示是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | +| onesided | onesided | 表示是否返回一个实信号。 | +| length | length | 表示输出信号的长度。 | +| return_complex | return_complex | 表示输出的重构信号是否为复信号。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.item.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.item.md new file mode 100644 index 00000000000..27f021023d7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.item.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor.item + +### [torch.Tensor.item](https://pytorch.org/docs/stable/generated/torch.Tensor.item.html#torch-tensor-item) + +```python +torch.Tensor.item() +``` + +### [paddle.Tensor.item](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#item-args) + +```python +paddle.Tensor.item(*args) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| - | *args | Tensor 的指定位置,保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.kthvalue.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.kthvalue.md new file mode 100644 index 00000000000..14e12070400 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.kthvalue.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.kthvalue + +### [torch.Tensor.kthvalue](https://pytorch.org/docs/stable/generated/torch.Tensor.kthvalue.html) + +```python +torch.Tensor.kthvalue(k, dim=None, keepdim=False) +``` + +### [paddle.Tensor.kthvalue](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#kthvalue-k-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.kthvalue(k, axis=None, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| k | k | 需要沿轴查找的第 k 小,所对应的 k 值。 | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否保留指定的轴。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm.md new file mode 100644 index 00000000000..3a510e267ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.lcm + +### [torch.Tensor.lcm](https://pytorch.org/docs/stable/generated/torch.Tensor.lcm.html) + +```python +torch.Tensor.lcm(other) +``` + +### [paddle.Tensor.lcm]() + +```python +paddle.Tensor.lcm(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm_.md new file mode 100644 index 00000000000..6707cbaa8a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lcm_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.lcm_ + +### [torch.Tensor.lcm_](https://pytorch.org/docs/stable/generated/torch.Tensor.lcm_.html) + +```python +torch.Tensor.lcm_(other) +``` + +### [paddle.Tensor.lcm_]() + +```python +paddle.Tensor.lcm_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp.md new file mode 100644 index 00000000000..3c5816088db --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.ldexp + +### [torch.Tensor.ldexp](https://pytorch.org/docs/stable/generated/torch.Tensor.ldexp.html#torch.Tensor.ldexp) + +```python +torch.Tensor.ldexp(other) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.ldexp(b) + +# Paddle 写法 +y = a * (2 ** b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp_.md new file mode 100644 index 00000000000..78a07731572 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ldexp_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.ldexp_ + +### [torch.Tensor.ldexp_](https://pytorch.org/docs/stable/generated/torch.Tensor.ldexp_.html) + +```python +torch.Tensor.ldexp_(other) +``` + +### [paddle.Tensor.ldexp_]() + +```python +paddle.Tensor.ldexp_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le.md new file mode 100644 index 00000000000..620ba89137a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.le + +### [torch.Tensor.le](https://pytorch.org/docs/stable/generated/torch.Tensor.le.html) + +```python +torch.Tensor.le(other) +``` + +### [paddle.Tensor.less_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#less-equal-y-name-none) + +```python +paddle.Tensor.less_equal(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.le(2) + +# Paddle 写法 +result = x.less_equal(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le_.md new file mode 100644 index 00000000000..bd49ecaa4ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.le_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.le_ + +### [torch.Tensor.le_](https://pytorch.org/docs/stable/generated/torch.Tensor.le_.html) + +```python +torch.Tensor.le_(other) +``` + +### [paddle.Tensor.less_equal_]() + +```python +paddle.Tensor.less_equal_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.le_(2) + +# Paddle 写法 +result = x.less_equal_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp.md new file mode 100644 index 00000000000..f5ff60d6a61 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.lerp + +### [torch.Tensor.lerp](https://pytorch.org/docs/stable/generated/torch.Tensor.lerp.html) + +```python +torch.Tensor.lerp(end, weight) +``` + +### [paddle.Tensor.lerp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#lerp-x-y-weight-name-none) + +```python +paddle.Tensor.lerp(y, weight, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| end | y | 输入的 Tensor,作为线性插值结束的点,仅参数名不一致。 | +| weight | weight | 给定的权重值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp_.md new file mode 100644 index 00000000000..b9f932c7a85 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lerp_.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.lerp_ + +### [torch.Tensor.lerp\_](https://pytorch.org/docs/stable/generated/torch.Tensor.lerp_.html) + +```python +torch.Tensor.lerp_(end, weight) +``` + +### [paddle.Tensor.lerp\_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#lerp-x-y-weight-name-none) + +```python +paddle.Tensor.lerp_(y, weight, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| end | y | 输入的 Tensor,作为线性插值结束的点,仅参数名不一致。 | +| weight | weight | 给定的权重值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less.md new file mode 100644 index 00000000000..6b0c3e4b22f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.less + +### [torch.Tensor.less](https://pytorch.org/docs/stable/generated/torch.Tensor.less.html) + +```python +torch.Tensor.less(other) +``` + +### [paddle.Tensor.less_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#less-than-y-name-none) + +```python +paddle.Tensor.less_than(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.less(2) + +# Paddle 写法 +result = x.less_than(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_.md new file mode 100644 index 00000000000..1f0a2d49fa9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.less_ + +### [torch.Tensor.less_](https://pytorch.org/docs/stable/generated/torch.Tensor.less_.html) + +```python +torch.Tensor.less_(other) +``` + +### [paddle.Tensor.less_than_]() + +```python +paddle.Tensor.less_than_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.less_(2) + +# Paddle 写法 +result = x.less_than_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal.md new file mode 100644 index 00000000000..2e345ee6451 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.less_equal + +### [torch.Tensor.less_equal](https://pytorch.org/docs/stable/generated/torch.Tensor.less_equal.html) + +```python +torch.Tensor.less_equal(other) +``` + +### [paddle.Tensor.less_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#less-equal-y-name-none) + +```python +paddle.Tensor.less_equal(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.less_equal(2) + +# Paddle 写法 +result = x.less_equal(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal_.md new file mode 100644 index 00000000000..606a674454a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.less_equal_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.less_equal_ + +### [torch.Tensor.less_equal_](https://pytorch.org/docs/stable/generated/torch.Tensor.less_equal_.html) + +```python +torch.Tensor.less_equal_(other) +``` + +### [paddle.Tensor.less_equal_]() + +```python +paddle.Tensor.less_equal_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.less_equal_(2) + +# Paddle 写法 +result = x.less_equal_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma.md new file mode 100644 index 00000000000..b0ab4a59a93 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.lgamma + +### [torch.Tensor.lgamma](https://pytorch.org/docs/stable/generated/torch.lgamma.html#torch.lgamma) + +```python +torch.Tensor.lgamma() +``` + +### [paddle.Tensor.lgamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lgamma_cn.html) + +```python +paddle.Tensor.lgamma() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的自然对数伽马函数值的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma_.md new file mode 100644 index 00000000000..b546b373d33 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lgamma_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.lgamma_ + +### [torch.Tensor.lgamma_](https://pytorch.org/docs/stable/generated/torch.Tensor.lgamma_.html) + +```python +torch.Tensor.lgamma_() +``` + +### [paddle.Tensor.lgamma_]() + +```python +paddle.Tensor.lgamma_() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的自然对数伽马函数值的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log.md new file mode 100644 index 00000000000..4445d10ab81 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log + +### [torch.Tensor.log](https://pytorch.org/docs/stable/generated/torch.Tensor.log.html) + +```python +torch.Tensor.log() +``` + +### [paddle.Tensor.log](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#log-name-none) + +```python +paddle.Tensor.log() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的自然对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10.md new file mode 100644 index 00000000000..28b36ddaef4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log10 + +### [torch.Tensor.log10](https://pytorch.org/docs/stable/generated/torch.Tensor.log10.html#torch.Tensor.log10) + +```python +torch.Tensor.log10() +``` + +### [paddle.Tensor.log10](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#log10-name-none) + +```python +paddle.Tensor.log10() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的以 10 为底的对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10_.md new file mode 100644 index 00000000000..27408a12af6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log10_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log10_ + +### [torch.Tensor.log10_](https://pytorch.org/docs/stable/generated/torch.Tensor.log10_.html) + +```python +torch.Tensor.log10_() +``` + +### [paddle.Tensor.log10_](e) + +```python +paddle.Tensor.log10_() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的以 10 为底的对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p.md new file mode 100644 index 00000000000..2100581e224 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log1p + +### [torch.Tensor.log1p](https://pytorch.org/docs/stable/generated/torch.Tensor.log1p.html#torch.Tensor.log1p) + +```python +torch.Tensor.log1p() +``` + +### [paddle.Tensor.log1p](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#log1p-name-none) + +```python +paddle.Tensor.log1p() +``` + +两者功能一致,均无参数,用于计算张量中每个元素加 1 后的自然对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p_.md new file mode 100644 index 00000000000..511b4115f53 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log1p_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log1p_ + +### [torch.Tensor.log1p_](https://pytorch.org/docs/stable/generated/torch.Tensor.log1p_.html) + +```python +torch.Tensor.log1p_() +``` + +### [paddle.Tensor.log1p_]() + +```python +paddle.Tensor.log1p_() +``` + +两者功能一致,均无参数,用于计算张量中每个元素加 1 后的自然对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2.md new file mode 100644 index 00000000000..895b45946a5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log2 + +### [torch.Tensor.log2](https://pytorch.org/docs/stable/generated/torch.Tensor.log2.html#torch.Tensor.log2) + +```python +torch.Tensor.log2() +``` + +### [paddle.Tensor.log2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#log2-name-none) + +```python +paddle.Tensor.log2() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的以 2 为底的对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2_.md new file mode 100644 index 00000000000..58eca6495e2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log2_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log2_ + +### [torch.Tensor.log2_](https://pytorch.org/docs/stable/generated/torch.Tensor.log2_.html) + +```python +torch.Tensor.log2_() +``` + +### [paddle.Tensor.log2_]() + +```python +paddle.Tensor.log2_() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的以 2 为底的对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log_.md new file mode 100644 index 00000000000..66f7744b2cb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.log_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.log_ + +### [torch.Tensor.log_](https://pytorch.org/docs/stable/generated/torch.Tensor.log_.html) + +```python +torch.Tensor.log_() +``` + +### [paddle.Tensor.log_]() + +```python +paddle.Tensor.log_() +``` + +两者功能一致,均无参数,用于计算张量中每个元素的自然对数的函数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp.md new file mode 100644 index 00000000000..34ee2c2479b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.logaddexp + +### [torch.Tensor.logaddexp](https://pytorch.org/docs/stable/generated/torch.Tensor.logaddexp.html#torch.Tensor.logaddexp) + +```python +torch.Tensor.logaddexp(other) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.logaddexp(b) + +# Paddle 写法 +y = paddle.log(paddle.exp(a) + paddle.exp(b)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp2.md new file mode 100644 index 00000000000..e41582af1e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logaddexp2.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.logaddexp2 + +### [torch.Tensor.logaddexp2](https://pytorch.org/docs/stable/generated/torch.Tensor.logaddexp2.html#torch.Tensor.logaddexp2) + +```python +torch.Tensor.logaddexp2(other) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.logaddexp2(b) + +# Paddle 写法 +y = paddle.log2(2 ** a + 2 ** b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logcumsumexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logcumsumexp.md new file mode 100644 index 00000000000..289836ffa96 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logcumsumexp.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.logcumsumexp + +### [torch.Tensor.logcumsumexp](https://pytorch.org/docs/stable/generated/torch.Tensor.logcumsumexp.html?highlight=logcumsumexp#torch.Tensor.logcumsumexp) + +```python +torch.Tensor.logcumsumexp(dim) +``` + +### [paddle.Tensor.logcumsumexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logcumsumexp_cn.html#logcumsumexp) + +```python +paddle.Tensor.logcumsumexp(axis=None, dtype=None, name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| dim | axis | 指明需要计算的维,仅参数名不一致。 paddle 中默认 None。 | +| - | dtype | 输出 Tensor 的数据类型,支持 float32、float64。如果指定了,那么在执行操作之前,输入张量将被转换为 dtype,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logdet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logdet.md new file mode 100644 index 00000000000..7e0d5c15b8f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logdet.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.Tensor.logdet + +### [torch.Tensor.logdet](https://pytorch.org/docs/stable/generated/torch.Tensor.logdet.html#torch.Tensor.logdet) + +```python +torch.Tensor.logdet() +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = input.logdet() + +# Paddle 写法 +y = paddle.log(paddle.linalg.det(input)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and.md new file mode 100644 index 00000000000..3321ae885be --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor.logical_and + +### [torch.Tensor.logical_and](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_and.html) + +```python +torch.Tensor.logical_and(other) +``` + +### [paddle.Tensor.logical_and](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#logical-and-y-out-none-name-none) + +```python +paddle.Tensor.logical_and(y, + out=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| - | out | 指定算子输出结果的 Tensor,可以是程序中已经创建的任何 Tensor。默认值为 None,此时将创建新的 Tensor 来保存输出结果。PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and_.md new file mode 100644 index 00000000000..706d75e95c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_and_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.Tensor.logical_and_ + +### [torch.Tensor.logical_and_](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_and_.html) + +```python +torch.Tensor.logical_and_(other) +``` + +### [paddle.Tensor.logical_and_]() + +```python +paddle.Tensor.logical_and_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not.md new file mode 100644 index 00000000000..0ece44ec6ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor.logical_not + +### [torch.Tensor.logical_not](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_not.html) + +```python +torch.Tensor.logical_not() +``` + +### [paddle.Tensor.logical_not](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#logical-not-out-none-name-none) + +```python +paddle.Tensor.logical_not(out=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| - | out | 指定算子输出结果的 Tensor,可以是程序中已经创建的任何 Tensor。默认值为 None,此时将创建新的 Tensor 来保存输出结果。PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not_.md new file mode 100644 index 00000000000..bdf2ac22042 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_not_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.logical_not_ + +### [torch.Tensor.logical_not_](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_not_.html) + +```python +torch.Tensor.logical_not_() +``` + +### [paddle.Tensor.logical_not_]() + +```python +paddle.Tensor.logical_not_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or.md new file mode 100644 index 00000000000..843ceddf65d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor.logical_or + +### [torch.Tensor.logical_or](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_or.html) + +```python +torch.Tensor.logical_or(other) +``` + +### [paddle.Tensor.logical_or](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#logical-or-y-out-none-name-none) + +```python +paddle.Tensor.logical_or(y, + out=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------- | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| - | out | 指定算子输出结果的 Tensor,可以是程序中已经创建的任何 Tensor。默认值为 None,此时将创建新的 Tensor 来保存输出结果。PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or_.md new file mode 100644 index 00000000000..a23d96b55cd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_or_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.logical_or_ + +### [torch.Tensor.logical_or_](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_or_.html) + +```python +torch.Tensor.logical_or_(other) +``` + +### [paddle.Tensor.logical_or_]() + +```python +paddle.Tensor.logical_or_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor.md new file mode 100644 index 00000000000..75374f009d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.logical_xor + +### [torch.Tensor.logical_xor](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_xor.html) + +```python +torch.Tensor.logical_xor(other) +``` + +### [paddle.Tensor.logical_xor]() + +```python +paddle.Tensor.logical_xor(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor_.md new file mode 100644 index 00000000000..fed008219c3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logical_xor_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.logical_xor_ + +### [torch.Tensor.logical_xor_](https://pytorch.org/docs/stable/generated/torch.Tensor.logical_xor_.html) + +```python +torch.Tensor.logical_xor_(other) +``` + +### [paddle.Tensor.logical_xor_]() + +```python +paddle.Tensor.logical_xor_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit.md new file mode 100644 index 00000000000..e4c93d48301 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.logit + +### [torch.Tensor.logit](https://pytorch.org/docs/stable/generated/torch.Tensor.logit.html) + +```python +torch.Tensor.logit(eps=None) +``` + +### [paddle.Tensor.logit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#logit-eps-none-name-none) + +```python +paddle.Tensor.logit(eps=None, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| eps | eps | 传入该参数后可将 x 的范围控制在 [eps,1−eps],默认值为 None。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit_.md new file mode 100644 index 00000000000..b1041d22a36 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logit_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.logit_ + +### [torch.Tensor.logit_](https://pytorch.org/docs/stable/generated/torch.Tensor.logit_.html) + +```python +torch.Tensor.logit_(eps=None) +``` + +### [paddle.Tensor.logit_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logit_cn.html) + +```python +paddle.Tensor.logit_(eps=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| eps | eps | 将输入向量的范围控制在 [eps,1−eps] | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logsumexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logsumexp.md new file mode 100644 index 00000000000..a410c9d9e3f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.logsumexp.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ] torch.Tensor.logsumexp + + +### [torch.Tensor.logsumexp](https://pytorch.org/docs/stable/generated/torch.Tensor.logsumexp.html) + +```python +torch.Tensor.logsumexp(dim, + keepdim=False) +``` + +### [paddle.Tensor.logsumexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#logsumexp-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.logsumexp(axis=None, + keepdim=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.long.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.long.md new file mode 100644 index 00000000000..8fd516d010c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.long.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ] torch.Tensor.long + +### [torch.Tensor.long](https://pytorch.org/docs/stable/generated/torch.Tensor.long.html#torch.Tensor.long) + +```python +torch.Tensor.long(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype('int64') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lstsq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lstsq.md new file mode 100644 index 00000000000..b278928e98c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lstsq.md @@ -0,0 +1,45 @@ +## [ 参数不一致 ]torch.Tensor.lstsq + +### [torch.Tensor.lstsq](https://pytorch.org/docs/1.9.0/generated/torch.Tensor.lstsq.html?highlight=torch%20tensor%20lstsq#torch.Tensor.lstsq) + +```python +torch.Tensor.lstsq(A) +``` + +### [paddle.Tensor.lstsq]() + +```python +paddle.Tensor.lstsq(y, rcond=None, driver=None, name=None) +``` + +两者功能一致,参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------------------------------------------- | +| A | - | 线性方程组系数矩阵,Paddle 需要转写。 | +| - | y | 线性方程组右边的矩阵,Paddle 需要转写。 | +| - | rcond | 用来决定 x 有效秩的 float 型浮点数。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | driver | 用来指定计算使用的 LAPACK 库方法。PyTorch 无此参数,Paddle 保持默认即可。 | +| 返回值 | 返回值 | PyTorch 返回 solution、QR ,Paddle 返回 solution、residuals、rank、 singular_values,Paddle 与 PyTorch 仅第一个返回值相同,其他返回值结果不同,暂无转写方式。 | + +### 转写示例 + +#### A 参数转写 + +```python +# PyTorch 写法: +A = torch.tensor([[1, 1, 1], + [0, 2, 1], + [0, 0,-1]], dtype=torch.float64) +y = torch.tensor([[0], [-9], [5]], dtype=torch.float64) +y.lstsq(A) + +# Paddle 写法: +A = paddle.to_tensor([[1, 1, 1], + [0, 2, 1], + [0, 0,-1]], dtype=paddle.float64) +y = paddle.to_tensor([[0], [-9], [5]], dtype=paddle.float64) +A.lstsq(y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt.md new file mode 100644 index 00000000000..6ba59ba8c22 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.lt + +### [torch.Tensor.lt](https://pytorch.org/docs/stable/generated/torch.Tensor.lt.html) + +```python +torch.Tensor.lt(other) +``` + +### [paddle.Tensor.less_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#less-than-y-name-none) + +```python +paddle.Tensor.less_than(y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.lt(2) + +# Paddle 写法 +result = x.less_than(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt_.md new file mode 100644 index 00000000000..f28ef384c88 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lt_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.lt_ + +### [torch.Tensor.lt_](https://pytorch.org/docs/stable/generated/torch.Tensor.lt_.html) + +```python +torch.Tensor.lt_(other) +``` + +### [paddle.Tensor.less_than_]() + +```python +paddle.Tensor.less_than_(y) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|------------------------------| ------------------------------------------------------ | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +result = x.lt_(2) + +# Paddle 写法 +result = x.less_than_(paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lu.md new file mode 100644 index 00000000000..be2805a77cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.lu.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.Tensor.lu + +### [torch.Tensor.lu](https://pytorch.org/docs/stable/generated/torch.Tensor.lu.html) + +```python +torch.Tensor.lu(pivot=True, get_infos=False) +``` + +### [paddle.Tensor.lu]() + +```python +paddle.Tensor.lu(pivot=True, get_infos=False, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | -- | +| pivot | pivot | LU 分解时是否进行旋转。 | +| get_infos | get_infos | 是否返回分解状态信息,若为 True,则返回分解状态 Tensor,否则不返回。默认 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mH.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mH.md new file mode 100644 index 00000000000..d236bb96d10 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mH.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ] torch.Tensor.mH + +### [torch.Tensor.mH](https://pytorch.org/docs/stable/tensors.html?#torch.Tensor.mH) + +```python +torch.Tensor.mH +``` + +Paddle 无此 API,需要组合实现。 +PyTorch 中等于 x.transpose(-2, -1).conj(),Paddle 中 transpose 参数 perm 为转换后的维度位置。 + +### 转写示例 + +```python +# 假设 x 为 4D +# PyTorch 写法 +y = x.mH + +# Paddle 写法 +y = x.transpose(perm=[0, 1, 3, 2]).conj() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mT.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mT.md new file mode 100644 index 00000000000..a47ff61864a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mT.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ] torch.Tensor.mT + +### [torch.Tensor.mT](https://pytorch.org/docs/stable/tensors.html?#torch.Tensor.mT) + +```python +torch.Tensor.mT +``` + +Paddle 无此 API,需要组合实现。 +PyTorch 中等于 x.transpose(-2, -1),Paddle 中 transpose 参数 perm 为转换后的维度位置。 + +### 转写示例 + +```python +# 假设 x 为 4D +# PyTorch 写法 +y = x.mT + +# Paddle 写法 +y = x.transpose(x, perm=[0, 1, 3, 2]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill.md new file mode 100644 index 00000000000..76e7d54d4b2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ] torch.Tensor.masked_fill + +### [torch.Tensor.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html?highlight=masked_fill#torch.Tensor.masked_fill) + +```python +torch.Tensor.masked_fill(mask, value) +``` + +### [paddle.Tensor.masked_fill](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-fill-mask-value-name-non) + +```python +paddle.Tensor.masked_fill(mask, value, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| mask | mask | 布尔张量,表示要填充的位置 | +| value | value | 用于填充目标张量的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill_.md new file mode 100644 index 00000000000..89b460a725f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_fill_.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ] torch.Tensor.masked_fill_ + +### [torch.Tensor.masked_fill_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill_.html?highlight=masked_fill_#torch.Tensor.masked_fill_) + +```python +torch.Tensor.masked_fill_(mask, value) +``` + +### [paddle.Tensor.masked_fill_]() + +```python +paddle.Tensor.masked_fill_(mask, value, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| mask | mask | 布尔张量,表示要填充的位置 | +| value | value | 用于填充目标张量的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter.md new file mode 100644 index 00000000000..f7b796a9aaf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ] torch.Tensor.masked_scatter + +### [torch.Tensor.masked_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter.html?highlight=masked_scatter#torch.Tensor.masked_scatter) + +```python +torch.Tensor.masked_scatter(mask, value) +``` + +### [paddle.Tensor.masked_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#masked-scatter-mask-value-name-non) + +```python +paddle.Tensor.masked_scatter(mask, value, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| mask | mask | 布尔张量,表示要填充的位置 | +| value | value | 用于填充目标张量的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter_.md new file mode 100644 index 00000000000..a4d97f82810 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_scatter_.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ] torch.Tensor.masked_scatter_ + +### [torch.Tensor.masked_scatter_](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_scatter_.html?highlight=masked_scatter#torch.Tensor.masked_scatter_) + +```python +torch.Tensor.masked_scatter_(mask, value) +``` + +### [paddle.Tensor.masked_scatter_]() + +```python +paddle.Tensor.masked_scatter_(mask, value, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| mask | mask | 布尔张量,表示要填充的位置 | +| value | value | 用于填充目标张量的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_select.md new file mode 100644 index 00000000000..98818c61a4a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.masked_select.md @@ -0,0 +1,21 @@ +## [参数完全一致 ]torch.Tensor.masked_select + +### [torch.Tensor.masked_select](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_select.html?highlight=masked_select#torch.Tensor.masked_select) + +```python +torch.Tensor.masked_select(mask) +``` + +### [paddle.Tensor.masked_select](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#masked-select-mask-name-none) + +```python +paddle.Tensor.masked_select(mask, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------ | +| mask | mask | 表示用于索引的二进制掩码的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matmul.md new file mode 100644 index 00000000000..2d72140a390 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matmul.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.matmul + +### [torch.Tensor.matmul](https://pytorch.org/docs/stable/generated/torch.Tensor.matmul.html) + +```python +torch.Tensor.matmul(other) +``` + +### [paddle.Tensor.matmul](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#matmul-y-transpose-x-false-transpose-y-false-name-none) + +```python +paddle.Tensor.matmul(y, transpose_x=False, transpose_y=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅 Paddle 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---- | +| other | y | 输入变量,仅参数名不一致。 | +| - | transpose_x | 相乘前是否转置 x,仅 Paddle 参数更多,保持默认即可。 | +| - | transpose_y | 相乘前是否转置 y,仅 Paddle 参数更多,保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matrix_power.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matrix_power.md new file mode 100644 index 00000000000..ee35f60752a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.matrix_power.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.matrix_power + +### [torch.Tensor.matrix\_power](https://pytorch.org/docs/stable/generated/torch.Tensor.matrix_power.html) + +```python +torch.Tensor.matrix_power(n) +``` + +### [paddle.Tensor.matrix\_power](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#matrix-power-x-n-name-none) + +```python +paddle.Tensor.matrix_power(n, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| n | n | 输入的幂次,类型为 int。它可以是任意整数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.maximum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.maximum.md new file mode 100644 index 00000000000..3c246b78f73 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.maximum.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ] torch.Tensor.maximum + +### [torch.Tensor.maximum](https://pytorch.org/docs/stable/generated/torch.Tensor.maximum.html#torch.Tensor.maximum) + +```python +torch.Tensor.maximum(other) +``` + +### [paddle.Tensor.maximum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#maximum-y-axis-1-name-none) + +```python +paddle.Tensor.maximum(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|---------------------------------|------------------------------------| +| other | y | 输⼊第二个 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mean.md new file mode 100644 index 00000000000..e69a96df446 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mean.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.Tensor.mean + +### [torch.Tensor.mean](https://pytorch.org/docs/stable/generated/torch.Tensor.mean.html) + +```python +torch.Tensor.mean(dim=None, keepdim=False, *, dtype=None) +``` + +### [paddle.Tensor.mean](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#mean-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.mean(axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| dtype | - | 输出 Tensor 的类型,Paddle 无此参数, 需要转写。 | + +### 转写示例 + +#### dtype:输出数据类型 +```python +# PyTorch 写法 +x.mean(dtype=torch.float32) + +# Paddle 写法 +x.mean().astype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.median.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.median.md new file mode 100644 index 00000000000..e1854dc94c3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.median.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.median + +### [torch.Tensor.median](https://pytorch.org/docs/stable/generated/torch.Tensor.median.html) + +```python +torch.Tensor.median(dim=None, keepdim=False) +``` + +### [paddle.Tensor.median](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#median-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.median(axis=None, keepdim=False, mode='avg', name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| ------- | mode | 当 x 在所需要计算的轴上有偶数个元素时,选择使用平均值或最小值确定中位数的值, PyTorch 无此参数, Paddle 需设置为 'min'。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.minimum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.minimum.md new file mode 100644 index 00000000000..360e6b77f33 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.minimum.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ] torch.Tensor.minimum + +### [torch.Tensor.minimum](https://pytorch.org/docs/stable/generated/torch.Tensor.minimum.html) + +```python +torch.Tensor.minimum(other) +``` + +### [paddle.Tensor.minimum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#minimum-y-axis-1-name-none) + +```python +paddle.Tensor.minimum(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +| PyTorch | PaddlePaddle | 备注 | +|----------------------------------|---------------------------------|------------------------------------| +| other | y | 输⼊第二个 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mm.md new file mode 100644 index 00000000000..9fdda57cef7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mm.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.mm + +### [torch.Tensor.mm](https://pytorch.org/docs/stable/generated/torch.Tensor.mm.html) + +```python +torch.Tensor.mm(mat2) +``` + +### [paddle.Tensor.mm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#mm-mat2-name-none) + +```python +paddle.Tensor.mm(mat2, name=None) +``` + +两者功能一致且参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------------------------------|---------------------------------| ----------------------------------------- | +| mat2 | mat2 | 输⼊ Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mode.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mode.md new file mode 100644 index 00000000000..9cabd358f1e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mode.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.mode + +### [torch.Tensor.mode](https://pytorch.org/docs/stable/generated/torch.Tensor.mode.html) + +```python +torch.Tensor.mode(dim=None, keepdim=False) +``` + +### [paddle.Tensor.mode](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#mode-axis-1-keepdim-false-name-none) + +```python +paddle.Tensor.mode(axis=-1, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否保留指定的轴。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.moveaxis.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.moveaxis.md new file mode 100644 index 00000000000..debeec5ea6d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.moveaxis.md @@ -0,0 +1,20 @@ +## [ 参数完全一致 ]torch.Tensor.moveaxis + +### [torch.Tensor.moveaxis](https://pytorch.org/docs/stable/generated/torch.Tensor.moveaxis.html) + +```python +torch.Tensor.moveaxis(source, destination) +``` + +### [paddle.Tensor.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/moveaxis_cn.html) + +```python +paddle.Tensor.moveaxis(source, destination,name = None) +``` + +两者功能一致且参数用法一致,具体如下: + +| PyTorch | PaddlePaddle | 备注 | +|------------------------------------|------------------------------------|----------------------------------| +| source | source | 将被移动的轴的位置。 | +| destination | destination | 轴被移动后的目标位置。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.movedim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.movedim.md new file mode 100644 index 00000000000..a3d4a415356 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.movedim.md @@ -0,0 +1,20 @@ +## [ 参数完全一致 ]torch.Tensor.movedim + +### [torch.Tensor.movedim](https://pytorch.org/docs/stable/generated/torch.Tensor.movedim.html) + +```python +torch.Tensor.movedim(source, destination) +``` + +### [paddle.Tensor.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/moveaxis_cn.html) + +```python +paddle.Tensor.moveaxis(source, destination, name = None) +``` + +两者功能一致且参数用法一致,具体如下: + +| PyTorch | PaddlePaddle | 备注 | +|------------------------------------|------------------------------------|----------------------------------| +| source | source | 将被移动的轴的位置。 | +| destination | destination | 轴被移动后的目标位置。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.msort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.msort.md new file mode 100644 index 00000000000..feed58081c4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.msort.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.msort + +### [torch.Tensor.msort](https://pytorch.org/docs/stable/generated/torch.Tensor.msort.html#torch.Tensor.msort) + +```python +torch.Tensor.msort() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.msort() + +# Paddle 写法 +y = paddle.sort(a, axis=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mul.md new file mode 100644 index 00000000000..05654002a91 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mul.md @@ -0,0 +1,34 @@ +## [ 参数不一致 ] torch.Tensor.mul + +### [torch.Tensor.mul](https://pytorch.org/docs/stable/generated/torch.Tensor.mul.html) + +```python +torch.Tensor.mul(other) +``` + +### [paddle.Tensor.multiply](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#multiply-y-axis-1-name-none) + +```python +paddle.Tensor.multiply(y, + axis=-1, + name=None) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 相乘的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | +| - | axis | 计算的维度,PyTorch 无此参数, Paddle 保持默认即可。| + +### 转写示例 +#### other:相乘的元素 +```python +# PyTorch 写法 +y = x.mul(other=2) + +# Paddle 写法 +y = x.multiply(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multinomial.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multinomial.md new file mode 100644 index 00000000000..3b2f8bfcff6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multinomial.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.Tensor.multinomial + +### [torch.Tensor.multinomial](https://pytorch.org/docs/stable/generated/torch.Tensor.multinomial.html#torch.Tensor.multinomial) + +```python +torch.Tensor.multinomial(num_samples, replacement=False, *, generator=None) +``` + +### [paddle.Tensor.multinomial]() + +```python +paddle.Tensor.multinomial(num_samples=1, replacement=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------- | +| num_samples | num_samples | 采样的次数。 | +| replacement | replacement | 是否是可放回的采样。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply.md new file mode 100644 index 00000000000..a493dbaa2a2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply.md @@ -0,0 +1,34 @@ +## [ 参数不一致 ] torch.Tensor.multiply + +### [torch.Tensor.multiply](https://pytorch.org/docs/stable/generated/torch.Tensor.multiply.html) + +```python +torch.Tensor.multiply(other) +``` + +### [paddle.Tensor.multiply](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#multiply-y-axis-1-name-none) + +```python +paddle.Tensor.multiply(y, + axis=-1, + name=None) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 相乘的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | +| - | axis | 计算的维度,PyTorch 无此参数, Paddle 保持默认即可。| + +### 转写示例 +#### other:相乘的元素 +```python +# PyTorch 写法 +y = x.multiply(other=2) + +# Paddle 写法 +y = x.multiply(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply_.md new file mode 100644 index 00000000000..ad5e8474b31 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.multiply_.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ] torch.Tensor.multiply_ + +### [torch.Tensor.multiply_](https://pytorch.org/docs/stable/generated/torch.Tensor.multiply_.html) + +```python +torch.Tensor.multiply_(other) +``` + +### [paddle.Tensor.multiply_]() + +```python +paddle.Tensor.multiply_(y, + axis=-1, + name=None) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 相乘的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | +| - | axis | 计算的维度,PyTorch 无此参数, Paddle 保持默认即可。| + +### 转写示例 + +#### other:相乘的元素 +```python +# PyTorch 写法 +x.multiply_(other=2) + +# Paddle 写法 +x.multiply_(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mv.md new file mode 100644 index 00000000000..b226ebeb0f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.mv.md @@ -0,0 +1,20 @@ +## [ 参数完全一致 ] torch.Tensor.mv +### [torch.Tensor.mv](https://pytorch.org/docs/stable/generated/torch.Tensor.mv.html) + +```python +torch.Tensor.mv(vec) +``` + +### [paddle.Tensor.mv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#mv-vec-name-none) + +```python +paddle.Tensor.mv(vec) +``` + +两者功能一致,且参数一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| vec | vec | 相乘的向量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num.md new file mode 100644 index 00000000000..9fa820ddfc2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num.md @@ -0,0 +1,23 @@ +## [参数完全一致]torch.Tensor.nan_to_num + +### [torch.Tensor.nan_to_num](https://pytorch.org/docs/stable/generated/torch.Tensor.nan_to_num.html#torch.Tensor.nan_to_num) + +```python +torch.Tensor.nan_to_num(nan=0.0, posinf=None, neginf=None) +``` + +### [paddle.Tensor.nan_to_num](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#nan-to-num) + +```python +paddle.Tensor.nan_to_num(nan=0.0, posinf=None, neginf=None) +``` + +两者功能一致,且参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------- | +| nan | nan | NaN 的替换值。 | +| posinf | posinf | +inf 的替换值。 | +| neginf | neginf | -inf 的替换值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num_.md new file mode 100644 index 00000000000..719136aa761 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nan_to_num_.md @@ -0,0 +1,23 @@ +## [参数完全一致]torch.Tensor.nan_to_num_ + +### [torch.Tensor.nan_to_num_](https://pytorch.org/docs/stable/generated/torch.Tensor.nan_to_num_.html#torch.Tensor.nan_to_num_) + +```python +torch.Tensor.nan_to_num_(nan=0.0, posinf=None, neginf=None) +``` + +### [paddle.Tensor.nan_to_num_]() + +```python +paddle.Tensor.nan_to_num_(nan=0.0, posinf=None, neginf=None) +``` + +两者功能一致,且参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------- | +| nan | nan | NaN 的替换值。 | +| posinf | posinf | +inf 的替换值。 | +| neginf | neginf | -inf 的替换值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmean.md new file mode 100644 index 00000000000..c9abeede8e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmean.md @@ -0,0 +1,51 @@ +## [ torch 参数更多 ]torch.Tensor.nanmean + +### [torch.Tensor.nanmean](https://pytorch.org/docs/stable/generated/torch.Tensor.nanmean.html?highlight=nanmean#torch.Tensor.nanmean) + +```python +torch.Tensor.nanmean(dim=None, + keepdim=False, + dtype=None, + out=None) +``` + +### [paddle.Tensor.nanmean](暂无对应文档) + +```python +paddle.Tensor.nanmean(axis=None, + keepdim=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示进行运算的轴,可选项,仅参数名不一致。 | +| keepdim | keepdim | 表示是否保留计算后的维度,可选项。 | +| dtype | - | 指定输出数据类型,可选项,PyTorch 默认值为 None,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,可选项,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### dytpe:指定数据类型 + +```python +# PyTorch 写法 +x.nanmean(dim=-1, dtype=torch.float32,out=y) + +# Paddle 写法 +x.astype('float32') +paddle.assign(x.nanmean(dim=-1),y) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +x.nanmean(dim=1,out=y) + +# Paddle 写法 +paddle.assign(x.nanmean(dim=1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmedian.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmedian.md new file mode 100644 index 00000000000..3e069b2b7f1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanmedian.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.nanmedian + +### [torch.Tensor.nanmedian](https://pytorch.org/docs/stable/generated/torch.Tensor.nanmedian.html) + +```python +torch.Tensor.nanmedian(dim=None, keepdim=False) +``` + +### [paddle.Tensor.nanmedian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#nanmedian-axis-none-keepdim-true-name-none) + +```python +paddle.Tensor.nanmedian(axis=None, keepdim=False, mode='avg', name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| ------- | mode | 当 x 在所需要计算的轴上有偶数个非 NaN 元素时,选择使用平均值或最小值确定非 NaN 中位数的值, PyTorch 无此参数, Paddle 需设置为 'min'。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanquantile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanquantile.md new file mode 100644 index 00000000000..a62c9ceb326 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nanquantile.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ] torch.Tensor.nanquantile + +### [torch.Tensor.nanquantile](https://pytorch.org/docs/stable/generated/torch.nanquantile.html#torch.nanquantile) + +```python +torch.Tensor.nanquantile(q, dim=None, keepdim=False, *, interpolation='linear') +``` + +### [paddle.Tensor.nanquantile](https://github.com/PaddlePaddle/Paddle/pull/41343) + +```python +paddle.Tensor.nanquantile(q, axis=None, keepdim=False, interpolation='linear') +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------------------------------------------------------------------| +| q | q | 待计算的分位数。| +| dim | axis | 求乘积运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留输入的维度。 | +| interpolation | interpolation | 指定当所需分位数位于两个数据点之间时使用的插值方法。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nansum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nansum.md new file mode 100644 index 00000000000..24f1b469f5e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nansum.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ] torch.Tensor.nansum +### [torch.Tensor.nansum](https://pytorch.org/docs/stable/generated/torch.Tensor.nansum.html?highlight=nansum#torch.Tensor.nansum) + +```python +torch.Tensor.nansum(dim=None, + keepdim=False, + dtype=None) +``` + +### [paddle.Tensor.nansum]() + +```python +paddle.Tensor.nansum(axis=None, + keepdim=False, + dtype=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 需要求和的维度,仅参数名不一致。 | +| keepdim | keepdim | 结果是否需要保持维度不变,仅参数名不一致。 | +| dtype | dtype | 返回的 Tensor 的类型,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow.md new file mode 100644 index 00000000000..c533b5765de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow.md @@ -0,0 +1,36 @@ +## [ 参数不一致 ]torch.Tensor.narrow +### [torch.Tensor.narrow](https://pytorch.org/docs/stable/generated/torch.Tensor.narrow.html#torch.Tensor.narrow) + +```python +torch.Tensor.narrow(dim, start, length) +``` + +### [paddle.slice](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/slice_cn.html#slice) +```python +paddle.slice(input, + axes, + starts, + ends) +``` + +其中 PyTorch 的 length 与 Paddle 的 ends 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| - | input | 表示输入的 Tensor 。 | +| dim | axes | 表示切片的轴。 | +| start | starts | 表示起始位置。 | +| length | - | 到结束位置的长度,Paddle 无此参数,需要转写。Paddle 应改写 ends。 | +| - | ends | 表示结束位置,PyTorch 无此参数,应设为 start + length 。 | + +### 转写示例 + +```python +# PyTorch 写法 +y = a.narrow(1, 1, 4) + +# Paddle 写法 +# Paddle 可通过设置 ends-starts=length 来实现 PyTorch 的 length 功能 +y = paddle.slice(a, [1], [1], [5]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow_copy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow_copy.md new file mode 100644 index 00000000000..7abc0c71cdc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.narrow_copy.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.narrow_copy + +### [torch.Tensor.narrow_copy](https://pytorch.org/docs/stable/generated/torch.Tensor.narrow_copy.html#torch.Tensor.narrow_copy) + +```python +torch.Tensor.narrow_copy(dimension, start, length) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.narrow_copy(1, 1, 4) + +# Paddle 写法 +y = paddle.assign(paddle.slice(a, [1], [1], [5])) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndim.md new file mode 100644 index 00000000000..945a6e7bb64 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndim.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.ndim + +### [torch.Tensor.ndim](https://pytorch.org/docs/stable/generated/torch.Tensor.ndim.html) + +```python +torch.Tensor.ndim +``` + +### [paddle.Tensor.ndim](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#ndim) + +```python +paddle.Tensor.ndim +``` + +两者功能一致,均无参数,查看一个 Tensor 的维度。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndimension.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndimension.md new file mode 100644 index 00000000000..e0c3826b01a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ndimension.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.ndimension + +### [torch.Tensor.ndimension](https://pytorch.org/docs/stable/generated/torch.Tensor.ndimension.html?highlight=ndimension#torch.Tensor.ndimension) + +```python +torch.Tensor.ndimension() +``` + +### [paddle.Tensor.ndimension](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#ndimension) + +```python +paddle.Tensor.ndimension() +``` + +两者功能一致,均无参数,查看一个 Tensor 的维度。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne.md new file mode 100644 index 00000000000..82e50bbdb27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ] torch.Tensor.ne +### [torch.Tensor.ne](https://pytorch.org/docs/stable/generated/torch.Tensor.ne.html?highlight=ne) + +```python +torch.Tensor.ne(other) +``` + +### [paddle.Tensor.not_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#not-equal-y-name-none) + +```python +paddle.Tensor.not_equal(y) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 比较的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other:比较的元素 +```python +# PyTorch 写法 +y = x.ne(other=2) + +# Paddle 写法 +y = x.not_equal(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne_.md new file mode 100644 index 00000000000..89d6043dca4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ne_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ] torch.Tensor.ne_ +### [torch.Tensor.ne_](https://pytorch.org/docs/stable/generated/torch.Tensor.ne_.html) + +```python +torch.Tensor.ne_(other) +``` + +### [paddle.Tensor.not_equal_]() + +```python +paddle.Tensor.not_equal_(y) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 比较的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other:比较的元素 +```python +# PyTorch 写法 +y = x.ne_(other=2) + +# Paddle 写法 +y = x.not_equal_(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg.md new file mode 100644 index 00000000000..f05ad826217 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.neg + +### [torch.Tensor.neg](https://pytorch.org/docs/stable/generated/torch.Tensor.neg.html?highlight=neg#torch.Tensor.neg) + +```python +torch.Tensor.neg() +``` + +### [paddle.Tensor.neg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#neg-name-none) + +```python +paddle.Tensor.neg() +``` + +两者功能一致,均无参数,将 Tensor 上的各个值取相反数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg_.md new file mode 100644 index 00000000000..e1cc849c129 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.neg_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.neg_ + +### [torch.Tensor.neg_](https://pytorch.org/docs/stable/generated/torch.Tensor.neg_.html) + +```python +torch.Tensor.neg_() +``` + +### [paddle.Tensor.neg_]() + +```python +paddle.Tensor.neg_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative.md new file mode 100644 index 00000000000..5d01bdc0d5c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.negative + +### [torch.Tensor.negative](https://pytorch.org/docs/stable/generated/torch.negative.html#torch.negative) + +```python +torch.Tensor.negative() +``` + +### [paddle.Tensor.neg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/neg_cn.html#cn-api-paddle-neg) + +```python +paddle.Tensor.neg() +``` + +两者功能一致,均无参数,用于计算输入 x 的相反数并返回。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative_.md new file mode 100644 index 00000000000..7b714e047ff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.negative_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.negative_ + +### [torch.Tensor.negative_](https://pytorch.org/docs/stable/generated/torch.Tensor.negative_.html) + +```python +torch.Tensor.negative_() +``` + +### [paddle.Tensor.neg_]() + +```python +paddle.Tensor.neg_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nelement.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nelement.md new file mode 100644 index 00000000000..0fd21948dd2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nelement.md @@ -0,0 +1,17 @@ +## [ 无参数 ] torch.Tensor.nelement + +### [torch.Tensor.nelement](https://pytorch.org/docs/stable/generated/torch.Tensor.nelement.html?highlight=nelement#torch.Tensor.nelement) + +```python +torch.Tensor.nelement() +``` + +### [paddle.Tensor.size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fluid/layers/size_cn.html#cn-api-fluid-layers-size) + +```python +paddle.Tensor.size() +``` + + + +两者功能一致,均无参数,用于返回张量的单元数量,是一个 int 型的整数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_empty.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_empty.md new file mode 100644 index 00000000000..ef77921c3d1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_empty.md @@ -0,0 +1,82 @@ +## [torch 参数更多]torch.Tensor.new_empty + +### [torch.Tensor.new_empty](https://pytorch.org/docs/stable/generated/torch.Tensor.new_empty.html#torch-tensor-new-empty) + +```python +torch.Tensor.new_empty(*size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) +``` + +### [paddle.empty](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/empty_cn.html) + +```python +paddle.empty(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| *size | shape | 表示输出形状大小, PyTorch 是可变参数用法, Paddle 是列表或元组,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型,如果没有指定,默认使用当前对象的 dtype,需要转写。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### size:输出形状大小 + +```python +# PyTorch 写法 +x.new_empty(3, 5) + +# Paddle 写法 +paddle.empty([3, 5]) +``` + +#### dtype:数据类型 + +```python +# PyTorch 写法 +x.new_empty(3, 5) + +# Paddle 写法 +paddle.empty([3, 5], dtype=x.dtype) +``` + +#### device: Tensor torch 的设备 + +```python +# PyTorch 写法 +y = x.new_empty((3, 5), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.empty([3, 5]) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = x.new_empty((3, 5), requires_grad=True) + +# Paddle 写法 +y = paddle.empty([3, 5]) +y.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = x.new_empty((3, 5), pin_memory=True) + +# Paddle 写法 +y = paddle.empty([3, 5]).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_full.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_full.md new file mode 100644 index 00000000000..ccab1ea982c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_full.md @@ -0,0 +1,74 @@ +## [torch 参数更多]torch.Tensor.new_full + +### [torch.Tensor.new_full](https://pytorch.org/docs/stable/generated/torch.Tensor.new_full.html#torch-tensor-new-full) + +```python +torch.Tensor.new_full(size, fill_value, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) +``` + +### [paddle.full](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/full_cn.html) + +```python +paddle.full(shape, + fill_value, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ----------- | ----------------------------------------------------------- | +| size | shape | 表示创建 Tensor 的形状,仅参数名不一致。 | +| fill_value | fill_value | 表示初始化输出 Tensor 的常量数据的值 | +| dtype | dtype | 表示输出 Tensor 类型,如果没有指定,默认使用当前对象的 dtype,需要转写。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### dtype:数据类型 + +```python +# PyTorch 写法 +x.new_full(3, 5, 1.) + +# Paddle 写法 +paddle.full([3, 5], 1., dtype=x.dtype) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = x.new_full([3, 5], 1., device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.full([3, 5], 1.) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = x.new_full([3, 5], 1., requires_grad=True) + +# Paddle 写法 +y = paddle.full([3, 5], 1.) +y.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = x.new_full((3, 5), 1., pin_memory=True) + +# Paddle 写法 +y = paddle.full([3, 5], 1.).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_ones.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_ones.md new file mode 100644 index 00000000000..0162f3d889b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_ones.md @@ -0,0 +1,83 @@ +## [torch 参数更多]torch.Tensor.new_ones + +### [torch.Tensor.new_ones](https://pytorch.org/docs/stable/generated/torch.Tensor.new_ones.html#torch-tensor-new-ones) + +```python +torch.Tensor.new_ones(*size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) +``` + +### [paddle.ones](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/ones_cn.html) + +```python +paddle.ones(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| *size | shape | 表示输出形状大小, PyTorch 是可变参数用法, Paddle 是列表或元组,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型,如果没有指定,默认使用当前对象的 dtype,需要转写。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### size:输出形状大小 + +```python +# PyTorch 写法 +x.new_ones(3, 5) + +# Paddle 写法 +paddle.ones([3, 5]) +``` + +#### dtype:数据类型 + +```python +# PyTorch 写法 +x.new_ones(3, 5) + +# Paddle 写法 +paddle.ones([3, 5], dtype=x.dtype) +``` + + +#### device: Tensor torch 的设备 + +```python +# PyTorch 写法 +y = x.new_ones((3, 5), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.ones([3, 5]) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = x.new_ones((3, 5), requires_grad=True) + +# Paddle 写法 +y = paddle.ones([3, 5]) +y.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = x.new_ones((3, 5), pin_memory=True) + +# Paddle 写法 +y = paddle.ones([3, 5]).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_tensor.md new file mode 100644 index 00000000000..5341399083c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_tensor.md @@ -0,0 +1,58 @@ +## [torch 参数更多]torch.Tensor.new_tensor + +### [torch.Tensor.new_tensor](https://pytorch.org/docs/stable/generated/torch.Tensor.new_tensor.html#torch-tensor-new-tensor) + +```python +torch.Tensor.new_tensor(data, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html) + +```python +paddle.to_tensor(data, dtype=None, place=None, stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| data | data | 数据内容。 | +| dtype | dtype | 表示输出 Tensor 类型,如果没有指定,默认使用当前对象的 dtype,需要转写。 | +| device | place | 创建 tensor 的设备位置,仅参数名不一致。 | +| requires_grad | stop_gradient | 表示是否计算梯度,两者参数功能相反,需要转写。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### dtype:数据类型 + +```python +# PyTorch 写法 +y = x.new_tensor(data) + +# Paddle 写法 +y = paddle.to_tensor(data, dtype=x.dtype) +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = x.new_tensor(data, requires_grad=True) + +# Paddle 写法 +y = paddle.to_tensor(data, stop_gradient=False) +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = x.new_tensor(data, pin_memory=True) + +# Paddle 写法 +y = paddle.to_tensor(data).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_zeros.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_zeros.md new file mode 100644 index 00000000000..19bd203aad5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.new_zeros.md @@ -0,0 +1,82 @@ +## [torch 参数更多]torch.Tensor.new_zeros + +### [torch.Tensor.new_zeros](https://pytorch.org/docs/stable/generated/torch.Tensor.new_zeros.html#torch-tensor-new-zeros) + +```python +torch.Tensor.new_zeros(*size, *, dtype=None, device=None, requires_grad=False, layout=torch.strided, pin_memory=False) +``` + +### [paddle.zeros](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/zeros_cn.html) + +```python +paddle.zeros(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| *size | shape | 表示输出形状大小, PyTorch 是可变参数用法, Paddle 是列表或元组,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型,如果没有指定,默认使用当前对象的 dtype,需要转写。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### size:输出形状大小 + +```python +# PyTorch 写法 +x.new_zeros(3, 5) + +# Paddle 写法 +paddle.zeros([3, 5]) +``` + +#### dtype: 数据类型 + +```python +# PyTorch 写法 +x.new_zeros(3, 5) + +# Paddle 写法 +paddle.zeros([3, 5], dtype=x.dtype) +``` + +#### device: Tensor torch 的设备 + +```python +# PyTorch 写法 +y = x.new_zeros((3, 5), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.zeros([3, 5]) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = x.new_zeros((3, 5), requires_grad=True) + +# Paddle 写法 +y = paddle.zeros([3, 5]) +y.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = x.new_zeros((3, 5), pin_memory=True) + +# Paddle 写法 +y = paddle.zeros([3, 5]).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nextafter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nextafter.md new file mode 100644 index 00000000000..ec5933db60a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nextafter.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.Tensor.nextafter + +### [torch.Tensor.nextafter](https://pytorch.org/docs/stable/generated/torch.Tensor.nextafter.html#torch.Tensor.nextafter) + +```python +torch.Tensor.nextafter(other) +``` + +### [paddle.Tensor.nextafter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nextafter_cn.html) + +```python +paddle.Tensor.nextafter(y) +``` + +两者功能一致,且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| other | y | 输⼊第二个 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nonzero.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nonzero.md new file mode 100644 index 00000000000..9b0dbfc195f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.nonzero.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.nonzero + +### [torch.Tensor.nonzero](https://pytorch.org/docs/stable/generated/torch.Tensor.nonzero.html?highlight=nonzero#torch.Tensor.nonzero) + +```python +torch.Tensor.nonzero() +``` + +### [paddle.Tensor.nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nonzero_cn.html#cn-api-tensor-search-nonzero) + +```python +paddle.Tensor.nonzero() +``` + +两者功能一致,均无参数,用于返回输入 `x` 中非零元素的坐标。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.norm.md new file mode 100644 index 00000000000..4852864dab0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.norm.md @@ -0,0 +1,37 @@ +## [torch 参数更多]torch.Tensor.norm + +### [torch.Tensor.norm](https://pytorch.org/docs/stable/generated/torch.Tensor.norm.html#torch.Tensor.norm) + +```python +torch.Tensor.norm(p='fro', dim=None, keepdim=False, dtype=None) +``` + +### [paddle.Tensor.norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#norm-p-fro-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.norm(p='fro', axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------- | +| p | p | 范数(ord)的种类。 | +| dim | axis | 使用范数计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 | +| dtype | - | 输出数据类型,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### dtype 参数:输出数据类型 + +```python +# PyTorch 写法 +x.norm(dim=-1, dtype=torch.float32) + +# Paddle 写法 +y = x.astype('float32') +y.norm(dim=-1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.normal_.md new file mode 100644 index 00000000000..d8fec0a8103 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.normal_.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.Tensor.normal_ + +### [torch.Tensor.normal_](https://pytorch.org/docs/stable/generated/torch.Tensor.normal_.html#torch-tensor-normal) + +```python +torch.Tensor.normal_(mean=0, std=1, *, generator=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +x.normal_(mean=0) + +# Paddle 写法 +paddle.assign(paddle.normal(mean=0, shape=x.shape).astype(x.dtype), x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal.md new file mode 100644 index 00000000000..0f30356ddba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ] torch.Tensor.not_equal +### [torch.Tensor.not_equal](https://pytorch.org/docs/stable/generated/torch.Tensor.not_equal.html) + +```python +torch.Tensor.not_equal(other) +``` + +### [paddle.Tensor.not_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#not-equal-y-name-none) + +```python +paddle.Tensor.not_equal(y) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 比较的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other:比较的元素 +```python +# PyTorch 写法 +y = x.not_equal(other=2) + +# Paddle 写法 +y = x.not_equal(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal_.md new file mode 100644 index 00000000000..72aa0ab9b86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.not_equal_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ] torch.Tensor.not_equal_ +### [torch.Tensor.not_equal_](https://pytorch.org/docs/stable/generated/torch.Tensor.not_equal_.html) + +```python +torch.Tensor.not_equal_(other) +``` + +### [paddle.Tensor.not_equal_]() + +```python +paddle.Tensor.not_equal_(y) +``` + +其中,Paddle 与 PyTorch 的 `other` 参数所支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------- | +| other | y | 比较的元素,PyTorch 支持 Tensor 和 Python Number,Paddle 仅支持 Tensor,需要转写。 | + +### 转写示例 +#### other:比较的元素 +```python +# PyTorch 写法 +y = x.not_equal_(other=2) + +# Paddle 写法 +y = x.not_equal_(y=paddle.to_tensor(2)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numel.md new file mode 100644 index 00000000000..2e43571b21a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numel.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.numel + +### [torch.Tensor.numel](https://pytorch.org/docs/stable/generated/torch.numel.html?highlight=numel#torch.numel) + +```python +torch.Tensor.numel() +``` + +### [paddle.Tensor.size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fluid/layers/size_cn.html#cn-api-fluid-layers-size) + +```python +paddle.Tensor.size() +``` + +两者功能一致,均无参数,用于返回张量的单元数量,是一个 int 型的整数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numpy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numpy.md new file mode 100644 index 00000000000..eab34d1e6ec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.numpy.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ] torch.Tensor.numpy + +### [torch.Tensor.numpy](https://pytorch.org/docs/stable/generated/torch.Tensor.numpy.html?highlight=numpy#torch.Tensor.numpy) + +```python +torch.Tensor.numpy(force=False) +``` + +### [paddle.Tensor.numpy](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#numpy) + +```python +paddle.Tensor.numpy() +``` + +两者功能一致,用于将当前 Tensor 转化为 numpy.ndarray。 + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------------- | +| force | - | 若 force 为默认,则返回的 ndarray 和 tensor 将共享它们的存储空间。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.outer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.outer.md new file mode 100644 index 00000000000..e94b35f22ec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.outer.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.Tensor.outer + +### [torch.Tensor.outer](https://pytorch.org/docs/stable/generated/torch.Tensor.outer.html?highlight=outer#torch.Tensor.outer) + +```python +torch.Tensor.outer(vec2) +``` + +### [paddle.Tensor.outer]() + +```python +paddle.Tensor.outer(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------- | +| vec2 | y | 如果类型是多维 `Tensor`,其数据类型应该和 `x` 相同,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.permute.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.permute.md new file mode 100644 index 00000000000..2a2ce0fcf0c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.permute.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.Tensor.permute + +### [torch.Tensor.permute](https://pytorch.org/docs/stable/generated/torch.Tensor.permute.html) + +```python +torch.Tensor.permute(*dims) +``` + +### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#transpose-perm-name-none) + +```python +paddle.Tensor.transpose(perm, name=None) +``` + +PyTorch 的 `*dims` 相比于 paddle 的 `perm` 额外支持可变参数的用法,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *dims | perm | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple。对于可变参数的用法,需要转写。 | + +### 转写示例 +#### *dims: 可变参数用法 +```python +# pytorch +x = torch.randn(2, 3, 5) +y = x.permute(2, 0, 1) + +# paddle +x = paddle.randn([2, 3, 5]) +y = x.transpose([2, 0, 1]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pin_memory.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pin_memory.md new file mode 100644 index 00000000000..1d0f08d99e8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pin_memory.md @@ -0,0 +1,17 @@ +## [ 无参数 ] torch.Tensor.pin_memory + +### [torch.Tensor.pin_memory](https://pytorch.org/docs/stable/generated/torch.Tensor.pin_memory.html?highlight=pin_mem#torch.Tensor.pin_memory) + +```python +torch.Tensor.pin_memory() +``` + +### [paddle.Tensor.pin_memory](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#pin-memory-y-name-none) + +```python +paddle.Tensor.pin_memory() +``` + + + +两者功能一致,均无参数,用于将当前 Tensor 的拷贝到固定内存上,且返回的 Tensor 不保留在原计算图中。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pinverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pinverse.md new file mode 100644 index 00000000000..9d8adb06581 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pinverse.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.pinverse +### [torch.Tensor.pinverse](https://pytorch.org/docs/stable/generated/torch.Tensor.pinverse.html#torch.Tensor.pinverse) + +```python +torch.Tensor.pinverse() +``` + +### [paddle.Tensor.pinv]() + +```python +paddle.Tensor.pinv(rcond=1e-15, + hermitian=False, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| - | rcond | 奇异值(特征值)被截断的阈值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | hermitian | 是否为 hermitian 矩阵或者实对称矩阵,PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma.md new file mode 100644 index 00000000000..3bfea29213d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.polygamma + +### [torch.Tensor.polygamma](https://pytorch.org/docs/stable/generated/torch.Tensor.polygamma.html?highlight=tensor+polygamma#torch.Tensor.polygamma) + +```python +torch.Tensor.polygamma(n) +``` + +### [paddle.Tensor.polygamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/polygamma_cn.html#polygamma) + +```python +paddle.Tensor.polygamma(n) +``` + +两者功能一致,且参数一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|------------------| +| n | n | 表示返回第 n 阶的多伽马函数的值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma_.md new file mode 100644 index 00000000000..6231088a668 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.polygamma_.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.polygamma_ + +### [torch.Tensor.polygamma_](https://pytorch.org/docs/stable/generated/torch.Tensor.polygamma_.html) + +```python +torch.Tensor.polygamma_(n) +``` + +### [paddle.Tensor.polygamma_]() + +```python +paddle.Tensor.polygamma_(n) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| n | n | 指定需要求解 n 阶多伽马函数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow.md new file mode 100644 index 00000000000..60aea0daf26 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.Tensor.pow + +### [torch.Tensor.pow](https://pytorch.org/docs/stable/generated/torch.Tensor.pow.html?highlight=pow#torch.Tensor.pow) + +```python +torch.Tensor.pow(exponent) +``` + +### [paddle.Tensor.pow]() + +```python +paddle.Tensor.pow(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------------------------- | +| exponent | y | 一个 N 维 Tensor 或者标量 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow_.md new file mode 100644 index 00000000000..02af8eb91d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.pow_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.Tensor.pow_ + +### [torch.Tensor.pow_](https://pytorch.org/docs/stable/generated/torch.Tensor.pow_.html) + +```python +torch.Tensor.pow_(exponent) +``` + +### [paddle.Tensor.pow_]() + +```python +paddle.Tensor.pow_(y) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------------------------- | +| exponent | y | 一个标量 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.prod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.prod.md new file mode 100644 index 00000000000..728808f3837 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.prod.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ] torch.Tensor.prod + +### [torch.Tensor.prod](https://pytorch.org/docs/stable/generated/torch.prod.html#torch.prod) + +```python +torch.Tensor.prod(dim, keepdim=False, *, dtype=None) +``` + +### [paddle.Tensor.prod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/prod_cn.html) + +```python +paddle.Tensor.prod(axis=None, keepdim=False, dtype=None, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------- | +| dim | axis | 求乘积运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留输入的维度,仅参数名不一致。 | +| dtype | dtype | 输出 Tensor 的数据类型,支持 int32、int64、float32、float64。 | +| - | name | 一般无需设置,默认值为 None。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.qr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.qr.md new file mode 100644 index 00000000000..e6123737b48 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.qr.md @@ -0,0 +1,41 @@ +## [ 参数不一致 ] torch.Tensor.qr + +### [torch.Tensor.qr](https://pytorch.org/docs/stable/generated/torch.Tensor.qr.html?highlight=torch+tensor+qr#torch.Tensor.qr) + +```python +torch.Tensor.qr(some=True) +``` + +### [paddle.Tensor.qr](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/qr_cn.html#qr) + +```python +paddle.Tensor.qr(mode='reduced') +``` + +其中,PyTorch 的 `some` 和 PaddlePaddle 的 `mode` 参数所支持的数据类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|------------------------------------------------------------------------| +| some | mode | 表示 QR 分解的行为。PyTorch 支持布尔类型的输入,PaddlePaddle 支持字符串类型的输入。 两者使用方式不一致,需要转写。 | + + +### 转写示例 +### some:控制 QR 分解的行为 +```python +# 当进行完整的 QR 分解时 +# PyTorch 写法 +q, r = x.qr(some=False) + +# Paddle 写法 +q, r = x.qr(mode='complete') + + +#当进行减少的 QR 分解时 +# PyTorch 写法 +q, r = x.qr(some=True) + +# Paddle 写法 +q, r = x.qr(mode='reduced') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md new file mode 100644 index 00000000000..6757255ccf6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.quantile.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.Tensor.quantile + +### [torch.Tensor.quantile](https://pytorch.org/docs/stable/generated/torch.Tensor.quantile.html#torch.Tensor.quantile) + +```python +torch.Tensor.quantile(q, dim=None, keepdim=False, *, interpolation='linear') +``` + +### [paddle.Tensor.quantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#quantile-q-axis-none-keepdim-false-name-none) + +```python +paddle.Tensor.quantile(q, axis=None, keepdim=False, interpolation='linear', name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------ | +| q | q | 待计算的分位数。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。| +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。| +| interpolation | interpolation | 两个数据点的插补取值方法。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rad2deg.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rad2deg.md new file mode 100644 index 00000000000..99e7c0a45b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rad2deg.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.rad2deg + +### [torch.Tensor.rad2deg](https://pytorch.org/docs/stable/generated/torch.Tensor.rad2deg.html#torch-tensor-rad2deg) + +```python +torch.Tensor.rad2deg() +``` + +### [paddle.Tensor.rad2deg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#rad2deg-x-name-none) + +```python +paddle.Tensor.rad2deg() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ravel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ravel.md new file mode 100644 index 00000000000..d2567859c92 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.ravel.md @@ -0,0 +1,20 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.ravel +### [torch.Tensor.ravel](https://pytorch.org/docs/stable/generated/torch.Tensor.ravel.html#torch.Tensor.ravel) + +```python +torch.Tensor.ravel() +``` + +### [paddle.Tensor.flatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#flatten-start-axis-0-stop-axis-1-name-none) + +```python +paddle.Tensor.flatten(start_axis=0, stop_axis=- 1, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| - | start_axis | 表示 flatten 展开的起始维度, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | stop_axis | 表示 flatten 展开的结束维度, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.real.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.real.md new file mode 100644 index 00000000000..5bd56f30644 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.real.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.real + +### [torch.Tensor.real](https://pytorch.org/docs/stable/generated/torch.Tensor.real.html) + +```python +torch.Tensor.real +``` + +### [paddle.Tensor.real](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#real-name-none) + +```python +paddle.Tensor.real +``` + +两者功能一致,均无参数,用于返回 Tensor 的实部数值。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal.md new file mode 100644 index 00000000000..612cc721c7b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.reciprocal + +### [torch.Tensor.reciprocal](https://pytorch.org/docs/stable/generated/torch.Tensor.reciprocal.html?highlight=torch+tensor+reciprocal#torch.Tensor.reciprocal) + +```python +torch.Tensor.reciprocal() +``` + +### [paddle.Tensor.reciprocal]() + +```python +paddle.Tensor.reciprocal() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal_.md new file mode 100644 index 00000000000..06854009246 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reciprocal_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.reciprocal_ + +### [torch.Tensor.reciprocal_](https://pytorch.org/docs/stable/generated/torch.Tensor.reciprocal_.html?highlight=torch+tensor+reciprocal_#torch.Tensor.reciprocal_) + +```python +torch.Tensor.reciprocal_() +``` + +### [paddle.Tensor.reciprocal_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id11) + +```python +paddle.Tensor.reciprocal_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.register_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.register_hook.md new file mode 100644 index 00000000000..d695169c696 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.register_hook.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.register_hook +### [torch.Tensor.register_hook](https://pytorch.org/docs/stable/generated/torch.Tensor.register_hook.html#torch-tensor-register-hook) + +```python +torch.Tensor.register_hook(hook) +``` + +### [paddle.Tensor.register_hook](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#register-hook-hook) + +```python +paddle.Tensor.register_hook(hook) +``` + + +两者功能一致,且参数一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| hook | hook | 一个需要注册到 Tensor.grad 上的 hook 函数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder.md new file mode 100644 index 00000000000..f334ffc5fd7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.remainder +### [torch.Tensor.remainder](https://pytorch.org/docs/stable/generated/torch.Tensor.remainder.html?highlight=torch+tensor+remainder#torch.Tensor.remainder) + +```python +torch.Tensor.remainder(divisor) +``` + +### [paddle.Tensor.remainder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#remainder-y-name-none) + +```python +paddle.Tensor.remainder(y, name=None) +``` + +其中 Paddle 与 PyTorch 运算除数参数所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| divisor | y | 除数,PyTorch 可为 Tensor or Scalar,Paddle 仅可为 Tensor, 需要转写。 | + +### 转写示例 +#### divisor:除数为 Scalar +```python +# PyTorch 写法 +x.remainder(1) + +# Paddle 写法 +x.remainder(y=paddle.to_tensor(1)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder_.md new file mode 100644 index 00000000000..b7ee69c3fce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.remainder_.md @@ -0,0 +1,30 @@ +## [ 参数不一致 ]torch.Tensor.remainder_ +### [torch.Tensor.remainder_](https://pytorch.org/docs/stable/generated/torch.Tensor.remainder_.html?highlight=torch+tensor+remainder_#torch.Tensor.remainder_) + +```python +torch.Tensor.remainder_(divisor) +``` + +### [paddle.Tensor.remainder_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id15) + +```python +paddle.Tensor.remainder_(, name=None) +``` + +其中 Paddle 与 PyTorch 运算除数参数所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| divisor | y | 除数,PyTorch 可为 Tensor or Scalar,Paddle 仅可为 Tensor,需要转写。 | + +### 转写示例 +#### divisor:除数为 Scalar +```python +# PyTorch 写法 +x.remainder_(1) + +# Paddle 写法 +x.remainder_(y=paddle.to_tensor(1)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm.md new file mode 100644 index 00000000000..10bd5a545c6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.renorm + +### [torch.Tensor.renorm](https://pytorch.org/docs/stable/generated/torch.Tensor.renorm.html#torch-tensor-renorm) + +```python +torch.Tensor.renorm(p, dim, maxnorm) +``` + +### [paddle.Tensor.renorm]() + +```python +paddle.Tensor.renorm(p, axis, max_norm) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| p | p | 表示 p-范数计算的 p 值。| +| dim | axis | 表示切分的维度,仅参数名不一致。 | +| maxnorm | max_norm | 表示子张量的 p-范数最大值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm_.md new file mode 100644 index 00000000000..00382356b2c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.renorm_.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.renorm_ + +### [torch.Tensor.renorm_](https://pytorch.org/docs/stable/generated/torch.Tensor.renorm_.html#torch-tensor-renorm_) + +```python +torch.Tensor.renorm_(p, dim, maxnorm) +``` + +### [paddle.Tensor.renorm_]() + +```python +paddle.Tensor.renorm_(p, axis, max_norm) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| p | p | 表示 p-范数计算的 p 值。| +| dim | axis | 表示切分的维度,仅参数名不一致。 | +| maxnorm | max_norm | 表示子张量的 p-范数最大值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat.md new file mode 100644 index 00000000000..d083aac695b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.Tensor.repeat + +### [torch.Tensor.repeat](https://pytorch.org/docs/stable/generated/torch.Tensor.repeat.html) + +```python +torch.Tensor.repeat(*sizes) +``` + +### [paddle.Tensor.tile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tile-repeat-times-name-none) + +```python +paddle.Tensor.tile(repeat_times, name=None) +``` + +PyTorch 的 `*sizes` 相比于 Paddle 的 `repeat_times` 额外支持可变参数的用法,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *sizes | repeat_times | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple。对于可变参数的用法,需要转写。 | + +### 转写示例 +#### *sizes: 各个维度重复的次数,可变参数用法 +```python +# pytorch +x = torch.randn(2, 3, 5) +y = x.repeat(4, 2, 1) + +# paddle +x = paddle.randn([2, 3, 5]) +y = x.tile((4, 2, 1)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat_interleave.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat_interleave.md new file mode 100644 index 00000000000..fad3a795ff7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.repeat_interleave.md @@ -0,0 +1,23 @@ +## [ torch 参数更多]torch.Tensor.repeat_interleave + +### [torch.Tensor.repeat_interleave](https://pytorch.org/docs/stable/generated/torch.Tensor.repeat_interleave.html#torch.Tensor.repeat_interleave) + +```python +torch.Tensor.repeat_interleave(repeats, dim=None, *, output_size=None) +``` + +### [paddle.Tensor.repeat_interleave](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#repeat-interleave-repeats-axis-none-name-none) + +```python +paddle.Tensor.repeat_interleave(repeats, axis=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| repeats | repeats | 表示指定复制次数的 1-D Tensor 或指定的复制次数。 | +| dim | axis | 表示复制取值的维度,仅参数名不一致。 | +| output_size | - | 表示给定维度的总输出尺寸,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad_.md new file mode 100644 index 00000000000..f2990bc4584 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.requires_grad_.md @@ -0,0 +1,36 @@ +## [组合替代实现]torch.Tensor.requires_grad_ + +### [torch.Tensor.requires_grad_](https://pytorch.org/docs/stable/generated/torch.Tensor.requires_grad_.html?highlight=requires_grad_#torch.Tensor.requires_grad_) + +```python +torch.Tensor.requires_grad_(requires_grad=True) +``` + +### [paddle.Tensor.stop_gradient](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#stop-gradient) + +```python +paddle.Tensor.stop_gradient = False +``` + +两者功能一致,torch 为 funtion 调用方式,paddle 为 attribution 赋值方式,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| requires_grad | - | 是否计算梯度,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### requires_grad:是否计算梯度 +```python +# 当 requires_grad 为‘True’时,torch 写法 +x.requires_grad_(requires_grad=True) + +# paddle 写法 +x.stop_gradient = False + +# 当 requires_grad 为‘False’时,torch 写法 +x.requires_grad_(requires_grad=False) + +# paddle 写法 +x.stop_gradient = True +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape.md new file mode 100644 index 00000000000..5a31cfb8a86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.Tensor.reshape + +### [torch.Tensor.reshape](https://pytorch.org/docs/stable/generated/torch.Tensor.reshape.html) + +```python +torch.Tensor.reshape(*shape) +``` + +### [paddle.Tensor.reshape](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#reshape-shape-name-none) + +```python +paddle.Tensor.reshape(shape, name=None) +``` + +PyTorch 的 `*shape` 相比于 Paddle 的 `shape` 额外支持可变参数的用法,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *shape | shape | torch 支持可变参数或 list/tuple,paddle 仅支持 list/tuple。对于可变参数的用法,需要转写。 | + +### 转写示例 +#### *shape: 新数组的维度序列,可变参数用法 +```python +# pytorch +x = torch.randn(2, 3, 5) +y = x.reshape(6, 5) + +# paddle +x = paddle.randn([2, 3, 5]) +y = x.reshape((6, 5)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape_as.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape_as.md new file mode 100644 index 00000000000..ac8243d4c66 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.reshape_as.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.reshape_as + +### [torch.Tensor.reshape_as](https://pytorch.org/docs/stable/generated/torch.Tensor.reshape_as.html#torch.Tensor.reshape_as) + +```python +torch.Tensor.reshape_as(other) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.reshape_as(b) + +# Paddle 写法 +y = paddle.reshape(a, b.shape) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.resize_as_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.resize_as_.md new file mode 100644 index 00000000000..3f4e49150b8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.resize_as_.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.Tensor.resize_as_ + +### [torch.Tensor.resize_as_](https://pytorch.org/docs/stable/generated/torch.Tensor.resize_as_.html?highlight=resize_as#torch.Tensor.resize_as_) + +```python +# PyTorch 文档有误,测试第一个参数为 the_template +torch.Tensor.resize_as_(the_template, memory_format=torch.contiguous_format) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.resize_as_(b) + +# Paddle 写法 +y = a.reshape_(b.shape) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.retain_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.retain_grad.md new file mode 100644 index 00000000000..3423c7c2712 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.retain_grad.md @@ -0,0 +1,15 @@ +## [无参数]torch.Tensor.retain_grad + +### [torch.Tensor.retain_grad](https://pytorch.org/docs/stable/generated/torch.Tensor.retain_grad.html) + +```python +torch.Tensor.retain_grad() +``` + +### [paddle.Tensor.retain_grads](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Overview_cn.html#paddle) + +```python +paddle.Tensor.retain_grads() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.roll.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.roll.md new file mode 100644 index 00000000000..10cdabeb9e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.roll.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.Tensor.roll +### [torch.Tensor.roll](https://pytorch.org/docs/stable/generated/torch.Tensor.roll.html?highlight=torch+tensor+roll#torch.Tensor.roll) + +```python +torch.Tensor.roll(shifts, dims) +``` + +### [paddle.Tensor.roll](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/roll_cn.html#roll) + +```python +paddle.Tensor.roll(shifts, axis=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| shifts | shifts | 表示偏移量。 | +| dims | axis | 表示滚动的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rot90.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rot90.md new file mode 100644 index 00000000000..844f3de32b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rot90.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.rot90 + +### [torch.Tensor.rot90](https://pytorch.org/docs/stable/generated/torch.Tensor.rot90.html?highlight=torch+tensor+rot90#torch.Tensor.rot90) + +```python +torch.Tensor.rot90(k, dims) +``` + +### [paddle.Tensor.rot90]() + +```python +paddle.Tensor.rot90(k=1, axes=[0, 1]) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| k | k | 旋转方向和次数。 | +| dims | axes | 指定旋转的平面,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md new file mode 100644 index 00000000000..7ca3ed10a7c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round.md @@ -0,0 +1,33 @@ +## [torch 参数更多]torch.Tensor.round + +### [torch.Tensor.round](https://pytorch.org/docs/stable/generated/torch.Tensor.round.html#torch.Tensor.round) + +```python +torch.Tensor.round(decimals=0) +``` + +### [paddle.Tensor.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#round-name-none) + +```python +paddle.Tensor.round(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------- | ------- | +| decimals | - | 舍入小数位数 | + +### 转写示例 +#### decimals:要舍入到的小数位数 +```python +# PyTorch 写法 +torch.tensor([3.345, 5.774]).round(decimals=2) + +# Paddle 写法 +(paddle.to_tensor([3.345, 5.774]) * 1e2).round() / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md new file mode 100644 index 00000000000..117a65edb6b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.round_.md @@ -0,0 +1,33 @@ +## [torch 参数更多]torch.Tensor.round_ + +### [torch.Tensor.round_](https://pytorch.org/docs/stable/generated/torch.Tensor.round_.html#torch.Tensor.round_) + +```python +torch.Tensor.round_(decimals=0) +``` + +### [paddle.Tensor.round_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#round-name-none) + +```python +paddle.Tensor.round_(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------- | ------- | +| decimals | - | 舍入小数位数 | + +### 转写示例 +#### decimals:要舍入到的小数位数 +```python +# PyTorch 写法 +torch.tensor([3.345, 5.774]).round_(decimals=2) + +# Paddle 写法 +(paddle.to_tensor([3.345, 5.774]) * 1e2).round_() / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt.md new file mode 100644 index 00000000000..a40ca35c389 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.rsqrt + +### [ torch.Tensor.rsqrt](https://pytorch.org/docs/stable/generated/torch.Tensor.rsqrt) + +```python +torch.Tensor.rsqrt() +``` + +### [paddle.Tensor.rsqrt](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#rsqrt-name-none) + +```python +paddle.Tensor.rsqrt() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt_.md new file mode 100644 index 00000000000..7e6c5ca8e31 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.rsqrt_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.rsqrt_ + +### [torch.Tensor.rsqrt_](https://pytorch.org/docs/stable/generated/torch.Tensor.rsqrt_) + +```python +torch.Tensor.rsqrt_() +``` + +### [paddle.Tensor.rsqrt_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id15) + +```python +paddle.Tensor.rsqrt_() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md new file mode 100644 index 00000000000..f6d58e7065e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter.md @@ -0,0 +1,26 @@ +## [仅 paddle 参数更多]torch.Tensor.scatter + +### [torch.Tensor.scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter.html#torch.Tensor.scatter) + +```python +torch.Tensor.scatter(dim, index, src, reduce=None) +``` + +### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) + +```python +paddle.Tensor.put_along_axis(indices, values, axis, reduce="assign", include_self=True, broadcast=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| reduce | reduce | 归约操作类型 。 | +| - | include_self | 表示插入 values 时是否包含 arr 中的元素,PyTorch 无此参数。| +| - | broadcast | 表示是否需要广播 indices 矩阵,PyTorch 无此参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md new file mode 100644 index 00000000000..af51c6d3315 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.Tensor.scatter_ + +### [torch.Tensor.scatter_](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_.html?highlight=scatter_#torch.Tensor.scatter_) + +```python +torch.Tensor.scatter_(dim, index, src) +``` + +### [paddle.Tensor.put_along_axis_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/put_along_axis__cn.html#put-along-axis) + +```python +paddle.Tensor.put_along_axis_(index, value, axis, reduce="assign", include_self=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| reduce | reduce | 归约操作类型,PyTorch 默认为 None, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md new file mode 100644 index 00000000000..ad528d0b210 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add.md @@ -0,0 +1,30 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.scatter_add + +### [torch.Tensor.scatter_add](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_add.html#torch.Tensor.scatter_add) + +```python +torch.Tensor.scatter_add(dim, index, src) +``` + +### [paddle.Tensor.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/put_along_axis_cn.html) + +```python +paddle.Tensor.put_along_axis(indices, + values, + axis, + reduce='assign', + include_self=True, + broadcast=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| - | reduce | 表示对输出 Tensor 的计算方式, PyTorch 无此参数, Paddle 应设置为 'add' 。 | +| - | include_self | 表示插入 values 时是否包含 arr 中的元素,PyTorch 无此参数,Paddle 应设置为 'True' 。 | +| - | broadcast | 表示是否需要广播 indices 矩阵,PyTorch 无此参数,Paddle 应设置为 'False' 结果才与 pytorch 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add_.md new file mode 100644 index 00000000000..410c1bf217f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.scatter_add_.md @@ -0,0 +1,30 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.scatter_add_ + +### [torch.Tensor.scatter_add_](https://pytorch.org/docs/stable/generated/torch.Tensor.scatter_add_.html#torch.Tensor.scatter_add_) + +```python +torch.Tensor.scatter_add_(dim, + index, + src) +``` + +### [paddle.Tensor.put_along_axis_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/put_along_axis__cn.html) + +```python +paddle.Tensor.put_along_axis_(indices, + values, + axis, + reduce='assign', + include_self=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| - | reduce | 表示对输出 Tensor 的计算方式, PyTorch 无此参数, Paddle 应设置为 'add' 。 | +| - | include_self | 表示插入 values 时是否包含 arr 中的元素,PyTorch 无此参数,Paddle 应设置为 'True' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.select.md new file mode 100644 index 00000000000..eeefec672b6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.select.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.select + +### [torch.Tensor.select](https://pytorch.org/docs/stable/generated/torch.Tensor.select.html?highlight=select#torch.Tensor.select) + +```python +torch.Tensor.select(dim, index) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.select(dim=dim, index=index) + +# Paddle 写法 +y = paddle.index_select(a, index=paddle.to_tensor([index]), axis=dim).squeeze(dim) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sgn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sgn.md new file mode 100644 index 00000000000..aef70be6cd7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sgn.md @@ -0,0 +1,12 @@ +## [ 无参数 ]torch.Tensor.sgn +### [torch.Tensor.sgn](https://pytorch.org/docs/stable/generated/torch.Tensor.sgn.html#torch.Tensor.sgn) + +```python +torch.Tensor.sgn() +``` + +### [paddle.Tensor.sgn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sgn-name-none) + +```python +paddle.Tensor.sgn() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.shape.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.shape.md new file mode 100644 index 00000000000..e0567226ed7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.shape.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.shape + +### [torch.Tensor.shape](https://pytorch.org/docs/stable/generated/torch.Tensor.shape.html) + +```python +torch.Tensor.shape +``` + +### [paddle.Tensor.shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#shape) + +```python +paddle.Tensor.shape +``` + +两者功能一致,均无参数,都用来查看一个 Tensor 的 shape,shape 是 Tensor 的一个重要的概念,其描述了 tensor 在每个维度上的元素数量。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md new file mode 100644 index 00000000000..fdf85bf0526 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.short.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.Tensor.short + +### [torch.Tensor.short](https://pytorch.org/docs/stable/generated/torch.Tensor.short.html#torch.Tensor.short) + +```python +torch.Tensor.short(memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#put-along-axis-arr-index-value-axis-reduce-assign) + +```python +paddle.Tensor.astype('int16') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| memory_format | - |表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid.md new file mode 100644 index 00000000000..a2df16cc2c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sigmoid + +### [torch.Tensor.sigmoid](https://pytorch.org/docs/stable/generated/torch.Tensor.sigmoid) + +```python +torch.Tensor.sigmoid() +``` + +### [paddle.Tensor.sigmoid]() + +```python +paddle.Tensor.sigmoid() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid_.md new file mode 100644 index 00000000000..5e46a05aa6c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sigmoid_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sigmoid_ + +### [torch.Tensor.sigmoid_](https://pytorch.org/docs/stable/generated/torch.Tensor.sigmoid_) + +```python +torch.Tensor.sigmoid_() +``` + +### [paddle.Tensor.sigmoid_]() + +```python +paddle.Tensor.sigmoid_() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sign.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sign.md new file mode 100644 index 00000000000..dfda02114eb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sign.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sign + +### [torch.Tensor.sign](https://pytorch.org/docs/stable/generated/torch.Tensor.sign) + +```python +torch.Tensor.sign() +``` + +### [paddle.Tensor.sign](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sign-name-none) + +```python +paddle.Tensor.sign() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.signbit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.signbit.md new file mode 100644 index 00000000000..1dfe7df4ce3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.signbit.md @@ -0,0 +1,15 @@ +## [无参数]torch.Tensor.signbit + +### [torch.Tensor.signbit](https://pytorch.org/docs/stable/generated/torch.Tensor.signbit.html#torch-signbit) + +```python +torch.Tensor.signbit() +``` + +### [paddle.Tensor.signbit](https://github.com/PaddlePaddle/Paddle/blob/9ce3a54f456011c664c70fbcd318f2e1af0a7d81/python/paddle/tensor/math.py#L7175) + +```python +paddle.Tensor.signbit() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin.md new file mode 100644 index 00000000000..085dac59dc9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sin + +### [torch.Tensor.sin](https://pytorch.org/docs/stable/generated/torch.Tensor.sin) + +```python +torch.Tensor.sin() +``` + +### [paddle.Tensor.sin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sin-name-none) + +```python +paddle.Tensor.sin() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin_.md new file mode 100644 index 00000000000..0cdd5ebf829 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sin_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.sin_ + +### [torch.Tensor.sin_](https://pytorch.org/docs/stable/generated/torch.Tensor.sin_.html) + +```python +torch.Tensor.sin_() +``` + +### [paddle.Tensor.sin_]() + +```python +paddle.Tensor.sin_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinc.md new file mode 100644 index 00000000000..0ddf66a2ef2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinc.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.Tensor.sinc + +### [torch.Tensor.sinc](https://pytorch.org/docs/stable/generated/torch.Tensor.sinc.html#torch.Tensor.sinc) + +```python +torch.Tensor.sinc() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.sinc() + +# Paddle 写法 +import numpy +y = paddle.where(a==0, x=paddle.to_tensor([1], dtype=a.dtype), y=paddle.sin(numpy.pi*a)/(numpy.pi*a)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh.md new file mode 100644 index 00000000000..e95b85647ff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sinh + +### [torch.Tensor.sinh](https://pytorch.org/docs/stable/generated/torch.Tensor.sinh.html?highlight=torch+tensor+sinh#torch.Tensor.sinh) + +```python +torch.Tensor.sinh() +``` + +### [paddle.Tensor.sinh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sinh-name-none) + +```python +paddle.Tensor.sinh() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh_.md new file mode 100644 index 00000000000..403d1349f05 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sinh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.sinh_ + +### [torch.Tensor.sinh_](https://pytorch.org/docs/stable/generated/torch.Tensor.sinh_.html) + +```python +torch.Tensor.sinh_() +``` + +### [paddle.Tensor.sinh_]() + +```python +paddle.Tensor.sinh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md new file mode 100644 index 00000000000..b0171744136 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.size.md @@ -0,0 +1,31 @@ +## [torch 参数更多]torch.Tensor.size + +### [torch.Tensor.size](https://pytorch.org/docs/stable/generated/torch.Tensor.size.html#torch.Tensor.size) + +```python +torch.Tensor.size(dim=None) +``` + +### [paddle.Tensor.shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#shape) + +```python +paddle.Tensor.shape +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| dim | - | 表示获取大小的轴,Paddle 无此参数,需要转写。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.tensor([-1, -2, 3]).size(0) + +# Paddle 写法 +paddle.to_tensor([-0.4, -0.2, 0.1, 0.3]).shape[0] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slice_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slice_scatter.md new file mode 100644 index 00000000000..e61cb11e1ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slice_scatter.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.Tensor.slice_scatter + +### [torch.Tensor.slice_scatter](https://pytorch.org/docs/stable/generated/torch.Tensor.slice_scatter.html#torch-tensor-slice-scatter) + +```python +torch.Tensor.slice_scatter(src, dim=0, start=None, end=None, step=1) +``` + +### [paddle.Tensor.slice_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#slice_scatter-value-axes-starts-ends-strides-name-none) + +```python +paddle.Tensor.slice_scatter(value, axes, starts, ends, strides, name=None) +``` + +两者功能一致,参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| src | value | 嵌入的值,仅参数名不一致。 | +| dim | axes | 嵌入的维度,PyTorch 为 int 类型,Paddle 为 list of int。 | +| start | starts | 嵌入起始索引,PyTorch 为 int 类型,Paddle 为 list of int。 | +| end | ends | 嵌入截至索引,PyTorch 为 int 类型,Paddle 为 list of int。 | +| step | strides | 嵌入步长,PyTorch 为 int 类型,Paddle 为 list of int。 | + +### 转写示例 + +```python +# PyTorch 写法 +x.slice_scatter(src, dim=0, start=1, end=5, step=2) + +# Paddle 写法 +x.slice_scatter(value, axes=[0], starts=[1], ends=[5], strides=[2]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slogdet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slogdet.md new file mode 100644 index 00000000000..1e9dc6d77b4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.slogdet.md @@ -0,0 +1,36 @@ +## [ 返回参数类型不一致 ]torch.Tensor.slogdet + +### [torch.Tensor.slogdet](https://pytorch.org/docs/stable/generated/torch.Tensor.slogdet.html) + +```python +torch.Tensor.slogdet() +``` + +### [paddle.linalg.slogdet](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/slogdet_cn.html#slogdet) + +```python +paddle.linalg.slogdet(x) +``` + +两者功能一致,返回参数的个数不同,PyTorch 返回两个 Tesnor,Paddle 返回一个 Tensor,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| self | x | 表示输入的 Tensor ,仅参数名不一致。 | +| 返回值 | 返回值 | PyTorch 返回两个 Tesnor,Paddle 返回一个 Tensor,需要转写。 | + + + +### 转写示例 + +#### 返回值 +```python +# PyTorch 写法 +x.slogdet() + +# Paddle 写法 +y = paddle.linalg.slogdet(x) +(y[0], y[1]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.softmax.md new file mode 100644 index 00000000000..65a6dc09d37 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.softmax.md @@ -0,0 +1,28 @@ +## [ 仅 paddle 参数更多 ]torch.Tensor.softmax +### [torch.Tensor.softmax](https://pytorch.org/docs/stable/generated/torch.Tensor.softmax.html?highlight=softmax#torch.Tensor.softmax) + +```python +torch.Tensor.softmax(dim) +``` + +### [paddle.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softmax_cn.html#softmax) + +```python +paddle.nn.functional.softmax(x, axis=-1, dtype=None, name=None) +``` + +功能一致,torch 是类成员方式,paddle 是 function 调用,具体差异如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 计算 softmax 的轴,仅参数名不一致。 | + +### 转写示例 +#### dim: 计算 softmax 的轴 +```python +# torch 写法 +x.softmax(dim=1) + +# paddle 写法 +paddle.nn.functional.softmax(x, axis=1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sort.md new file mode 100644 index 00000000000..bd8fd70b3a9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sort.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.sort + +### [torch.Tensor.sort](https://pytorch.org/docs/stable/generated/torch.Tensor.sort.html#torch-tensor-sort) + +```python +torch.Tensor.sort(dim=- 1, descending=False) +``` + +### [paddle.sort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sort_cn.html#sort) + +```python +paddle.sort(x, axis=- 1, descending=False) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴。默认值为-1, 仅参数名不一致。 | +| descending |descending | 指定算法排序的方向, 参数完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.split.md new file mode 100644 index 00000000000..bd0fb33c85f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.split.md @@ -0,0 +1,33 @@ +## [ 参数不一致 ]torch.Tensor.split + +### [torch.Tensor.split](https://pytorch.org/docs/stable/generated/torch.Tensor.split.html) + +```python +torch.Tensor.split(split_size_or_sections, dim=0) +``` + +### [paddle.Tensor.split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#split-num-or-sections-axis-0-name-none) + +```python +paddle.Tensor.split(num_or_sections, axis=0, name=None) +``` + +PyTorch 的 `split_size_or_sections` 与 Paddle 的 `num_or_sections` 用法不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | +| split_size_or_sections | num_or_sections | torch:int 时表示块的大小, list 时表示块的大小; paddle: int 时表示块的个数, list 时表示块的大小。因此对于 int 时,两者用法不同,需要转写。| + +### 转写示例 +#### split_size_or_sections: 为 int 时 torch 表示块的大小,paddle 表示块的个数 +```python +# pytorch +x = torch.randn(8, 2) +y = x.split(4) + +# paddle +x = paddle.randn([8, 2]) +y = x.split(2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt.md new file mode 100644 index 00000000000..c2edf8b7e01 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sqrt + +### [torch.Tensor.sqrt](https://pytorch.org/docs/stable/generated/torch.sqrt.html) + +```python +torch.Tensor.sqrt() +``` + +### [paddle.Tensor.sqrt](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sqrt-name-none) + +```python +paddle.Tensor.sqrt() +``` + +两者功能一致,无参数. diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt_.md new file mode 100644 index 00000000000..088c3891166 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sqrt_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.sqrt_ + +### [torch.Tensor.sqrt_](https://pytorch.org/docs/stable/generated/torch.Tensor.sqrt_.html?highlight=torch+tensor+sqrt_#torch.Tensor.sqrt_) + +```python +torch.Tensor.sqrt_() +``` + +### [paddle.Tensor.sqrt_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id18) + +```python +paddle.Tensor.sqrt_() +``` + +两者功能一致,无参数. diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square.md new file mode 100644 index 00000000000..dcc1cda1753 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square.md @@ -0,0 +1,14 @@ +## [ 无参数 ]torch.Tensor.square + +### [torch.Tensor.square](https://pytorch.org/docs/stable/generated/torch.Tensor.square.html#torch-tensor-square) + +```python +torch.Tensor.square() +``` + +### [paddle.Tensor.square](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#square-name-none) + +```python +paddle.Tensor.square() +``` +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square_.md new file mode 100644 index 00000000000..9ed562b75b8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.square_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.square_ + +### [torch.Tensor.square_](https://pytorch.org/docs/stable/generated/torch.Tensor.square_.html) + +```python +torch.Tensor.square_() +``` + +### [paddle.square_]() + +```python +paddle.square_(x) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze.md new file mode 100644 index 00000000000..59d4ba597da --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.squeeze + +### [torch.Tensor.squeeze](https://pytorch.org/docs/stable/generated/torch.Tensor.squeeze.html#torch.Tensor.squeeze) + +```python +torch.Tensor.squeeze(dim=None) +``` + +### [paddle.Tensor.squeeze](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#squeeze-axis-none-name-none) + +```python +paddle.Tensor.squeeze(axis=None) +``` +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 输入一个或一列整数,代表要压缩的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze_.md new file mode 100644 index 00000000000..e5d11ed48be --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.squeeze_.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.Tensor.squeeze_ + +### [torch.Tensor.squeeze_](https://pytorch.org/docs/stable/generated/torch.Tensor.squeeze_.html#torch-tensor-squeeze) + +```python +torch.Tensor.squeeze_(dim=None) +``` + +### [paddle.Tensor.squeeze_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id19) + +```python +paddle.Tensor.squeeze_(axis=None) +``` +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 输入一个或一列整数,代表要压缩的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.std.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.std.md new file mode 100644 index 00000000000..254e5b6003f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.std.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.std + +### [torch.Tensor.std](https://pytorch.org/docs/stable/generated/torch.Tensor.std.html?highlight=torch+tensor+std#torch.Tensor.std) + +```python +torch.Tensor.std(dim=None, *, correction=1, keepdim=False) +``` + +### [paddle.Tensor.std](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#std-axis-none-unbiased-true-keepdim-false-name-none) + +```python +paddle.Tensor.std(axis=None, unbiased=True, keepdim=False, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------- | +| dim | axis | 指定对 Tensor 进行计算的轴,仅参数名不一致。 | +| correction | unbiased | 是否使用无偏估计来计算标准差。PyTorch 支持 int 类型,Paddle 支持 bool/int 类型。仅参数名不一致。| +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md new file mode 100644 index 00000000000..636f6d81eeb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.stft.md @@ -0,0 +1,39 @@ +## [torch 参数更多]torch.Tensor.stft + +### [torch.Tensor.stft](https://pytorch.org/docs/stable/generated/torch.Tensor.stft.html#torch.Tensor.stft) + +```python +torch.Tensor.stft(n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=None, return_complex=None) +``` + +### [paddle.signal.stft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/signal/stft_cn.html) + +```python +paddle.signal.stft(x, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------- | +| n_fft | n_fft | 离散傅里叶变换的样本点个数。 | +| hop_length | hop_length | 对输入分帧时,相邻两帧偏移的样本点个数。 | +| win_length | win_length | 信号窗的长度。 | +| window | window | 维度为 1D 长度为 win_length 的 Tensor。 | +| center | center | 选择是否将输入信号进行补长。 | +| pad_mode | pad_mode | 当 center 为 True 时,确定 padding 的模式。 | +| normalized | normalized | 是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | +| onesided | onesided | 当输入为实信号时,选择是否只返回傅里叶变换结果的一半的频点值。 | +| return_complex | - | 表示当输入为复数时,是否以复数形式返回,还是将实部与虚部分开以实数形式返回。Paddle 目前只支持返回复数,分开返回实部与虚部的情况,需要使用 as_real 进行转写。 | + +### 转写示例 +#### return_complex:是否返回复数 +```python +# PyTorch 写法 +y = torch.rand(512,512).stft(n_fft=512, return_complex=False) + +# Paddle 写法 +y = paddle.as_real(paddle.signal.stft(paddle.rand((512,512)), n_fft=512)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub.md new file mode 100644 index 00000000000..7598c5db34b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.Tensor.sub +### [torch.Tensor.sub](https://pytorch.org/docs/stable/generated/torch.Tensor.sub.html#torch.Tensor.sub) + +```python +torch.Tensor.sub(other, *, alpha=1) +``` + +### [paddle.Tensor.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/subtract_cn.html#subtract) + +```python +paddle.Tensor.subtract(y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数,需要转写。Paddle 应设置 y = alpha * other。 | + + +### 转写示例 +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +x.sub(y, alpha=2) + +# Paddle 写法 +x.subtract(2 * y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub_.md new file mode 100644 index 00000000000..3b2b5996e1a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sub_.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.Tensor.sub_ +### [torch.Tensor.sub_](https://pytorch.org/docs/stable/generated/torch.Tensor.sub_.html) + +```python +torch.Tensor.sub_(other, *, alpha=1) +``` + +### [paddle.Tensor.subtract_]() + +```python +paddle.Tensor.subtract_(y) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数,需要转写。Paddle 应设置 y = alpha * other。 | + + +### 转写示例 +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +x.sub_(y, alpha=2) + +# Paddle 写法 +x.subtract_(2 * y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract.md new file mode 100644 index 00000000000..0d169bafdc3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.Tensor.subtract +### [torch.Tensor.subtract](https://pytorch.org/docs/stable/generated/torch.Tensor.subtract.html#torch.Tensor.subtract) + +```python +torch.Tensor.subtract(other, *, alpha=1) +``` + +### [paddle.Tensor.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/subtract_cn.html#subtract) + +```python +paddle.Tensor.subtract(y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数,需要转写。Paddle 应设置 y = alpha * other。 | + + +### 转写示例 +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +x.subtract(y, alpha=2) + +# Paddle 写法 +x.subtract(2 * y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract_.md new file mode 100644 index 00000000000..b0d7c19fd44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.subtract_.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.Tensor.subtract_ + +### [torch.Tensor.subtract_](https://pytorch.org/docs/stable/generated/torch.Tensor.subtract_.html#torch.Tensor.subtract_) + +```python +torch.Tensor.subtract_(other, *, alpha=1) +``` + +### [paddle.Tensor.subtract_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id20) + +```python +paddle.Tensor.subtract_(y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数,需要转写。Paddle 应设置 y = alpha * other。 | + +### 转写示例 + +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +x.subtract_(y, alpha=2) + +# Paddle 写法 +x.subtract_(2 * y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sum.md new file mode 100644 index 00000000000..f8d00535b0c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.sum.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.Tensor.sum + +### [torch.Tensor.sum](https://pytorch.org/docs/stable/generated/torch.Tensor.sum.html) + +```python +torch.Tensor.sum(dim=None, keepdim=False, dtype=None) +``` + +### [paddle.Tensor.sum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#sum-axis-none-dtype-none-keepdim-false-name-none) +```python +paddle.Tensor.sum(axis=None, dtype=None, keepdim=False, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------| +| dim | axis | 求和运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度 。 | +| dtype | dtype | 是输出变量的数据类型 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.svd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.svd.md new file mode 100644 index 00000000000..be4e2dfb440 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.svd.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.Tensor.svd + +### [torch.Tensor.svd](https://pytorch.org/docs/stable/generated/torch.Tensor.svd.html#torch.Tensor.svd) + +```python +torch.Tensor.svd(some=True, compute_uv=True) +``` + +### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/svd_cn.html#svd) +```python +paddle.linalg.svd(x, full_matrics=False, name=None) +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| some | full_matrics | 是否计算完整的 U 和 V 矩阵,两者参数功能相反,需要转写。 | +| compute_uv | - | 是否返回零填充的 U 和 V 矩阵, 默认为 `True`, Paddle 无此参数。暂无转写方式。 | + + +### 转写示例 +#### some 是否计算完整的 U 和 V 矩阵 +```python +# PyTorch 写法 +y = a.svd(some=False) + +# Paddle 写法 +y = paddle.linalg.svd(a, full_matrices=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapaxes.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapaxes.md new file mode 100644 index 00000000000..c469eb5ef6d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapaxes.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ] torch.Tensor.swapaxes + +### [torch.Tensor.swapaxes](https://pytorch.org/docs/stable/generated/torch.Tensor.swapaxes.html#torch.Tensor.swapaxes) + +```python +torch.Tensor.swapaxes(axis0, axis1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +其中 PyTorch 的 `axis0、axis1` 与 Paddle 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| _ | x | 输入 Tensor。 | +| axis0 | - | PyTorch 转置的第一个维度,Paddle 无此参数,需要转写。 | +| axis1 | - | PyTorch 转置的第二个维度,Paddle 无此参数,需要转写。 | +| - | perm | PyTorch 无此参数。 Paddle 可通过 perm 参数,等价的实现 torch 的 axis0、axis1 的功能。| + + +### 转写示例 + +#### axis0、axis1 参数: 转置的维度设置 +``` python +# PyTorch 写法: +x.swapaxes(axis0=0, axis1=1) + +# Paddle 写法: +paddle.transpose(x, perm=[1, 0, 2]) + +# 注:x 为 3D Tensor +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapdims.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapdims.md new file mode 100644 index 00000000000..3d52eeb473a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.swapdims.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ] torch.Tensor.swapdims + +### [torch.Tensor.swapdims](https://pytorch.org/docs/stable/generated/torch.Tensor.swapdims.html#torch.Tensor.swapdims) + +```python +torch.Tensor.swapdims(dim0, dim1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +其中 PyTorch 的 `dim0、dim1` 与 Paddle 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| _ | x | 输入 Tensor。 | +| dim0 | - | PyTorch 转置的第一个维度,Paddle 无此参数,需要转写。 | +| dim1 | - | PyTorch 转置的第二个维度,Paddle 无此参数,需要转写。 | +| - | perm | Paddle 无此参数。 Paddle 可通过 perm 参数,等价的实现 torch 的 dim0、dim1 的功能。| + + +### 转写示例 + +#### dim0、dim1 参数: 转置的维度设置 +``` python +# PyTorch 写法: +x.swapaxes(dim0=0, dim1=1) + +# Paddle 写法: +paddle.transpose(x, perm=[1, 0, 2]) + +# 注:x 为 3D Tensor +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.symeig.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.symeig.md new file mode 100644 index 00000000000..a2ca327c419 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.symeig.md @@ -0,0 +1,54 @@ +## [torch 参数更多]torch.Tensor.symeig + +### [torch.Tensor.symeig](https://pytorch.org/docs/stable/generated/torch.Tensor.symeig.html#torch.Tensor.symeig) + +```python +# pytorch1.9 以上版本不支持 +torch.Tensor.symeig(eigenvectors=False, upper=True) +``` + +### [paddle.linalg.eigh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eigh_cn.html) + +```python +# eigenvectors 为 True +paddle.linalg.eigh(x, UPLO='L', name=None) + +# eigenvectors 为 False +paddle.linalg.eigvalsh(x, UPLO='L', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------ | +| - | x | 表示输入的 Tensor 。 | +| eigenvectors | - | 表示是否计算 eigenvectors,Paddle 无此参数,需要转写。 | +| upper | UPLO | 表示计算上三角或者下三角矩阵,PyTorch 取值 bool 类型,Paddle 取值 L, U。 | + +### 转写示例 + +#### eigenvectors:表示是否计算特征向量 +```python +# PyTorch 写法,eigenvectors 为 False +e, _ = x.symeig(eigenvectors=False) + +# Paddle 写法 +e = paddle.linalg.eigvalsh(x) + +# PyTorch 写法,eigenvectors 为 True +e, v = x.symeig(eigenvectors=True) + +# Paddle 写法 +e, v = paddle.linalg.eigh(x) +``` + +#### upper:表示计算上三角或者下三角矩阵 +```python +# PyTorch 写法 +e, v = x.symeig(upper = False) + +# Paddle 写法 +e, v = paddle.linalg.eigh(x, UPLO = 'L') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.t.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.t.md new file mode 100644 index 00000000000..01b83f5ed8e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.t.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.t + +### [torch.Tensor.t](https://pytorch.org/docs/stable/generated/torch.Tensor.t.html#torch.Tensor.t) + +```python +torch.Tensor.t() +``` + +### [paddle.Tensor.t](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#t-name-none) + +```python +paddle.Tensor.t() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md new file mode 100644 index 00000000000..3c4467b85b1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take.md @@ -0,0 +1,30 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor.take + +### [torch.Tensor.take](https://pytorch.org/docs/stable/generated/torch.Tensor.take.html#torch.Tensor.take) + +```python +torch.Tensor.take(indices) +``` + +### [paddle.Tensor.take](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#take-index-mode-raise-name-none) + +```python +paddle.Tensor.take(index, mode='raise', name=None) +``` + +两者功能一致,仅参数名不一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| indices | index | 表示输入 tensor 的索引,仅参数名不一致。 | +| - | mode | 指定索引越界的 3 种处理方式,PyTorch 无此参数,Paddle 保持默认即可。 | + +注: + +三种 mode + +- `mode='raise'`,若索引越界,通过最后调用的 `paddle.index_select` 抛出错误 (默认); +- `mode='wrap'`,通过取余约束越界的 indices; +- `mode='clip'`,通过 `paddle.clip` 将两端超出范围的索引约束到 [0, max_index-1]。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take_along_dim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take_along_dim.md new file mode 100644 index 00000000000..91e6e8f9de9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.take_along_dim.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.Tensor.take_along_dim +### [torch.Tensor.take_along_dim](https://pytorch.org/docs/stable/generated/torch.Tensor.take_along_dim.html?highlight=torch+tensor+take_along_dim#torch.Tensor.take_along_dim) + +```python +torch.Tensor.take_along_dim(indices, + dim) +``` + +### [paddle.Tensor.take_along_axis]( ) + +```python +paddle.Tensor.take_along_axis(indices, + axis, + broadcast=True) +``` + +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| indices | indices | 索引矩阵,包含沿轴提取 1d 切片的下标,必须和 arr 矩阵有相同的维度,需要能够 broadcast 与 arr 矩阵对齐,数据类型为:int、int64。 | +| dim | axis | 指定沿着哪个维度获取对应的值,数据类型为:int,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md new file mode 100644 index 00000000000..ed6c896330a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.tan + +### [torch.Tensor.tan](https://pytorch.org/docs/stable/generated/torch.Tensor.tan.html#torch.Tensor.tan) + +```python +torch.Tensor.tan() +``` + +### [paddle.Tensor.tan]() + +```python +paddle.Tensor.tan() +``` + +两者功能一致,无参数. diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan_.md new file mode 100644 index 00000000000..df73370cbc0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tan_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.tan_ + +### [torch.Tensor.tan_](https://pytorch.org/docs/stable/generated/torch.Tensor.tan_.html) + +```python +torch.Tensor.tan_() +``` + +### [paddle.Tensor.tan_]() + +```python +paddle.Tensor.tan_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md new file mode 100644 index 00000000000..514297cf873 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.tanh + +### [torch.Tensor.tanh](https://pytorch.org/docs/stable/generated/torch.Tensor.tanh.html#torch.Tensor.tanh) + +```python +torch.Tensor.tanh() +``` + +### [paddle.Tensor.tanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tanh-name-none) + +```python +paddle.Tensor.tanh() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md new file mode 100644 index 00000000000..80bdd1e2223 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tanh_.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.tanh_ + +### [torch.Tensor.tanh_](https://pytorch.org/docs/stable/generated/torch.Tensor.tanh_.html#torch.Tensor.tanh_) + +```python +torch.Tensor.tanh_() +``` + +### [paddle.Tensor.tanh_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id22) + +```python +paddle.Tensor.tanh_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tensor_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tensor_split.md new file mode 100644 index 00000000000..5926b3633e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tensor_split.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.tensor_split +### [torch.Tensor.tensor_split](https://pytorch.org/docs/stable/generated/torch.Tensor.tensor_split.html) + +```python +torch.Tensor.tensor_split(indices_or_sections, dim=0) +``` + +### [paddle.Tensor.tensor_split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tensor_split-num_or_indices-axis-0-name-none) + +```python +paddle.Tensor.tensor_split(num_or_indices, axis=0, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| indices_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md new file mode 100644 index 00000000000..e6db442ac19 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tile.md @@ -0,0 +1,34 @@ +## [ 参数不一致 ] torch.Tensor.tile + +### [torch.Tensor.tile](https://pytorch.org/docs/stable/generated/torch.Tensor.tile.html#torch.Tensor.tile) + +```python +torch.Tensor.tile(*reps) +``` + +### [paddle.Tensor.tile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tile-repeat-times-name-none) + +```python +paddle.Tensor.tile(repeat_times, name=None) +``` + +两者功能一致,但 pytorch 的 `reps` 和 paddle 的 `repeat_times` 参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| *reps | repeat_times | 维度复制次数, PyTorch 参数 reps 既可以是可变参数,也可以是 list/tuple/tensor 的形式, Paddle 参数 repeat_times 为 list/tuple/tensor 的形式。 | + +转写示例 + +#### ***reps: 维度复制次数** + +```python +# PyTorch 写法 +x = torch.tensor([1, 2, 3]) +x.tile(2,3) +# Paddle 写法 +y= paddle.to_tensor([1, 2, 3], dtype='int32') +y.tile([2,3]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to.md new file mode 100644 index 00000000000..7d5b9d0f621 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to.md @@ -0,0 +1,124 @@ +## [torch 参数更多]torch.Tensor.to + +### [torch.Tensor.to](https://pytorch.org/docs/stable/generated/torch.Tensor.to.html#torch.Tensor.to) + +```python +torch.Tensor.to(dtype, non_blocking=False, copy=False, memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#to-args-kwargs) + +```python +paddle.Tensor.to(dtype, blocking=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| dtype | dtype | 表示输出 Tensor 的数据类型。 | +| non_blocking | blocking | 控制 cpu 和 gpu 数据的异步复制,取值相反,需要转写。 | +| copy | - | 表示是否复制,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### non_blocking: cpu 和 gpu 数据的异步复制 + +``` python +# PyTorch 写法 +x = torch.tensor([1, 2, 3]) +x.to(dtype, non_blocking=True) + +# Paddle 写法 +x= paddle.to_tensor([1, 2, 3]) +x.to(dtype, blocking=False) +``` + +--- + +### [torch.Tensor.to](https://pytorch.org/docs/stable/generated/torch.Tensor.to.html#torch.Tensor.to) + +```python +torch.Tensor.to(device=None, dtype=None, non_blocking=False, copy=False, memory_format=torch.preserve_format) +``` + +### [paddle.Tensor.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#to-args-kwargs) + +```python +paddle.Tensor.to(device, dtype=None, blocking=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| device | device | 表示 Tensor 存放设备位置。 | +| dtype | dtype | 表示输出 Tensor 的数据类型。 | +| non_blocking | blocking | 控制 cpu 和 gpu 数据的异步复制,取值相反,需要转写。 | +| copy | - | 表示是否复制,Paddle 无此参数,暂无转写方式。 | +| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### non_blocking: cpu 和 gpu 数据的异步复制 + +``` python +# PyTorch 写法 +x = torch.tensor([1, 2, 3]) +x.to(device, dtype, non_blocking=True) + +# Paddle 写法 +x= paddle.to_tensor([1, 2, 3]) +x.to(device, dtype, blocking=False) +``` + +--- + +### [torch.Tensor.to](https://pytorch.org/docs/stable/generated/torch.Tensor.to.html#torch.Tensor.to) + +```python +torch.Tensor.to(other, non_blocking=False, copy=False) +``` + +### [paddle.Tensor.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#to-args-kwargs) + +```python +paddle.Tensor.to(dtype) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ----------------------------------------------------- | +| other | - | 表示参照 dtype 的 Tensor,Paddle 无此参数,需要转写。 | +| non_blocking | blocking | 控制 cpu 和 gpu 数据的异步复制,取值相反,需要转写。 | +| copy | - | 表示是否复制,Paddle 无此参数,暂无转写方式。 | + +### 转写示例 + +#### other: 表示参照 dtype 的 Tensor + +```python +# PyTorch 写法 +y = x.to(x2) + +# Paddle 写法 +y = x.to(x2.dtype) +``` + +#### non_blocking: cpu 和 gpu 数据的异步复制 + +``` python +# PyTorch 写法 +y = x.to(x2, non_blocking=True) + +# Paddle 写法 +y = x.to(x2.dtype, blocking=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_dense.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_dense.md new file mode 100644 index 00000000000..7513aebec9a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_dense.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.to_dense + +### [torch.Tensor.to_dense](https://pytorch.org/docs/stable/generated/torch.Tensor.to_dense.html#torch-tensor-to-dense) + +```python +torch.Tensor.to_dense() +``` + +### [paddle.Tensor.to_dense](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor/to_dense_en.html#to-dense) + +```python +paddle.Tensor.to_dense() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md new file mode 100644 index 00000000000..277b09b035e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.to_sparse.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.Tensor.to_sparse + +### [torch.Tensor.to_sparse](https://pytorch.org/docs/stable/generated/torch.Tensor.to_sparse.html#torch.Tensor.to_sparse) + +```python +torch.Tensor.to_sparse(sparseDims) +``` + +### [paddle.Tensor.to_sparse_coo]() + +```python +paddle.Tensor.to_sparse_coo(sparseDims) +``` + +两者功能一致,参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------------------------------------ | +| sparseDims | sparseDims | 在新的稀疏张量中包含的稀疏维度的数量 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md new file mode 100644 index 00000000000..616cced334e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tolist.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.Tensor.tolist + +### [torch.Tensor.tolist](https://pytorch.org/docs/stable/generated/torch.Tensor.tolist.html#torch.Tensor.tolist) + +```python +torch.Tensor.tolist() +``` + +### [paddle.Tensor.tolist](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#tolist) + +```python +paddle.Tensor.tolist() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md new file mode 100644 index 00000000000..e3608fb83a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.topk.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ] torch.Tensor.topk + +### [torch.Tensor.topk](https://pytorch.org/docs/stable/generated/torch.Tensor.topk.html#torch.Tensor.topk) + +```python +torch.Tensor.topk(k, dim=None, largest=True, sorted=True) +``` + +### [paddle.Tensor.topk](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#topk-k-axis-none-largest-true-sorted-true-name-none) + +```python +paddle.Tensor.topk(k, axis=None, largest=True, sorted=True, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------- | +| k | k | 表示前 k 个最大项。 | +| dim | axis | 表示排序的维度,仅参数名不一致。 | +| largest | largest | True: 最大值, False: 最小值。 | +| sorted | sorted | 表示是否排序。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trace.md new file mode 100644 index 00000000000..7acab3b852f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trace.md @@ -0,0 +1,23 @@ +## [仅 paddle 参数更多]torch.Tensor.trace + +### [torch.Tensor.trace](https://pytorch.org/docs/stable/generated/torch.Tensor.trace.html#torch-tensor-trace) + +```python +torch.Tensor.trace() +``` + +### [paddle.Tensor.trace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#trace-offset-0-axis1-0-axis2-1-name-none) + +```python +paddle.Tensor.trace(offset=0, axis1=0, axis2=1, name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| - | offset | 表示指定的二维平面中获取对角线的位置,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | axis1 | 表示获取对角线的二维平面的第一维,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | axis2 | 表示获取对角线的二维平面的第二维,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.transpose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.transpose.md new file mode 100644 index 00000000000..bde793a0e97 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.transpose.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.Tensor.transpose + +### [torch.Tensor.transpose](https://pytorch.org/docs/stable/generated/torch.Tensor.transpose.html) + +```python +torch.Tensor.transpose(dim0, dim1) +``` + +### [paddle.Tensor.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#transpose-perm-name-none) + +```python +paddle.Tensor.transpose(perm, name=None) +``` + +PyTorch 的 `dim0, dim1` 与 Paddle 的 `perm` 用法不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim0, dim1 | perm | torch 的 dim0 与 dim1 表示要交换的两个维度, 为整数。 paddle 的 perm 表示重排的维度序列,为 list/tuple 。需要转写。| + +### 转写示例 +#### dim0, dim1: 表示要交换的两个维度 +```python +# pytorch +x = torch.randn(2, 3, 5) +y = x.transpose(0, 1) + +# paddle +x = paddle.randn([2, 3, 5]) +y = x.transpose(perm=[1, 0, 2]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triangular_solve.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triangular_solve.md new file mode 100644 index 00000000000..166f4cde285 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triangular_solve.md @@ -0,0 +1,47 @@ +## [参数不一致]torch.Tensor.triangular_solve + +### [torch.Tensor.triangular_solve](https://pytorch.org/docs/stable/generated/torch.Tensor.triangular_solve.html#torch.Tensor.triangular_solve) + +```python +torch.Tensor.triangular_solve(A, upper=True, transpose=False, unitriangular=False) +``` + +### [paddle.Tensor.triangular_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#triangular-solve-b-upper-true-transpose-false-unitriangular-false-name-none) + +```python +paddle.Tensor.triangular_solve(b, upper=True, transpose=False, unitriangular=False, name=None) +``` + +其中两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | ----------------------------------------------------------- | +| A | - | 线性方程组系数矩阵,Paddle 需要转写。 | +| - | b | 线性方程组右边的矩阵,Paddle 需要转写。 | +| upper | upper | 对系数矩阵 x 取上三角还是下三角。 | +| transpose | transpose | 是否对系数矩阵 x 进行转置。 | +| unitriangular | unitriangular | 如果为 True,则将系数矩阵 x 对角线元素假设为 1 来求解方程。 | + +### 转写示例 + +#### A:线性方程组系数矩阵 + +```python +# PyTorch 写法 +A = torch.tensor([[1, 1, 1], + [0, 2, 1], + [0, 0,-1]], dtype=torch.float64) +b = torch.tensor([[0], [-9], [5]], dtype=torch.float64) +b.triangular_solve(A) + +# Paddle 写法 +A = paddle.to_tensor([[1, 1, 1], + [0, 2, 1], + [0, 0,-1]], dtype=paddle.float64) +b = paddle.to_tensor([[0], [-9], [5]], dtype=paddle.float64) +A.triangular_solve(b) + +# 注:Paddle 将 A 与 b 交换 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril.md new file mode 100644 index 00000000000..24faa39e517 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.tril + +### [torch.Tensor.tril](https://pytorch.org/docs/stable/generated/torch.Tensor.tril.html#torch.Tensor.tril) + +```python +torch.Tensor.tril(diagonal=0) +``` + +### [paddle.Tensor.tril]() + +```python +paddle.Tensor.tril(diagonal=0, name=None) +``` + +两者功能一致且参数用法一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| diagonal | diagonal | 表示运算的对角线,参数完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril_.md new file mode 100644 index 00000000000..b1fb17346d9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.tril_.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.Tensor.tril_ + +### [torch.Tensor.tril_](https://pytorch.org/docs/stable/generated/torch.Tensor.tril_.html#torch.Tensor.tril_) + +```python +torch.Tensor.tril_(diagonal=0) +``` + +### [paddle.Tensor.tril_]() + +```python +paddle.Tensor.tril_(diagonal=0) +``` + +两者功能一致且参数用法一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| diagonal | diagonal | 表示运算的对角线,参数完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu.md new file mode 100644 index 00000000000..654c518cd27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.triu + +### [torch.Tensor.triu](https://pytorch.org/docs/stable/generated/torch.Tensor.triu.html#torch.Tensor.triu) + +```python +torch.Tensor.triu(diagonal=0) +``` + +### [paddle.Tensor.triu]() + +```python +paddle.Tensor.triu(diagonal=0, name=None) +``` + +两者功能一致且参数用法一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| diagonal | diagonal | 表示运算的对角线,参数完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu_.md new file mode 100644 index 00000000000..301e7f3835f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.triu_.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.Tensor.triu_ + +### [torch.Tensor.triu_](https://pytorch.org/docs/stable/generated/torch.Tensor.triu_.html#torch.Tensor.triu_) + +```python +torch.Tensor.triu_(diagonal=0) +``` + +### [paddle.Tensor.triu_]() + +```python +paddle.Tensor.triu_(diagonal=0) +``` + +两者功能一致且参数用法一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| diagonal | diagonal | 表示运算的对角线,参数完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide.md new file mode 100644 index 00000000000..1c83d79e420 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.Tensor.true_divide + +### [torch.Tensor.true_divide](https://pytorch.org/docs/stable/generated/torch.Tensor.true_divide.html#torch.Tensor.true_divide) + +```python +torch.Tensor.true_divide(value) +``` + +### [paddle.Tensor.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#divide-y-name-none) + +```python +paddle.Tensor.divide(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| value | y | 表示输入的 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide_.md new file mode 100644 index 00000000000..d4aa4b715b0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.true_divide_.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.true_divide_ + +### [torch.Tensor.true_divide_](https://pytorch.org/docs/stable/generated/torch.Tensor.true_divide_.html) + +```python +torch.Tensor.true_divide_(other) +``` + +### [paddle.Tensor.divide_]() + +```python +paddle.Tensor.divide_(y) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -------------------------------- | +| other | y | 表示输入的 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc.md new file mode 100644 index 00000000000..978fa791f28 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc.md @@ -0,0 +1,15 @@ +## [无参数]torch.Tensor.trunc + +### [torch.Tensor.trunc](https://pytorch.org/docs/stable/generated/torch.Tensor.trunc.html#torch.Tensor.trunc) + +```python +torch.Tensor.trunc() +``` + +### [paddle.Tensor.trunc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#trunc-name-none) + +```python +paddle.Tensor.trunc() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc_.md new file mode 100644 index 00000000000..18515e4fcf9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.trunc_.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.trunc_ + +### [torch.Tensor.trunc_](https://pytorch.org/docs/stable/generated/torch.Tensor.trunc_.html) + +```python +torch.Tensor.trunc_() +``` + +### [paddle.Tensor.trunc_]() + +```python +paddle.Tensor.trunc_() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type.md new file mode 100644 index 00000000000..a1024ed29c9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.Tensor.type + +### [torch.Tensor.type](https://pytorch.org/docs/stable/generated/torch.Tensor.type.html#torch.Tensor.type) + +```python +torch.Tensor.type(dtype=None, non_blocking=False, **kwargs) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype(dtype) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------ | +| dtype | dtype | 转换后的 dtype。 | +| non_blocking | - | 控制 cpu 和 gpu 数据的异步复制,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type_as.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type_as.md new file mode 100644 index 00000000000..9235c6f69ff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.type_as.md @@ -0,0 +1,25 @@ +## [ 组合替代实现 ] torch.Tensor.type_as + +### [torch.Tensor.type_as](https://pytorch.org/docs/stable/generated/torch.Tensor.type_as.html) + +```python +torch.Tensor.type_as(tensor) +``` + +### [paddle.Tensor.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#astype-dtype) + +```python +paddle.Tensor.astype(dtype=tensor.dtype) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 +#### +```python +# PyTorch 写法 +x.type_as(a) + +# Paddle 写法 +x.astype(dtype=a.dtype) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unbind.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unbind.md new file mode 100644 index 00000000000..74c46914260 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unbind.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.Tensor.unbind + +### [torch.Tensor.unbind](https://pytorch.org/docs/stable/generated/torch.Tensor.unbind.html#torch.Tensor.unbind) + +```python +torch.Tensor.unbind(dim=0) +``` + +### [paddle.Tensor.unbind](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unbind-axis-0) + +```python +paddle.Tensor.unbind(axis=0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unflatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unflatten.md new file mode 100644 index 00000000000..304ddcf5f13 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unflatten.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ] torch.Tensor.unflatten + +### [torch.Tensor.unflatten](https://pytorch.org/docs/stable/generated/torch.Tensor.unflatten.html#torch.Tensor.unflatten) + +```python +torch.Tensor.unflatten(dim, sizes) +``` + +### [paddle.Tensor.unflatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unflatten-axis-shape-name-none) + +```python +paddle.Tensor.unflatten(axis, shape, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 需要变换的维度,仅参数名不一致。 | +| sizes | shape | 维度变换的新形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unfold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unfold.md new file mode 100644 index 00000000000..c427aefcb1c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unfold.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.Tensor.unfold + +### [torch.Tensor.unfold](https://pytorch.org/docs/stable/generated/torch.Tensor.unfold.html?highlight=unfold#torch.Tensor.unfold) + +```python +torch.Tensor.unfold(dimension, + size, + step) +``` + +### [paddle.Tensor.unfold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unfold-x-axis-size-step-name-none) + +```python +paddle.Tensor.unfold(axis, + size, + step, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| dimension | axis | 表示需要提取的维度,仅参数名不一致。 | +| size | size | 表示需要提取的窗口长度。 | +| step | step | 表示每次提取跳跃的步长。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.uniform_.md new file mode 100644 index 00000000000..b038d4c82ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.uniform_.md @@ -0,0 +1,23 @@ +## [仅 paddle 参数更多]torch.Tensor.uniform_ + +### [torch.Tensor.uniform_](https://pytorch.org/docs/stable/generated/torch.Tensor.uniform_.html#torch-tensor-uniform) + +```python +torch.Tensor.uniform_(from=0, to=1) +``` + +### [paddle.Tensor.uniform_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#uniform-min-1-0-max-1-0-seed-0-name-none) + +```python +paddle.Tensor.uniform_(min=- 1.0, max=1.0, seed=0, name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| from | min | 表示生成元素的起始位置,仅参数名不一致。 | +| to | max | 表示生成元素的结束位置,仅参数名不一致。 | +| - | seed | 表示用于生成随机数的随机种子,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique.md new file mode 100644 index 00000000000..4ec7202c2c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique.md @@ -0,0 +1,34 @@ +## [torch 参数更多] torch.Tensor.unique +### [torch.Tensor.unique](https://pytorch.org/docs/stable/generated/torch.Tensor.unique.html?highlight=unique#torch.Tensor.unique) + +```python +torch.Tensor.unique(sorted=True, return_inverse=False, return_counts=False, dim=None) +``` + +### [paddle.Tensor.unique](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unique-return-index-false-return-inverse-false-return-counts-false-axis-none-dtype-int64-name-none) + +```python +paddle.Tensor.unique(return_index=False, return_inverse=False, return_counts=False, axis=None, dtype='int64', name=None) +``` + +两者功能一致,torch 参数更多,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| sorted | - | 是否返回前进行排序,Paddle 无此参数,需要转写。 | +| return_inverse| return_inverse | 是否返回输入 Tensor 的元素对应在独有元素中的索引。 | +| return_counts | return_counts | 是否返回每个独有元素在输入 Tensor 中的个数。 | +| dim | axis | 选取的轴,仅参数名不一致。 | +| - | return_index| 是否返回独有元素在输入 Tensor 中的索引,PyTorch 无此参数, Paddle 保持默认即可。| + +### 转写示例 +#### sorted:是否对返回值进行排序 +```python +# 当 sorted 为‘True’时,torch 写法 +torch.Tensor.unique(sorted=True, return_inverse=False, return_counts=False, dim=1) + +# paddle 写法 +paddle.Tensor.unique(return_index=False, return_inverse=False, return_counts=False, axis=1) + +# 当 sorted 为‘False’时,暂时无法转写 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique_consecutive.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique_consecutive.md new file mode 100644 index 00000000000..4dc4cc08622 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unique_consecutive.md @@ -0,0 +1,24 @@ +## [仅 paddle 参数更多]torch.Tensor.unique_consecutive + +### [torch.Tensor.unique_consecutive](https://pytorch.org/docs/stable/generated/torch.Tensor.unique_consecutive.html#torch.Tensor.unique_consecutive) + +```python +torch.Tensor.unique_consecutive(return_inverse=False, return_counts=False, dim=None) +``` + +### [paddle.Tensor.unique_consecutive]() + +```python +paddle.Tensor.unique_consecutive(return_inverse=False, return_counts=False, axis=None, dtype='int64', name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | -------------- | ------------------------------------------------------------ | +| return_inverse | return_inverse | 表示输入 Tensor 的元素对应在连续不重复元素中的索引。参数完全一致。 | +| return_counts | return_counts | 表示每个连续不重复元素在输入 Tensor 中的个数。参数完全一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| - | dtype | 表示设置 inverse 或 counts 的类型。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md new file mode 100644 index 00000000000..98b9b2be484 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.Tensor.unsqueeze + +### [torch.Tensor.unsqueeze](https://pytorch.org/docs/stable/generated/torch.Tensor.unsqueeze.html#torch.Tensor.unsqueeze) + +```python +torch.Tensor.unsqueeze(dim) +``` + +### [paddle.Tensor.unsqueeze](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#unsqueeze-axis-name-none) + +```python +paddle.Tensor.unsqueeze(axis, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze_.md new file mode 100644 index 00000000000..eaee5065fa9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.unsqueeze_.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.Tensor.unsqueeze_ + +### [torch.Tensor.unsqueeze_](https://pytorch.org/docs/stable/generated/torch.Tensor.unsqueeze_.html#torch-tensor-unsqueeze) + +```python +torch.Tensor.unsqueeze_(dim) +``` + +### [paddle.Tensor.unsqueeze_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#id22) + +```python +paddle.Tensor.unsqueeze_(axis, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.values.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.values.md new file mode 100644 index 00000000000..62ede0b8c36 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.values.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.Tensor.values + +### [torch.Tensor.values](https://pytorch.org/docs/stable/generated/torch.Tensor.values.html?highlight=torch+tensor+values#torch.Tensor.values) + +```python +torch.Tensor.values() +``` + +### [paddle.Tensor.values](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/Overview_cn.html) + +```python +paddle.Tensor.values() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.var.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.var.md new file mode 100644 index 00000000000..270b450296f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.var.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.Tensor.var + +### [torch.Tensor.var](https://pytorch.org/docs/stable/generated/torch.Tensor.var.html#torch.Tensor.var) + +```python +torch.Tensor.var(dim, unbiased=True, keepdim=False) +``` + +### [paddle.Tensor.var](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#var-axis-none-unbiased-true-keepdim-false-name-none) + +```python +paddle.Tensor.var(axis=None, unbiased=True, keepdim=False, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定对 Tensor 进行计算的轴 ,仅参数名不一致。 | +| unbiased | unbiased | 表示是否使用无偏估计来计算方差。 | +| keepdim | keepdim | 表示是否保留计算后的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vdot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vdot.md new file mode 100644 index 00000000000..a2c04d3c96c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vdot.md @@ -0,0 +1,20 @@ +## [仅参数名不一致]torch.Tensor.vdot + +### [torch.Tensor.vdot](https://pytorch.org/docs/stable/generated/torch.Tensor.vdot.html#torch.Tensor.vdot) + +```python +torch.Tensor.vdot(other) +``` + +### [paddle.Tensor.dot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#dot-y-name-none) + +```python +paddle.Tensor.dot(y, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| other | y | 被乘的向量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view.md new file mode 100644 index 00000000000..c6603d90c70 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view.md @@ -0,0 +1,34 @@ +## [ 参数不一致 ]torch.Tensor.view + +### [torch.Tensor.view](https://pytorch.org/docs/stable/generated/torch.Tensor.view.html?highlight=view#torch.Tensor.view) + +```python +torch.Tensor.view(*shape) +torch.Tensor.view(dtype) +``` + +### [paddle.Tensor.view](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#view-x-shape-or-dtype-name-none) + +```python +paddle.Tensor.view(shape_or_dtype, name=None) +``` + +两者功能一致, 但 pytorch 的 `*shape` 和 paddle 的 `shape_or_dtype` 参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| *shape | shape_or_dtype | 指定的维度。 PyTorch 参数 shape 既可以是可变参数,也可以是 list/tuple/torch.Size/dtype 的形式, Paddle 参数 shape_or_dtype 为 list/tuple/dtype 的形式。对于可变参数的用法,需要进行转写。 | + +### 转写示例 + +```python +# PyTorch 写法 +x = torch.randn(4, 4) +x.view(2, 2, 4) + +# Paddle 写法 +x = paddle.randn(4, 4) +x.view([2, 2, 4]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view_as.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view_as.md new file mode 100644 index 00000000000..fd26f41c301 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.view_as.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.Tensor.view_as + +### [torch.Tensor.view_as](https://pytorch.org/docs/stable/generated/torch.Tensor.view_as.html?highlight=view_as#torch.Tensor.view_as) + +```python +torch.Tensor.view_as(other) +``` + +### [paddle.Tensor.view_as](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#view-as-x-other-name-none) + +```python +paddle.Tensor.view_as(other, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| other | other | 与返回 Tensor shape 相同的 Tensor | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vsplit.md new file mode 100644 index 00000000000..cf572aa277b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.vsplit.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.Tensor.vsplit + +### [torch.Tensor.vsplit](https://pytorch.org/docs/stable/generated/torch.Tensor.vsplit.html) + +```python +torch.Tensor.vsplit(split_size_or_sections) +``` + +### [paddle.Tensor.vsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#vsplit-num_or_indices-name-none) + +```python +paddle.Tensor.vsplit(num_or_indices, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| split_size_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md new file mode 100644 index 00000000000..dc0291b07c9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.where.md @@ -0,0 +1,36 @@ +## [ 参数不一致 ]torch.Tensor.where + +### [torch.Tensor.where](https://pytorch.org/docs/stable/generated/torch.Tensor.where.html#torch.Tensor.where) + +```python +torch.Tensor.where(condition, y) +``` + +### [paddle.Tensor.where](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#where-y-name-none) + +```python +paddle.Tensor.where(x, y, name=None) +``` + +两者功能一致,参数名和参数用法不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| condition | - | condition 为判断条件。Paddle 无此参数,需要转写。| +| - | x | 当 condition 为 true 时,选择 x 中元素。| +| y | y | 当 condition 为 false 时,选择 y 中元素。| + + +### 转写示例 + +```python +# torch 写法 +a = torch.tensor([0, 1, 2]) +b = torch.tensor([2, 3, 0]) +c = a.where(a > 0, b) + +# paddle 写法 +a = paddle.to_tensor([0, 1, 2]) +b = paddle.to_tensor([2, 3, 0]) +c = (a > 0).where(a, b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.xlogy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.xlogy.md new file mode 100644 index 00000000000..051e248939a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.xlogy.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.xlogy + +### [torch.Tensor.xlogy](https://pytorch.org/docs/stable/generated/torch.Tensor.xlogy.html#torch.Tensor.xlogy) + +```python +torch.Tensor.xlogy(other) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.xlogy(b) + +# Paddle 写法 +y = a * paddle.log(b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.zero_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.zero_.md new file mode 100644 index 00000000000..f81e7186f05 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/Tensor/torch.Tensor.zero_.md @@ -0,0 +1,15 @@ +## [无参数]torch.Tensor.zero_ + +### [torch.Tensor.zero_](https://pytorch.org/docs/stable/generated/torch.Tensor.zero_.html#torch.Tensor.zero_) + +```python +torch.Tensor.zero_() +``` + +### [paddle.Tensor.zero_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#zero-x-name-none) + +```python +paddle.Tensor.zero_() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.BoolTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.BoolTensor.md new file mode 100644 index 00000000000..3a32fe59f2e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.BoolTensor.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.BoolTensor + +### [torch.cuda.BoolTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.BoolTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='bool', place='gpu', stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'bool'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ByteTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ByteTensor.md new file mode 100644 index 00000000000..45c8a2520ef --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ByteTensor.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.ByteTensor + +### [torch.cuda.ByteTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.ByteTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='uint8', place='gpu', stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'uint8'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.DoubleTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.DoubleTensor.md new file mode 100644 index 00000000000..0150cb2fe0f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.DoubleTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.DoubleTensor + +### [torch.cuda.DoubleTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.DoubleTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float64', place='gpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float64'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Event.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Event.md new file mode 100644 index 00000000000..305bd4a2287 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Event.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.cuda.Event + +### [torch.cuda.Event](https://pytorch.org/docs/stable/generated/torch.cuda.Event.html#torch.cuda.Event) + +```python +torch.cuda.Event(enable_timing=False, blocking=False, interprocess=False) +``` + +### [paddle.device.cuda.Event](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/Event_cn.html) + +```python +paddle.device.cuda.Event(enable_timing=False, blocking=False, interprocess=False) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +|---------------|-------------------| ------------------------------------------------------ | +| enable_timing | enable_timing | 表示是否需要统计时间。默认值为 False。 | +| blocking | blocking | 表示 wait()函数是否被阻塞。默认值为 False。 | +| interprocess | interprocess | 表示是否能在进程间共享。默认值为 False。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.FloatTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.FloatTensor.md new file mode 100644 index 00000000000..ade385c8bbf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.FloatTensor.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.FloatTensor + +### [torch.cuda.FloatTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.FloatTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float32', place='gpu', stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float32'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.HalfTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.HalfTensor.md new file mode 100644 index 00000000000..c543b687f65 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.HalfTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.HalfTensor + +### [torch.cuda.HalfTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.HalfTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='float16', place='gpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------| ------------ |--------------------------------------------------| +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'float16'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.IntTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.IntTensor.md new file mode 100644 index 00000000000..fee0cc9c408 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.IntTensor.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.IntTensor + +### [torch.cuda.IntTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.IntTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int32', place='gpu', stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int32'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.LongTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.LongTensor.md new file mode 100644 index 00000000000..7f6c37d4621 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.LongTensor.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.LongTensor + +### [torch.cuda.LongTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.LongTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int64', place='gpu', stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int64'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ShortTensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ShortTensor.md new file mode 100644 index 00000000000..4bedd6423fc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.ShortTensor.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.cuda.ShortTensor + +### [torch.cuda.ShortTensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.cuda.ShortTensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype='int16', place='gpu') +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 需设置为 'int16'。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'gpu' 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md new file mode 100644 index 00000000000..7f6da8f26f5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.Stream__upper.md @@ -0,0 +1,38 @@ +## [参数不一致]torch.cuda.Stream + +### [torch.cuda.Stream](https://pytorch.org/docs/stable/generated/torch.cuda.Stream.html#torch.cuda.Stream) + +```python +torch.cuda.Stream(device=None, priority=0, **kwargs) +``` + +### [paddle.device.cuda.Stream](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/Stream_cn.html) + +```python +paddle.device.cuda.Stream(device=None, priority=None) +``` + +两者功能一致,参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | ----------------------------------------------------------------------------------------- | +| device | device | 希望分配 stream 的设备。 | +| priority | priority | stream 的优先级,PyTorch 取值范围为-1、0,Paddle 的取值范围为 1、2,需要转写。 | + +### 转写示例 + +#### priority: stream 的优先级 + +```python +# PyTorch 写法 +high_priority = -1 +default_priority = 0 +y = torch.cuda.Stream(priority=default_priority) + +# Paddle 写法 +high_priority = 1 +default_priority = 2 +y = paddle.device.cuda.Stream(priority=default_priority) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.GradScaler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.GradScaler.md new file mode 100644 index 00000000000..346f5a89bec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.GradScaler.md @@ -0,0 +1,27 @@ +## [仅参数默认值不一致]torch.cuda.amp.GradScaler + +### [torch.cuda.amp.GradScaler](https://pytorch.org/docs/stable/amp.html#torch.cuda.amp.GradScaler) + +```python +torch.cuda.amp.GradScaler(init_scale=65536.0, growth_factor=2.0, backoff_factor=0.5, growth_interval=2000, enabled=True) +``` + +### [paddle.amp.GradScaler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amp/GradScaler_cn.html) + +```python +paddle.amp.GradScaler(enable=True, init_loss_scaling=65536.0, incr_ratio=2.0, decr_ratio=0.5, incr_every_n_steps=2000, decr_every_n_nan_or_inf=2, use_dynamic_loss_scaling=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数且参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------------- | ------------------------ |-----------------------------------------------------------------------------| +| init_scale | init_loss_scaling | 初始 loss scaling 因子。与 PyTorch 默认值不同, Paddle 需设为 65536.0。 | +| growth_factor | incr_ratio | 增大 loss scaling 时使用的乘数。 | +| backoff_factor | decr_ratio | 减小 loss scaling 时使用的小于 1 的乘数。 | +| growth_interval | incr_every_n_steps | 连续 n 个 steps 的梯度都是有限值时,增加 loss scaling。与 PyTorch 默认值不同, Paddle 需设为 2000。 | +| enabled | enable | 是否使用 loss scaling。 | +| - | decr_every_n_nan_or_inf | 累计出现 n 个 steps 的梯度为 nan 或者 inf 时,减小 loss scaling,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_dynamic_loss_scaling | 是否使用动态的 loss scaling,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.autocast.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.autocast.md new file mode 100644 index 00000000000..c98c8019f45 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.amp.autocast.md @@ -0,0 +1,27 @@ +## [仅 paddle 参数更多]torch.cuda.amp.autocast + +### [torch.cuda.amp.autocast](https://pytorch.org/docs/stable/amp.html#torch.cuda.amp.autocast) + +```python +torch.cuda.amp.autocast(enabled=True, dtype=torch.float16, cache_enabled=True) +``` + +### [paddle.amp.auto_cast](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amp/auto_cast_cn.html) + +```python +paddle.amp.auto_cast(enable=True, custom_white_list=None, custom_black_list=None, level='O1', dtype='float16', use_promote=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ----------------- | ------------------------------------------------------------ | +| enabled | enable | 是否开启自动混合精度。 | +| dtype | dtype | 使用的数据类型。 | +| cache_enabled | - | 是否启用权重缓存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| - | custom_white_list | 自定义算子白名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | custom_black_list | 自定义算子黑名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | level | 混合精度训练模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_promote | 当一个算子存在 float32 类型的输入时,按照 Promote to the Widest 原则,选择 float32 数据类型进行计算。仅在 AMP-O2 训练时可配置。默认为 True。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.comm.broadcast.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.comm.broadcast.md new file mode 100644 index 00000000000..8df2d807489 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.comm.broadcast.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.cuda.comm.broadcast + +### [torch.cuda.comm.broadcast](https://pytorch.org/docs/stable/generated/torch.cuda.comm.broadcast.html#torch.cuda.comm.broadcast) + +```python +torch.cuda.comm.broadcast(tensor, devices=None, *, out=None) +``` + +### [paddle.distributed.broadcast](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/broadcast_cn.html) + +```python +paddle.distributed.broadcast(tensor, src, group=None, sync_op=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| tensor | tensor | 在目标进程上为待广播的 tensor,在其他进程上为用于接收广播结果的 tensor。 | +| devices | src | 发送源的进程编号。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | +| - | group | 工作的进程组编号,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | sync_op | 该操作是否为同步操作。默认为 True,即同步操作。PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### out 参数:指定输出 +``` python +# PyTorch 写法: +torch.cuda.comm.broadcast(x, 0, out=y) + +# Paddle 写法: +paddle.assign(paddle.distributed.broadcast(x, 0) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md new file mode 100644 index 00000000000..b2613355bff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_device.md @@ -0,0 +1,15 @@ +## [无参数]torch.cuda.current_device + +### [torch.cuda.current_device](https://pytorch.org/docs/stable/generated/torch.cuda.current_device.html#torch.cuda.current_device) + +```python +torch.cuda.current_device() +``` + +### [paddle.framework._current_expected_place]() + +```python +paddle.framework._current_expected_place() +``` + +功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md new file mode 100644 index 00000000000..2882e14c31f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.current_stream.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.current_stream + +### [torch.cuda.current_stream](https://pytorch.org/docs/stable/generated/torch.cuda.current_stream.html#torch.cuda.current_stream) + +```python +torch.cuda.current_stream(device=None) +``` + +### [paddle.device.cuda.current_stream](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/current_stream_cn.html) + +```python +paddle.device.cuda.current_stream(device=None) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| device | device | 表示希望获取 stream 的设备或者设备 ID。如果为 None,则为当前的设备。默认值为 None。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md new file mode 100644 index 00000000000..2c3ce1a01fd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device.md @@ -0,0 +1,40 @@ +## [参数不一致]torch.cuda.device + +### [torch.cuda.device](https://pytorch.org/docs/stable/generated/torch.cuda.device.html#torch.cuda.device) + +```python +torch.cuda.device(device) +``` + +### [paddle.CUDAPlace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/CUDAPlace_cn.html) + +```python +paddle.CUDAPlace(id) +``` + +其中 PyTorch 与 Paddle 的参数支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------- | +| device | id | GPU 的设备 ID, PyTorch 支持 torch.device 和 int,Paddle 支持 int,需要转写。 | + +### 转写示例 + +#### device: 获取 device 参数,对其取 device.index 值 + +```python +# PyTorch 写法 +torch.cuda.device(torch.device('cuda')) + +# Paddle 写法 +paddle.CUDAPlace(0) + +# 增加 index +# PyTorch 写法 +torch.cuda.device(torch.device('cuda', index=index)) + +# Paddle 写法 +paddle.CUDAPlace(index) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_count.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_count.md new file mode 100644 index 00000000000..e28ebe4d87e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.device_count.md @@ -0,0 +1,15 @@ +## [无参数]torch.cuda.device_count + +### [torch.cuda.device_count](https://pytorch.org/docs/stable/generated/torch.cuda.device_count.html#torch.cuda.device_count) + +```python +torch.cuda.device_count() +``` + +### [paddle.device.cuda.device_count](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/device_count_cn.html) + +```python +paddle.device.cuda.device_count() +``` + +功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.empty_cache.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.empty_cache.md new file mode 100644 index 00000000000..4bb84891384 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.empty_cache.md @@ -0,0 +1,15 @@ +## [无参数]torch.cuda.empty_cache + +### [torch.cuda.empty_cache](https://pytorch.org/docs/stable/generated/torch.cuda.empty_cache.html#torch.cuda.empty_cache) + +```python +torch.cuda.empty_cache() +``` + +### [paddle.device.cuda.empty_cache](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/empty_cache_cn.html) + +```python +paddle.device.cuda.empty_cache() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_capability.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_capability.md new file mode 100644 index 00000000000..c680eec25de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_capability.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.get_device_capability + +### [torch.cuda.get_device_capability](https://pytorch.org/docs/stable/generated/torch.cuda.get_device_capability.html#torch.cuda.get_device_capability) + +```python +torch.cuda.get_device_capability(device=None) +``` + +### [paddle.device.cuda.get_device_capability](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/get_device_capability_cn.html) + +```python +paddle.device.cuda.get_device_capability(device=None) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- |---------------------| ------------------------------------------------------ | +| device | device | 表示希望获取计算能力的设备或者设备 ID。如果 device 为 None(默认),则为当前的设备。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_name.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_name.md new file mode 100644 index 00000000000..c19518ca448 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_name.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.cuda.get_device_name + +### [torch.cuda.get_device_name](https://pytorch.org/docs/stable/generated/torch.cuda.get_device_name.html) + +```python +torch.cuda.get_device_name(device=None) +``` + +### [paddle.device.cuda.get_device_name](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/get_device_name_cn.html) + +```python +paddle.device.cuda.get_device_name(device=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|-----------------------------------------------------------------------------------------------| +| device | device | torch 的 device 参数类型为 torch.device 或 int 或 str。paddle 的 device 为 paddle.CUDAPlace 或 int 或 str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md new file mode 100644 index 00000000000..b67e7672cf2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_device_properties.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.get_device_properties + +### [torch.cuda.get_device_properties](https://pytorch.org/docs/stable/generated/torch.cuda.get_device_properties.html#torch.cuda.get_device_properties) + +```python +torch.cuda.get_device_properties(device) +``` + +### [paddle.device.cuda.get_device_properties](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/get_device_properties_cn.html) + +```python +paddle.device.cuda.get_device_properties(device) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| device | device | 表示设备、设备 ID 和类似于 gpu:x 的设备名称。如果 device 为空,则 device 为当前的设备。默认值为 None。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state_all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state_all.md new file mode 100644 index 00000000000..081137e9fd6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.get_rng_state_all.md @@ -0,0 +1,34 @@ +## [参数不一致]torch.cuda.get_rng_state_all + +### [torch.cuda.get_rng_state_all](https://pytorch.org/docs/stable/generated/torch.cuda.get_rng_state_all.html#torch.cuda.get_rng_state_all) + +```python +torch.cuda.get_rng_state_all() +``` + +### [paddle.get_rng_state]() + +```python +paddle.get_rng_state(device='gpu') +``` + +paddle 参数更多,并且 torch 与 paddle 的返回参数类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------------------------- | +| - | device | 返回随机数生成器状态的设备,PyTorch 无此参数,Paddle 需设置为'gpu' 。 | +| 返回值 | 返回值 | 返回参数类型不一致, PyTorch 返回 torch.ByteTensor,Paddle 返回 GeneratorState 对象。 | + +### 转写示例 + +#### 返回参数类型不同 + +```python +# PyTorch 写法,返回 torch.ByteTensor +x = torch.cuda.get_rng_state_all() + +# Paddle 写法,返回 GeneratorState 对象 +x = paddle.get_rng_state(device='gpu') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.initial_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.initial_seed.md new file mode 100644 index 00000000000..72257caa06e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.initial_seed.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.cuda.initial_seed + +### [torch.cuda.initial_seed](https://pytorch.org/docs/stable/generated/torch.cuda.initial_seed.html?highlight=torch+cuda+initial_seed#torch.cuda.initial_seed) + +```python +torch.cuda.initial_seed() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.cuda.initial_seed() + +# Paddle 写法 +paddle.get_cuda_rng_state()[0].current_seed() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.is_available.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.is_available.md new file mode 100644 index 00000000000..3e1dacb0ec9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.is_available.md @@ -0,0 +1,25 @@ +## [ 组合替代实现 ]torch.cuda.is_available + +### [torch.cuda.is_available](https://pytorch.org/docs/stable/generated/torch.cuda.is_available.html#torch-cuda-is-available) + +```python +torch.cuda.is_available() +``` + +### [paddle.device.cuda.device_count](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/device_count_cn.html) + +```python +paddle.device.cuda.device_count() +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# torch 写法 +torch.cuda.is_available() + +# paddle 写法 +paddle.device.cuda.device_count() >= 1 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed.md new file mode 100644 index 00000000000..68632e62b1a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed.md @@ -0,0 +1,32 @@ +## [参数不一致]torch.cuda.manual_seed + +### [torch.cuda.manual_seed](https://pytorch.org/docs/stable/generated/torch.cuda.manual_seed.html#torch.cuda.manual_seed) + +```python +torch.cuda.manual_seed(seed) +``` + +### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/seed_cn.html) + +```python +paddle.seed(seed) +``` + +功能一致,返回类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------|----------------------------------------------------| +| seed | seed | 表示设置的的随机种子(int)。 | +| - | 返回值 | PyTorch 无返回值,Paddle 返回 Generator(全局默认 generator 对象)。 | + +### 转写示例 +#### 返回值 +```python +# torch 写法 +torch.cuda.manual_seed(100) + +# paddle 写法 +gen = paddle.seed(100) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed_all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed_all.md new file mode 100644 index 00000000000..2afb6757076 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.manual_seed_all.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.manual_seed_all + +### [torch.cuda.manual_seed_all](https://pytorch.org/docs/2.0/generated/torch.cuda.manual_seed_all.html#torch.cuda.manual_seed_all) + +```python +torch.cuda.manual_seed_all(seed) +``` + +### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/seed_cn.html) + +```python +paddle.seed(seed) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| seed | seed | 表示设置的的随机种子。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_allocated.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_allocated.md new file mode 100644 index 00000000000..042b6adaea7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_allocated.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.max_memory_allocated + +### [torch.cuda.max_memory_allocated](https://pytorch.org/docs/stable/generated/torch.cuda.max_memory_allocated.html#torch.cuda.max_memory_allocated) + +```python +torch.cuda.max_memory_allocated(device) +``` + +### [paddle.device.cuda.max_memory_allocated](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/max_memory_allocated_cn.html) + +```python +paddle.device.cuda.max_memory_allocated(device) +``` + +功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------| +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_reserved.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_reserved.md new file mode 100644 index 00000000000..d57c7be1907 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.max_memory_reserved.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.max_memory_reserved + +### [torch.cuda.max_memory_reserved](https://pytorch.org/docs/stable/generated/torch.cuda.max_memory_reserved.html#torch.cuda.max_memory_reserved) + +```python +torch.cuda.max_memory_reserved(device) +``` + +### [paddle.device.cuda.max_memory_reserved](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/max_memory_reserved_cn.html) + +```python +paddle.device.cuda.max_memory_reserved(device) +``` + +功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------| +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_allocated.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_allocated.md new file mode 100644 index 00000000000..ad8afff485d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_allocated.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.memory_allocated + +### [torch.cuda.memory_allocated](https://pytorch.org/docs/stable/generated/torch.cuda.memory_allocated.html#torch.cuda.memory_allocated) + +```python +torch.cuda.memory_allocated(device) +``` + +### [paddle.device.cuda.memory_allocated](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/memory_allocated_cn.html) + +```python +paddle.device.cuda.memory_allocated(device) +``` + +功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------| +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_reserved.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_reserved.md new file mode 100644 index 00000000000..90b20b29705 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.memory_reserved.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.memory_reserved + +### [torch.cuda.memory_reserved](https://pytorch.org/docs/stable/generated/torch.cuda.memory_reserved.html#torch.cuda.memory_reserved) + +```python +torch.cuda.memory_reserved(device) +``` + +### [paddle.device.cuda.memory_reserved](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/memory_reserved_cn.html) + +```python +paddle.device.cuda.memory_reserved(device) +``` + +功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------| +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_pop.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_pop.md new file mode 100644 index 00000000000..13fe539e65d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_pop.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.cuda.nvtx.range_pop + +### [torch.cuda.nvtx.range_pop](https://pytorch.org/docs/stable/generated/torch.cuda.nvtx.range_pop.html#torch.cuda.nvtx.range_pop) + +```python +torch.cuda.nvtx.range_pop() +``` + +### [paddle.framework.core.nvprof_nvtx_pop](https://github.com/PaddlePaddle/Paddle/blob/645dfb4040a15712cea9ccfed4dcb0655aeeb0ea/paddle/fluid/pybind/pybind.cc#L2468) + +```python +paddle.framework.core.nvprof_nvtx_pop() +``` + +功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_push.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_push.md new file mode 100644 index 00000000000..ba54627f742 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.nvtx.range_push.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.cuda.nvtx.range_push + +### [torch.cuda.nvtx.range_push](https://pytorch.org/docs/stable/generated/torch.cuda.nvtx.range_push.html?highlight=range_push#torch.cuda.nvtx.range_push) + +```python +torch.cuda.nvtx.range_push(msg) +``` + +### [paddle.framework.core.nvprof_nvtx_push](https://github.com/PaddlePaddle/Paddle/blob/645dfb4040a15712cea9ccfed4dcb0655aeeb0ea/paddle/fluid/pybind/pybind.cc#L2465) + +```python +paddle.framework.core.nvprof_nvtx_push(name) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------ | +| msg | name | 关联 range 的 ASCII 消息,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md new file mode 100644 index 00000000000..a5debb826c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_device.md @@ -0,0 +1,20 @@ +## [参数不一致]torch.cuda.set_device + +### [torch.cuda.set_device](https://pytorch.org/docs/stable/generated/torch.cuda.set_device.html#torch.cuda.set_device) + +```python +torch.cuda.set_device(device) +``` + +### [paddle.device.set_device](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/set_device_cn.html) + +```python +paddle.device.set_device(device) +``` + +功能一致,参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |------------------------------------------------| +| device | device | PyTorch 支持 torch.device 或 int。PaddlePaddle 支持 str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_rng_state_all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_rng_state_all.md new file mode 100644 index 00000000000..3dd236ebf54 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_rng_state_all.md @@ -0,0 +1,36 @@ +## [参数不一致]torch.cuda.set_rng_state_all + +### [torch.cuda.set_rng_state_all](https://pytorch.org/docs/stable/generated/torch.cuda.set_rng_state_all.html#torch.cuda.set_rng_state_all) + +```python +torch.cuda.set_rng_state_all(new_states) +``` + +### [paddle.set_rng_state]() + +```python +paddle.set_rng_state(state_list, device='gpu') +``` + +其中 PyTorch 与 Paddle 的参数类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| new_states | state_list | 表示每个设备需要的状态,PyTorch 类型为 torch.ByteTensor 列表,Paddle 类型为 GeneratorState 列表,需要转写。 | +| - | device | 返回随机数生成器状态的设备,Paddle 取值 gpu。 | + +### 转写示例 + +#### 参数类型不同 + +```python +# PyTorch 写法 +x = torch.cuda.get_rng_state_all() +torch.cuda.set_rng_state_all(x) + +# Paddle 写法 +x = paddle.get_rng_state() +paddle.set_rng_state(x, device='gpu') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_stream.md new file mode 100644 index 00000000000..c2ea18bae0a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.set_stream.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.cuda.set_stream + +### [torch.cuda.set_stream](https://pytorch.org/docs/stable/generated/torch.cuda.set_stream.html#torch.cuda.set_stream) + +```python +torch.cuda.set_stream(stream) +``` + +### [paddle.device.set_stream](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/device/set_stream_cn.html#set-stream) + +```python +paddle.device.set_stream(stream=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------- | +| stream | stream | 希望设置的 stream。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.stream.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.stream.md new file mode 100644 index 00000000000..20eb5a8d268 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.stream.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.stream + +### [torch.cuda.stream](https://pytorch.org/docs/stable/generated/torch.cuda.stream.html) + +```python +torch.cuda.stream(stream) +``` + +### [paddle.device.cuda.stream_guard](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/stream_guard_cn.html) + +```python +paddle.device.cuda.stream_guard(stream) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| stream | stream | 指定的 CUDA stream。如果为 None,则不进行 stream 流切换。Paddle 的该 API 目前仅支持动态图模式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md new file mode 100644 index 00000000000..9bd33ebd7d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/cuda/torch.cuda.synchronize.md @@ -0,0 +1,20 @@ +## [参数完全一致]torch.cuda.synchronize + +### [torch.cuda.synchronize](https://pytorch.org/docs/stable/generated/torch.cuda.synchronize.html#torch.cuda.synchronize) + +```python +torch.cuda.synchronize(device) +``` + +### [paddle.device.cuda.synchronize](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/cuda/synchronize_cn.html) + +```python +paddle.device.cuda.synchronize(device) +``` + +功能一致,参数完全一致(PyTorch 参数是 PaddlePaddle 参数子集),具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------| +| device | device | PyTorch 支持 torch.device 和 int。 PaddlePaddle 支持 paddle.CUDAPlace、int 、str。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.ReduceOp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.ReduceOp.md new file mode 100644 index 00000000000..07c0af95f9a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.ReduceOp.md @@ -0,0 +1,28 @@ +## [torch 参数更多]torch.distributed.ReduceOp + +### [torch.distributed.ReduceOp](https://pytorch.org/docs/stable/distributed.html?highlight=torch+distributed+reduceop#torch.distributed.ReduceOp) + +```python +torch.distributed.ReduceOp +``` + +### [paddle.distributed.ReduceOp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/ReduceOp_cn.html) + +```python +paddle.distributed.ReduceOp +``` + +两者功能一致。 + +其中,规约操作对应如下: + +| torch | paddle | +| ---- | ---- | +| SUM | SUM | +| PRODUCT | PROD | +| MIN | MIN | +| MAX | MAX | +| BAND | - | +| BOR | - | +| BXOR | - | +| PREMUL_SUM | - | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather.md new file mode 100644 index 00000000000..1d996856a17 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather.md @@ -0,0 +1,24 @@ +## [参数不一致]torch.distributed.all_gather + +### [torch.distributed.all_gather](https://pytorch.org/docs/stable/distributed.html#torch.distributed.all_gather) + +```python +torch.distributed.all_gather(tensor_list, tensor, group=None, async_op=False) +``` + +### [paddle.distributed.all_gather](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/all_gather_cn.html) + +```python +paddle.distributed.all_gather(tensor_list, tensor, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | --------------------------------------------------------------- | +| tensor_list | tensor_list | 操作的输出 Tensor 列表。 | +| tensor | tensor | 操作的输入 Tensor。 | +| group | group | 工作的进程组编号。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md new file mode 100644 index 00000000000..d3437477503 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_gather_object.md @@ -0,0 +1,23 @@ +## [参数完全一致]torch.distributed.all_gather_object + +### [torch.distributed.all_gather_object](https://pytorch.org/docs/stable/distributed.html?highlight=all_gather_object#torch.distributed.all_gather_object) + +```python +torch.distributed.all_gather_object(object_list, obj, group=None) +``` + +### [paddle.distributed.all_gather_object](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distributed/all_gather_object_cn.html) + +```python +paddle.distributed.all_gather_object(object_list, obj, group=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------- | +| object_list | object_list | 表示用于保存聚合结果的列表。 | +| obj | obj | 表示待聚合的对象。 | +| group | group | 表示执行该操作的进程组实例。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_reduce.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_reduce.md new file mode 100644 index 00000000000..254719c11bf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_reduce.md @@ -0,0 +1,24 @@ +## [参数不一致]torch.distributed.all_reduce + +### [torch.distributed.all_reduce](https://pytorch.org/docs/stable/distributed.html#torch.distributed.all_reduce) + +```python +torch.distributed.all_reduce(tensor, op=, group=None, async_op=False) +``` + +### [paddle.distributed.all_reduce](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/all_reduce_cn.html) + +```python +paddle.distributed.all_reduce(tensor, op=ReduceOp.SUM, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------- | +| tensor | tensor | 操作的输入 Tensor。 | +| op | op | 归约的具体操作。 | +| group | group | 工作的进程组编号。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_to_all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_to_all.md new file mode 100644 index 00000000000..7af27ab5dab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.all_to_all.md @@ -0,0 +1,24 @@ +## [参数不一致]torch.distributed.all_to_all + +### [torch.distributed.all_to_all](https://pytorch.org/docs/stable/distributed.html#torch.distributed.all_to_all) + +```python +torch.distributed.all_to_all(output_tensor_list, input_tensor_list, group=None, async_op=False) +``` + +### [paddle.distributed.alltoall](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/alltoall_cn.html) + +```python +paddle.distributed.alltoall(in_tensor_list, out_tensor_list, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | --------------- | --------------------------------------------------------------- | +| output_tensor_list | out_tensor_list | 包含所有输出 Tensors 的一个列表,仅参数名不一致。 | +| input_tensor_list | in_tensor_list | 包含所有输入 Tensors 的一个列表,仅参数名不一致。 | +| group | group | new_group 返回的 Group 实例,或者设置为 None 表示默认地全局组。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.barrier.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.barrier.md new file mode 100644 index 00000000000..0141858022b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.barrier.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ] torch.distributed.barrier +### [torch.distributed.barrier](https://pytorch.org/docs/stable/distributed.html?highlight=barrier#torch.distributed.barrier) + +```python +torch.distributed.barrier(group=None, async_op=False, device_ids=None) +``` + +### [paddle.distributed.barrier](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/barrier_cn.html) + +```python +paddle.distributed.barrier(group=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------| +| group | group | 进程组编号。 | +| async_op | - | 是否是异步算子,Paddle 无此参数,暂无转写方式。 | +| device_ids | - | 设备 id,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast.md new file mode 100644 index 00000000000..28f62730a64 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast.md @@ -0,0 +1,24 @@ +## [参数不一致]torch.distributed.broadcast + +### [torch.distributed.broadcast](https://pytorch.org/docs/stable/distributed.html#torch.distributed.broadcast) + +```python +torch.distributed.broadcast(tensor, src, group=None, async_op=False) +``` + +### [paddle.distributed.broadcast](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/broadcast_cn.html) + +```python +paddle.distributed.broadcast(tensor, src, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | ------------------------------------------------------------------------------------------------------ | +| tensor | tensor | 如果当前进程编号是源,那么这个 Tensor 变量将被发送给其他进程,否则这个 Tensor 将接收源发送过来的数据。 | +| src | src | 发送源的进程编号。 | +| group | group | 工作的进程组编号。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast_object_list.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast_object_list.md new file mode 100644 index 00000000000..33dbb6b7421 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.broadcast_object_list.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributed.broadcast_object_list + +### [torch.distributed.broadcast_object_list](https://pytorch.org/docs/stable/distributed.html?highlight=broadcast_object_list#torch.distributed.broadcast_object_list) + +```python +torch.distributed.broadcast_object_list(object_list, src=0, group=None, device=None) +``` + +### [paddle.distributed.broadcast_object_list](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distributed/broadcast_object_list_cn.html) + +```python +paddle.distributed.broadcast_object_list(object_list, src, group=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| object_list | object_list | 表示在目标进程上为待广播的 object 列表,在其他进程上为用于接收广播结果的 object 列表。 | +| src | src | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| device | - | 表示如果不为空,则对象在被广播之前将被序列化并转换为 Tensor 后移动到设备上,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.gather.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.gather.md new file mode 100644 index 00000000000..43b0c0e83b8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.gather.md @@ -0,0 +1,25 @@ +## [参数不一致]torch.distributed.gather + +### [torch.distributed.gather](https://pytorch.org/docs/stable/distributed.html#torch.distributed.gather) + +```python +torch.distributed.gather(tensor, gather_list=None, dst=0, group=None, async_op=False) +``` + +### [paddle.distributed.gather](https://github.com/PaddlePaddle/Paddle/blob/c8ccc9b154632ef41ade1b8e97b87d54fde7e8f8/python/paddle/distributed/communication/gather.py#L20C71-L20C71) + +```python +paddle.distributed.gather(tensor, gather_list=None, dst=0, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | --------------------------------------------------------------- | +| tensor | tensor | 操作的输入 Tensor。 | +| gather_list | gather_list | 操作的输出 Tensor 列表。 | +| dst | dst | 表示目标进程的 rank。 | +| group | group | 工作的进程组编号。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_backend.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_backend.md new file mode 100644 index 00000000000..18074098065 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_backend.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.distributed.get_backend + +### [torch.distributed.get_backend](https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_backend) + +```python +torch.distributed.get_backend(group=None) +``` + +### [paddle.distributed.get_backend](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/get_backend_cn.html#get-backend) + +```python +paddle.distributed.get_backend(group=None) +``` + +其中功能一致, 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---- | +| group | group | 指定的通信组。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_rank.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_rank.md new file mode 100644 index 00000000000..30d0a8782f4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_rank.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.distributed.get_rank + +### [torch.distributed.get_rank](https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_rank) + +```python +torch.distributed.get_rank(group=None) +``` + +### [paddle.distributed.get_rank](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/get_rank_cn.html) + +```python +paddle.distributed.get_rank(group=None) +``` + +其中功能一致, 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------- | +| group | group | 进程组。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_world_size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_world_size.md new file mode 100644 index 00000000000..edf551e9cf7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.get_world_size.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.distributed.get_world_size + +### [torch.distributed.get_world_size](https://pytorch.org/docs/stable/distributed.html#torch.distributed.get_world_size) + +```python +torch.distributed.get_world_size(group=None) +``` + +### [paddle.distributed.get_world_size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/get_world_size_cn.html) + +```python +paddle.distributed.get_world_size(group=None) +``` + +其中功能一致, 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------- | +| group | group | 进程组。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.init_process_group.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.init_process_group.md new file mode 100644 index 00000000000..4acdd13c9f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.init_process_group.md @@ -0,0 +1,27 @@ +## [ torch 参数更多 ] torch.distributed.init_process_group +### [torch.distributed.init_process_group](https://pytorch.org/docs/stable/distributed.html?highlight=init_process#torch.distributed.init_process_group) + +```python +torch.distributed.init_process_group(backend='nccl', init_method=None, timeout=datetime.timedelta(seconds=1800), world_size=-1, rank=-1, store=None, group_name='', pg_options=None) +``` + +### [paddle.distributed.init_parallel_env](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/init_parallel_env_cn.html) + +```python +paddle.distributed.init_parallel_env() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| backend | - | backend 配置,paddle 无此参数,暂无转写方式。 | +| init_method | - | 初始化方法,paddle 无此参数,暂无转写方式。 | +| timeout | - | 超时配置,paddle 无此参数,暂无转写方式。 | +| world_size | - | 进程数量,paddle 无此参数,暂无转写方式。 | +| rank | - | 当前进程所在的 gpu,paddle 无此参数,暂无转写方式。 | +| store | - | 信息交换的配置,paddle 无此参数,暂无转写方式。 | +| group_name | - | 组名,paddle 无此参数,暂无转写方式。 | +| pg_options | - | 进程组配置,paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.irecv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.irecv.md new file mode 100644 index 00000000000..2ccfb96bf0a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.irecv.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributed.irecv + +### [torch.distributed.irecv](https://pytorch.org/docs/stable/distributed.html?highlight=send#torch.distributed.irecv) + +```python +torch.distributed.irecv(tensor, src=None, group=None, tag=0) +``` + +### [paddle.distributed.irecv](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distributed/irecv_cn.html) + +```python +paddle.distributed.irecv(tensor, src=0, group=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| tensor | tensor | 表示用于接收数据的 Tensor。 | +| src | src | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.isend.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.isend.md new file mode 100644 index 00000000000..e5b5cbcabac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.isend.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributed.isend + +### [torch.distributed.isend](https://pytorch.org/docs/stable/distributed.html#torch.distributed.isend) + +```python +torch.distributed.isend(tensor, dst, group=None, tag=0) +``` + +### [paddle.distributed.isend](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/distributed/isend_cn.html) + +```python +paddle.distributed.isend(tensor, dst=0, group=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| tensor | tensor | 表示待发送的 Tensor。 | +| dst | dst | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.new_group.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.new_group.md new file mode 100644 index 00000000000..768cf5189e2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.new_group.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributed.new_group + +### [torch.distributed.new_group](https://pytorch.org/docs/stable/distributed.html#torch.distributed.new_group) + +```python +torch.distributed.new_group(ranks=None, timeout=datetime.timedelta(seconds=1800), backend=None, pg_options=None) +``` + +### [paddle.distributed.new_group](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/new_group_cn.html) + +```python +paddle.distributed.new_group(ranks=None, backend=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ----------------------------------------- | +| ranks | ranks | 用于新建通信组的全局 rank 列表。 | +| timeout | - | 进程组执行超时时间,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| backend | backend | 用于新建通信组的后端支持。 | +| pg_options | - | 进程组选项,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.recv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.recv.md new file mode 100644 index 00000000000..a629bf3263c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.recv.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.distributed.recv + +### [torch.distributed.recv](https://pytorch.org/docs/stable/distributed.html#torch.distributed.recv) + +```python +torch.distributed.recv(tensor, src=None, group=None, tag=0) +``` + +### [paddle.distributed.recv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/recv_cn.html) + +```python +paddle.distributed.recv(tensor, src=0, group=None, sync_op=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| tensor | tensor | 表示用于接收数据的 Tensor。 | +| src | src | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | +| - | sync_op | 表示该操作是否为同步操作,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce.md new file mode 100644 index 00000000000..41f73b4c727 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce.md @@ -0,0 +1,36 @@ +## [参数不一致]torch.distributed.reduce + +### [torch.distributed.reduce](https://pytorch.org/docs/stable/distributed.html#torch.distributed.reduce) + +```python +torch.distributed.reduce(tensor, dst, op=, group=None, async_op=False) +``` + +### [paddle.distributed.reduce](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/reduce_cn.html) + +```python +paddle.distributed.reduce(tensor, dst, op=ReduceOp.SUM, group=None, sync_op=True) +``` + +两者功能一致但参数不一致,其中 PyTorch 的 async_op 与 Paddle 的 sync_op 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------- | +| tensor | tensor | 表示操作的输入 Tensor。 | +| dst | dst | 表示目标进程的 rank。 | +| op | op | 表示归约的具体操作。 | +| group | group | 表示执行该操作的进程组实例。 | +| async_op | sync_op | 表示是否异步或同步操作,两者功能相反,需要转写。 | + + +### 转写示例 +#### async_op:表示该操作是否为异步操作 +```python +# PyTorch 写法 +torch.distributed.reduce(tensor=tensor, dst=dst, op=, group=None, async_op=False) + +# Paddle 写法 +paddle.distributed.reduce(tensor=tensor, dst=dst, op=ReduceOp.SUM, group=None, sync_op=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce_scatter.md new file mode 100644 index 00000000000..c935474d9f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.reduce_scatter.md @@ -0,0 +1,37 @@ +## [参数不一致]torch.distributed.reduce_scatter + +### [torch.distributed.reduce_scatter](https://pytorch.org/docs/stable/distributed.html#torch.distributed.reduce_scatter) + +```python +torch.distributed.reduce_scatter(output, input_list, op=, group=None, async_op=False) +``` + +### [paddle.distributed.reduce_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/reduce_scatter_cn.html#reduce-scatter) + +```python +paddle.distributed.reduce_scatter(tensor, tensor_list, op=ReduceOp.SUM, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ---------------------------------------------------------------------- | +| output | tensor | 用于接收数据的 tensor,仅参数名不一致。 | +| input_list | tensor_list | 将被规约和分发的 tensor 列表,仅参数名不一致。 | +| op | op | 归约的操作类型。 | +| group | group | 执行该操作的进程组实例。 | +| async_op | sync_op | 该操作是否为异步或同步操作,PyTorch 和 Paddle 取值相反,需要转写。 | + +### 转写示例 + +#### async_op 参数:该操作是否为异步或同步操作 + +```python +# PyTorch 写法: +torch.distributed.reduce_scatter(data1, [data1, data2], async_op=False) + +# Paddle 写法: +paddle.distributed.reduce_scatter(data1, [data1, data2], sync_op=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.get_worker_info.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.get_worker_info.md new file mode 100644 index 00000000000..7a863de43c3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.get_worker_info.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.distributed.rpc.get_worker_info + +### [torch.distributed.rpc.get_worker_info](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.get_worker_info) + +```python +torch.distributed.rpc.get_worker_info(worker_name=None) +``` + +### [paddle.distributed.rpc.get_worker_info](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/get_worker_info_cn.html#cn-api-distributed-rpc-get-worker-info) + +```python +paddle.distributed.rpc.get_worker_info(name) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ------------------------------- | +| worker_name | name | worker 的名字,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.init_rpc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.init_rpc.md new file mode 100644 index 00000000000..cdb723a39ed --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.init_rpc.md @@ -0,0 +1,26 @@ +## [ torch 参数更多 ]torch.distributed.rpc.init_rpc + +### [torch.distributed.rpc.init\_rpc](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.init_rpc) + +```python +torch.distributed.rpc.init_rpc(name, backend=None, rank=-1, world_size=None, rpc_backend_options=None) +``` + +### [paddle.distributed.rpc.init\_rpc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/init_rpc_cn.html#init-rpc) + +```python +paddle.distributed.rpc.init_rpc(name, rank=None, world_size=None, master_endpoint=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------- | ------------------- | -- | +| name | name | worker 名字。 | +| backend | - | RPC 后台实现类型,Paddle 无此参数,暂无转写方式。 | +| rank | rank | worker 的 ID,仅参数默认值不同。 | +| world_size | world_size | workers 的数量。 | +| rpc_backend_options | - | 传递给 worker 创建时的配置项,Paddle 无此参数,暂无转写方式。 | +| - | master_endpoint | master 的 IP 地址,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md new file mode 100644 index 00000000000..87e18d68144 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_async.md @@ -0,0 +1,25 @@ +## [仅参数名不一致]torch.distributed.rpc.rpc_async + +### [torch.distributed.rpc.rpc_async](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.rpc_async) + +```python +torch.distributed.rpc.rpc_async(to, func, args=None, kwargs=None, timeout=- 1.0) +``` + +### [paddle.distributed.rpc.rpc_async](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/rpc_async_cn.html#rpc-async) + +```python +paddle.distributed.rpc.rpc_async(to, fn, args=None, kwargs=None, timeout=- 1) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| to | to | 目标 worker 的名字。 | +| func | fn | 一个可调用的函数,仅参数名不一致。 | +| args | args | 函数 fn 的参数。 | +| kwargs | kwargs | 函数 fn 的字典参数。 | +| timeout | timeout | RPC 调用的超时时间。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md new file mode 100644 index 00000000000..ee70c6c2a49 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.rpc_sync.md @@ -0,0 +1,25 @@ +## [仅参数名不一致]torch.distributed.rpc.rpc_sync + +### [torch.distributed.rpc.rpc_sync](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.rpc_sync) + +```python +torch.distributed.rpc.rpc_sync(to, func, args=None, kwargs=None, timeout=- 1.0) +``` + +### [paddle.distributed.rpc.rpc_sync](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/rpc_sync_cn.html) + +```python +paddle.distributed.rpc.rpc_sync(to, fn, args=None, kwargs=None, timeout=- 1) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| to | to | 目标 worker 的名字。 | +| func | fn | 一个可调用的函数,仅参数名不一致。 | +| args | args | 函数 fn 的参数。 | +| kwargs | kwargs | 函数 fn 的字典参数。 | +| timeout | timeout | RPC 调用的超时时间。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.shutdown.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.shutdown.md new file mode 100644 index 00000000000..4fbbcf9d2c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.rpc.shutdown.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.distributed.rpc.shutdown + +### [torch.distributed.rpc.shutdown](https://pytorch.org/docs/stable/rpc.html#torch.distributed.rpc.shutdown) + +```python +torch.distributed.rpc.shutdown(graceful=True, timeout=0) +``` + +### [paddle.distributed.rpc.shutdown](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/rpc/shutdown_cn.html) + +```python +paddle.distributed.rpc.shutdown() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------- | +| graceful | - | 是否优雅关闭,Paddle 无此参数,暂无转写方式。 | +| timeout | - | 操作超时时间,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter.md new file mode 100644 index 00000000000..870f61527cd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter.md @@ -0,0 +1,25 @@ +## [参数不一致]torch.distributed.scatter + +### [torch.distributed.scatter](https://pytorch.org/docs/stable/distributed.html#torch.distributed.scatter) + +```python +torch.distributed.scatter(tensor, scatter_list=None, src=0, group=None, async_op=False) +``` + +### [paddle.distributed.scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/scatter_cn.html) + +```python +paddle.distributed.scatter(tensor, tensor_list=None, src=0, group=None, sync_op=True) +``` + +其中 PyTorch 和 Paddle 功能一致,参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | --------------------------------------------------------------- | +| tensor | tensor | 操作的输出 Tensor。 | +| scatter_list | tensor_list | 操作的输入 Tensor 列表,仅参数名不一致。 | +| src | src | 操作的源进程号。 | +| group | group | 工作的进程组编号。 | +| async_op | sync_op | torch 为是否异步操作,Paddle 为是否同步操作,转写方式取反即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter_object_list.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter_object_list.md new file mode 100644 index 00000000000..2fd1ffc3413 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.scatter_object_list.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.distributed.scatter_object_list + +### [torch.distributed.scatter_object_list](https://pytorch.org/docs/stable/distributed.html#torch.distributed.scatter_object_list) + +```python +torch.distributed.scatter_object_list(scatter_object_output_list, scatter_object_input_list, src=0, group=None) +``` + +### [paddle.distributed.scatter_object_list](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/scatter_object_list_cn.html#scatter-object-list) + +```python +paddle.distributed.scatter_object_list(out_object_list, in_object_list, src=0, group=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------------------- | --------------- | -------------------------------------------- | +| scatter_object_output_list | out_object_list | 用于接收数据的 object 列表,仅参数名不一致。 | +| scatter_object_input_list | in_object_list | 将被分发的 object 列表,仅参数名不一致。 | +| src | src | 目标进程的 rank。 | +| group | group | 执行该操作的进程组实例。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.send.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.send.md new file mode 100644 index 00000000000..1b2f69ed162 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributed/torch.distributed.send.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.distributed.send + +### [torch.distributed.send](https://pytorch.org/docs/stable/distributed.html#torch.distributed.send) + +```python +torch.distributed.send(tensor, dst, group=None, tag=0) +``` + +### [paddle.distributed.send](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/send_cn.html) + +```python +paddle.distributed.send(tensor, dst=0, group=None, sync_op=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | --------------- | ----------------------------------------------------------------- | +| tensor | tensor | 表示待发送的 Tensor。 | +| dst | dst | 表示目标进程的 rank。 | +| group | group | 表示执行该操作的进程组实例。 | +| tag | - | 表示匹配接收标签,Paddle 无此参数,暂无转写方式。 | +| - | sync_op | 表示该操作是否为同步操作,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.log_prob.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.log_prob.md new file mode 100644 index 00000000000..c8921c03619 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.log_prob.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.distributions.Distribution.log_prob + +### [torch.distributions.Distribution.log\_prob](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.log_prob) + +```python +torch.distributions.Distribution.log_prob(value) +``` + +### [paddle.distributions.Distribution.log\_prob](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.log_prob) + +```python +paddle.distributions.Distribution.log_prob(value) +``` + + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------ | +| value | value | 输入 Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.rsample.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.rsample.md new file mode 100644 index 00000000000..e9b67fbdaf7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.rsample.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.distributions.Distribution.rsample + +### [torch.distributions.Distribution.rsample](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.rsample) + +```python +torch.distributions.Distribution.rsample(sample_shape=torch.Size([])) +``` + +### [paddle.distribution.Distribution.rsample](https://github.com/PaddlePaddle/Paddle/blob/2bbd6f84c1db3e7401732869ee50aef2d9c97bdc/python/paddle/distribution/distribution.py#L96) + +```python +paddle.distribution.Distribution.rsample(shape=()) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ---- | +| sample_shape | shape | 重参数化的样本形状,仅参数名不同。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.sample.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.sample.md new file mode 100644 index 00000000000..7d821d25dca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.Distribution.sample.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.distributions.Distribution.sample + +### [torch.distributions.Distribution.sample](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution.sample) + +```python +torch.distributions.Distribution.sample(sample_shape=torch.Size([])) +``` + +### [paddle.distribution.Distribution.sample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Distribution_cn.html#sample) + +```python +paddle.distribution.Distribution.sample(shape=()) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -- | +| sample_shape | shape | 采样形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.bernoulli.Bernoulli.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.bernoulli.Bernoulli.md new file mode 100644 index 00000000000..044b1a9ea73 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.bernoulli.Bernoulli.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.bernoulli.Bernoulli + +### [torch.distributions.bernoulli.Bernoulli](https://pytorch.org/docs/stable/distributions.html#torch.distributions.bernoulli.Bernoulli) + +```python +torch.distributions.bernoulli.Bernoulli(probs=None, logits=None, validate_args=None) +``` + +### [paddle.distribution.Bernoulli](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Bernoulli_cn.html#bernoulli) + +```python +paddle.distribution.Bernoulli(probs, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| probs | probs | 伯努利分布的概率输入。 | +| logits | - | 采样 1 的 log-odds,Paddle 无此参数,暂无转写方式。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.beta.Beta.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.beta.Beta.md new file mode 100644 index 00000000000..2bdfe7f7753 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.beta.Beta.md @@ -0,0 +1,23 @@ +## [torch 参数更多 ]torch.distributions.beta.Beta + +### [torch.distributions.beta.Beta](https://pytorch.org/docs/stable/distributions.html#torch.distributions.beta.Beta) + +```python +torch.distributions.beta.Beta(concentration1, concentration0, validate_args=None) +``` + +### [paddle.distribution.Beta](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Beta_cn.html#beta) + +```python +paddle.distribution.Beta(alpha, beta) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| concentration1 | alpha | 表示输入的参数 ,仅参数名不一致。 | +| concentration0 | beta | 表示输入的参数,仅参数名不一致。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.categorical.Categorical.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.categorical.Categorical.md new file mode 100644 index 00000000000..1897c4eeb85 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.categorical.Categorical.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.categorical.Categorical + +### [torch.distributions.categorical.Categorical](https://pytorch.org/docs/stable/distributions.html#torch.distributions.categorical.Categorical) + +```python +torch.distributions.categorical.Categorical(probs=None, logits=None, validate_args=None) +``` + +### [paddle.distribution.Categorical](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Categorical_cn.html) + +```python +paddle.distribution.Categorical(logits, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | --------------------------------------------- | +| probs | - | 事件概率,Paddle 无此参数,暂无转写方式。 | +| logits | logits | 类别分布对应的 logits。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.cauchy.Cauchy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.cauchy.Cauchy.md new file mode 100644 index 00000000000..a20b12d83ed --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.cauchy.Cauchy.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.cauchy.Cauchy + +### [torch.distributions.cauchy.Cauchy](https://pytorch.org/docs/stable/distributions.html#torch.distributions.cauchy.Cauchy) + +```python +torch.distributions.cauchy.Cauchy(loc, scale, validate_args=None) +``` + +### [paddle.distribution.Cauchy](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Cauchy_cn.html) + +```python +paddle.distribution.Cauchy(loc, scale, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| loc | loc | 定义分布峰值位置的位置参数。 | +| scale | scale | 最大值一半处的一半宽度的尺度参数。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.dirichlet.Dirichlet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.dirichlet.Dirichlet.md new file mode 100644 index 00000000000..c03117891ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.dirichlet.Dirichlet.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.distributions.dirichlet.Dirichlet + +### [torch.distributions.dirichlet.Dirichlet](https://pytorch.org/docs/stable/distributions.html#torch.distributions.dirichlet.Dirichlet) + +```python +torch.distributions.dirichlet.Dirichlet(concentration, validate_args=None) +``` + +### [paddle.distribution.Dirichlet](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Dirichlet_cn.html) + +```python +paddle.distribution.Dirichlet(concentration) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | --------------------------------------------- | +| concentration | concentration | 浓度参数,即公式中 α 参数。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.distribution.Distribution.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.distribution.Distribution.md new file mode 100644 index 00000000000..6ff88207df1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.distribution.Distribution.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.distribution.Distribution + +### [torch.distributions.distribution.Distribution](https://pytorch.org/docs/stable/distributions.html#torch.distributions.distribution.Distribution) + +```python +torch.distributions.distribution.Distribution(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None) +``` + +### [paddle.distribution.Distribution](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Distribution_cn.html) + +```python +paddle.distribution.Distribution(batch_shape, event_shape) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | --------------------------------------------- | +| batch_shape | batch_shape | 概率分布参数批量形状。 | +| event_shape | event_shape | 多元概率分布维数形状。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.exp_family.ExponentialFamily.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.exp_family.ExponentialFamily.md new file mode 100644 index 00000000000..6918c91f1ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.exp_family.ExponentialFamily.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.exp_family.ExponentialFamily + +### [torch.distributions.exp_family.ExponentialFamily](https://pytorch.org/docs/stable/distributions.html#torch.distributions.exp_family.ExponentialFamily) + +```python +torch.distributions.exp_family.ExponentialFamily(batch_shape=torch.Size([]), event_shape=torch.Size([]), validate_args=None) +``` + +### [paddle.distribution.ExponentialFamily](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/ExponentialFamily_cn.html) + +```python +paddle.distribution.ExponentialFamily(batch_shape, event_shape) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | --------------------------------------------- | +| batch_shape | batch_shape, | 概率分布参数批量形状。 | +| event_shape | event_shape | 多元概率分布维数形状。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.geometric.Geometric.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.geometric.Geometric.md new file mode 100644 index 00000000000..4af44e87dde --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.geometric.Geometric.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.geometric.Geometric + +### [torch.distributions.geometric.Geometric](https://pytorch.org/docs/stable/distributions.html#torch.distributions.geometric.Geometric) + +```python +torch.distributions.geometric.Geometric(probs=None, logits=None, validate_args=None) +``` + +### [paddle.distribution.Geometric](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Geometric_cn.html#geometric) + +```python +paddle.distribution.Geometric(probs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| probs | probs | 几何分布成功概率参数。 | +| logits | - | 采样 1 的 log-odds,Paddle 无此参数,暂无转写方式。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.gumbel.Gumbel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.gumbel.Gumbel.md new file mode 100644 index 00000000000..f28c4fcf15b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.gumbel.Gumbel.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.gumbel.Gumbel + +### [torch.distributions.gumbel.Gumbel](https://pytorch.org/docs/stable/distributions.html#torch.distributions.gumbel.Gumbel) + +```python +torch.distributions.gumbel.Gumbel(loc, scale, validate_args=None) +``` + +### [paddle.distribution.Gumbel](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Gumbel_cn.html#gumbel) + +```python +paddle.distribution.Gumbel(loc, scale) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| loc | loc | 耿贝尔分布位置参数。 | +| scale | scale | 耿贝尔分布尺度参数。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.independent.Independent.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.independent.Independent.md new file mode 100644 index 00000000000..19bca1212ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.independent.Independent.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.independent.Independent + +### [torch.distributions.independent.Independent](https://pytorch.org/docs/stable/distributions.html#torch.distributions.independent.Independent) + +```python +torch.distributions.independent.Independent(base_distribution, reinterpreted_batch_ndims, validate_args=None) +``` + +### [paddle.distribution.Independent](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Independent_cn.html) + +```python +paddle.distribution.Independent(base, reinterpreted_batch_rank) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------------- | ------------------------ | ------------------------------------------------ | +| base_distribution | base | 基础分布,仅参数名不一致。 | +| reinterpreted_batch_ndims | reinterpreted_batch_rank | 用于转换为事件维度的批维度数量,仅参数名不一致。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.kl_divergence.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.kl_divergence.md new file mode 100644 index 00000000000..cfed77b7d36 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.kl_divergence.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.distributions.kl.kl_divergence + +### [torch.distributions.kl.kl_divergence](https://pytorch.org/docs/stable/distributions.html?highlight=torch+distributions+kl+kl_divergence#torch.distributions.kl.kl_divergence) + +```python +torch.distributions.kl.kl_divergence(p, q) +``` + +### [paddle.distribution.kl_divergence](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/kl_divergence_cn.html) + +```python +paddle.distribution.kl_divergence(p, q) +``` + +功能一致,参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| p | p | 概率分布实例,继承于 Distribution 基类。| +| q | q | 概率分布实例,继承于 Distribution 基类。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.register_kl.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.register_kl.md new file mode 100644 index 00000000000..a82b2c0c179 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.kl.register_kl.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.distributions.kl.register_kl + +### [torch.distributions.kl.register_kl](https://pytorch.org/docs/stable/distributions.html?highlight=register_kl#torch.distributions.kl.register_kl) + +```python +torch.distributions.kl.register_kl(type_p, type_q) +``` + +### [paddle.distribution.register_kl](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/register_kl_cn.html) + +```python +paddle.distribution.register_kl(cls_p, cls_q) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| type_p | cls_p | 实例 p 的分布类型,继承于 Distribution 基类,仅参数名不一致。 | +| type_q | cls_q | 实例 q 的分布类型,继承于 Distribution 基类,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.laplace.Laplace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.laplace.Laplace.md new file mode 100644 index 00000000000..8ac93dfb90c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.laplace.Laplace.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.laplace.Laplace + +### [torch.distributions.laplace.Laplace](https://pytorch.org/docs/stable/distributions.html#torch.distributions.laplace.Laplace) + +```python +torch.distributions.laplace.Laplace(loc, scale, validate_args=None) +``` + +### [paddle.distribution.Laplace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Laplace_cn.html#laplace) + +```python +paddle.distribution.Laplace(loc, scale) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| loc | loc | 拉普拉斯分布位置参数。 | +| scale | scale | 拉普拉斯分布尺度参数。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.log_normal.LogNormal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.log_normal.LogNormal.md new file mode 100644 index 00000000000..799bc63f94f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.log_normal.LogNormal.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.log_normal.LogNormal + +### [torch.distributions.log_normal.LogNormal](https://pytorch.org/docs/stable/distributions.html#torch.distributions.log_normal.LogNormal) + +```python +torch.distributions.log_normal.LogNormal(loc, scale, validate_args=None) +``` + +### [paddle.distribution.LogNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/LogNormal_cn.html#lognormal) + +```python +paddle.distribution.LogNormal(loc, scale, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ----------------------------------------------------------------------- | +| loc | loc | 正态分布平均值。 | +| scale | scale | 正态分布标准差。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.multinomial.Multinomial.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.multinomial.Multinomial.md new file mode 100644 index 00000000000..d8b2bb88768 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.multinomial.Multinomial.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.distributions.multinomial.Multinomial + +### [torch.distributions.multinomial.Multinomial](https://pytorch.org/docs/stable/distributions.html#torch.distributions.multinomial.Multinomial) + +```python +torch.distributions.multinomial.Multinomial(total_count=1, probs=None, logits=None, validate_args=None) +``` + +### [paddle.distribution.Multinomial](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Multinomial_cn.html) + +```python +paddle.distribution.Multinomial(total_count, probs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ---------------------------------------------- | +| total_count | total_count | 实验次数。 | +| probs | probs | 每个类别发生的概率。 | +| logits | - | 事件 log 概率,Paddle 无此参数,暂无转写方式。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.normal.Normal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.normal.Normal.md new file mode 100644 index 00000000000..b2e5afcf188 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.normal.Normal.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.normal.Normal + +### [torch.distributions.normal.Normal](https://pytorch.org/docs/stable/distributions.html#torch.distributions.normal.Normal) + +```python +torch.distributions.normal.Normal(loc, scale, validate_args=None) +``` + +### [paddle.distribution.Normal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Normal_cn.html) + +```python +paddle.distribution.Normal(loc, scale, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | --------------------------------------------- | +| loc | loc | 正态分布平均值。 | +| scale | scale | 正态分布标准差。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transformed_distribution.TransformedDistribution.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transformed_distribution.TransformedDistribution.md new file mode 100644 index 00000000000..3d5396a7db3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transformed_distribution.TransformedDistribution.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.transformed_distribution.TransformedDistribution + +### [torch.distributions.transformed_distribution.TransformedDistribution](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transformed_distribution.TransformedDistribution) + +```python +torch.distributions.transformed_distribution.TransformedDistribution(base_distribution, transforms, validate_args=None) +``` + +### [paddle.distribution.TransformedDistribution](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/TransformedDistribution_cn.html#transformeddistribution) + +```python +paddle.distribution.TransformedDistribution(base, transforms) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------- | ------------ | ----------------------------------------------------------------------- | +| base_distribution | base | 基础分布,仅参数名不一致。 | +| transforms | transforms | 变换序列。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AbsTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AbsTransform.md new file mode 100644 index 00000000000..955e72308ec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AbsTransform.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.distributions.transforms.AbsTransform + +### [torch.distributions.transforms.AbsTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.AbsTransform) + +```python +torch.distributions.transforms.AbsTransform(cache_size=0) +``` + +### [paddle.distribution.AbsTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/AbsTransform_cn.html#paddle.distribution.AbsTransform) + +```python +paddle.distribution.AbsTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AffineTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AffineTransform.md new file mode 100644 index 00000000000..eab714833fd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.AffineTransform.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.distributions.transforms.AffineTransform + +### [torch.distributions.transforms.AffineTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.AffineTransform) + +```python +torch.distributions.transforms.AffineTransform(loc, scale, event_dim=0, cache_size=0) +``` + +### [paddle.distribution.AffineTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/AffineTransform_cn.html#affinetransform) + +```python +paddle.distribution.AffineTransform(loc, scale) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| loc | loc | 偏置参数。 | +| scale | scale | 缩放参数。 | +| event_dim | - | event_shape 可选尺寸。对于单随机变量为 0,对于向量分布为 1,对于矩阵分布为 2。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ComposeTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ComposeTransform.md new file mode 100644 index 00000000000..39ee6671344 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ComposeTransform.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.distributions.transforms.ComposeTransform + +### [torch.distributions.transforms.ComposeTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.ComposeTransform) + +```python +torch.distributions.transforms.ComposeTransform(parts, cache_size=0) +``` + +### [paddle.distribution.ChainTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/ChainTransform_cn.html) + +```python +paddle.distribution.ChainTransform(transforms) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -------------------------------------------------------------------------- | +| parts | transforms | 输入的变换序列,仅参数名不一致。 | +| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ExpTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ExpTransform.md new file mode 100644 index 00000000000..da1dfed5aca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ExpTransform.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.distributions.transforms.ExpTransform + +### [torch.distributions.transforms.ExpTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.ExpTransform) + +```python +torch.distributions.transforms.ExpTransform(cache_size=0) +``` + +### [paddle.distribution.ExpTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/ExpTransform_cn.html#exptransform) + +```python +paddle.distribution.ExpTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.IndependentTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.IndependentTransform.md new file mode 100644 index 00000000000..02b07625de7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.IndependentTransform.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ]torch.distributions.transforms.IndependentTransform + +### [torch.distributions.transforms.IndependentTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.IndependentTransform) + +```python +torch.distributions.transforms.IndependentTransform(base_transform, reinterpreted_batch_ndims, cache_size=0) +``` + +### [paddle.distribution.IndependentTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/IndependentTransform_cn.html#independenttransform) + +```python +paddle.distribution.IndependentTransform(base, reinterpreted_batch_rank) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------------- | ------------------------ | ------------------------ | +| base_transform | base | 基础变换,仅参数名不一致。 | +| reinterpreted_batch_ndims | reinterpreted_batch_rank | 被扩展为事件维度的最右侧批维度数量,需大于 0,仅参数名不一致。 | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.PowerTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.PowerTransform.md new file mode 100644 index 00000000000..00e3ffc8553 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.PowerTransform.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ]torch.distributions.transforms.PowerTransform + +### [torch.distributions.transforms.PowerTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.SigmoidTransform) + +```python +torch.distributions.transforms.PowerTransform(exponent, cache_size=0) +``` + +### [paddle.distribution.PowerTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/PowerTransform_cn.html#powertransform) + +```python +paddle.distribution.PowerTransform(power) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| exponent | power | 幂参数。 | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ReshapeTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ReshapeTransform.md new file mode 100644 index 00000000000..ed33da17aa0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.ReshapeTransform.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.transforms.ReshapeTransform + +### [torch.distributions.transforms.ReshapeTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.ReshapeTransform) + +```python +torch.distributions.transforms.ReshapeTransform(in_shape, out_shape, cache_size=0) +``` + +### [paddle.distribution.ReshapeTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/ReshapeTransform_cn.html) + +```python +paddle.distribution.ReshapeTransform(in_event_shape, out_event_shape) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | --------------- | ------------------------------------------- | +| in_shape | in_event_shape | Reshape 前的事件形状,仅参数名不一致。 | +| out_shape | out_event_shape | Reshape 后的事件形状,仅参数名不一致。 | +| cache_size | - | cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SigmoidTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SigmoidTransform.md new file mode 100644 index 00000000000..dec61fc2cf5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SigmoidTransform.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.distributions.transforms.SigmoidTransform + +### [torch.distributions.transforms.SigmoidTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.SigmoidTransform) + +```python +torch.distributions.transforms.SigmoidTransform(cache_size=0) +``` + +### [paddle.distribution.SigmoidTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/SigmoidTransform_cn.html#sigmoidtransform) + +```python +paddle.distribution.SigmoidTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SoftmaxTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SoftmaxTransform.md new file mode 100644 index 00000000000..95ef8b2e234 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.SoftmaxTransform.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.distributions.transforms.SoftmaxTransform + +### [torch.distributions.transforms.SoftmaxTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.SoftmaxTransform) + +```python +torch.distributions.transforms.SoftmaxTransform(cache_size=0) +``` + +### [paddle.distribution.SoftmaxTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/SoftmaxTransform_cn.html) + +```python +paddle.distribution.SoftmaxTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -------------------------------------------------------------------------- | +| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StackTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StackTransform.md new file mode 100644 index 00000000000..dca6de9ded7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StackTransform.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.transforms.StackTransform + +### [torch.distributions.transforms.StackTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.StackTransform) + +```python +torch.distributions.transforms.StackTransform(tseq, dim=0, cache_size=0) +``` + +### [paddle.distribution.StackTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/StackTransform_cn.html) + +```python +paddle.distribution.StackTransform(transforms, axis=0) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -------------------------------------------------------------------------- | +| tseq | transforms | 输入的变换序列,仅参数名不一致。 | +| dim | axis | 待变换的轴,仅参数名不一致。 | +| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StickBreakingTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StickBreakingTransform.md new file mode 100644 index 00000000000..96bfd231320 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.StickBreakingTransform.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.distributions.transforms.StickBreakingTransform + +### [torch.distributions.transforms.StickBreakingTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.StickBreakingTransform) + +```python +torch.distributions.transforms.StickBreakingTransform(cache_size=0) +``` + +### [paddle.distribution.StickBreakingTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/StickBreakingTransform_cn.html) + +```python +paddle.distribution.StickBreakingTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -------------------------------------------------------------------------- | +| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.TanhTransform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.TanhTransform.md new file mode 100644 index 00000000000..476bdf948e9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.TanhTransform.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.distributions.transforms.TanhTransform + +### [torch.distributions.transforms.TanhTransform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.TanhTransform) + +```python +torch.distributions.transforms.TanhTransform(cache_size=0) +``` + +### [paddle.distribution.TanhTransform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/TanhTransform_cn.html#tanhtransform) + +```python +paddle.distribution.TanhTransform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| cache_size | - | 缓存大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.Transform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.Transform.md new file mode 100644 index 00000000000..97c411a27bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.transforms.Transform.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.distributions.transforms.Transform + +### [torch.distributions.transforms.Transform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.transforms.Transform) + +```python +torch.distributions.transforms.Transform(cache_size=0) +``` + +### [paddle.distribution.Transform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Transform_cn.html#transform) + +```python +paddle.distribution.Transform() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -------------------------------------------------------------------------- | +| cache_size | - | 表示 cache 大小,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.uniform.Uniform.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.uniform.Uniform.md new file mode 100644 index 00000000000..f37e1b6eb7c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/distributions/torch.distributions.uniform.Uniform.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.distributions.uniform.Uniform + +### [torch.distributions.uniform.Uniform](https://pytorch.org/docs/stable/distributions.html#torch.distributions.uniform.Uniform) + +```python +torch.distributions.uniform.Uniform(low, high, validate_args=None) +``` + +### [paddle.distribution.Uniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distribution/Uniform_cn.html) + +```python +paddle.distribution.Uniform(low, high, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | --------------------------------------------- | +| low | low | 均匀分布的下边界。 | +| high | high | 均匀分布的上边界。 | +| validate_args | - | 是否添加验证环节。Paddle 无此参数,一般对训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft.md new file mode 100644 index 00000000000..87a74599d44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ] torch.fft.fft + +### [torch.fft.fft](https://pytorch.org/docs/stable/generated/torch.fft.fft.html?highlight=fft#torch.fft.fft) + +```python +torch.fft.fft(input, n=None, dim=- 1, norm='backward', *, out=None) +``` + +### [paddle.fft.fft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/fft_cn.html) + +```python +paddle.fft.fft(x, n=None, axis=- 1, norm='backward', name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| n | n | 输出 Tensor 在傅里叶变换轴的长度。 | +| dim | axis | 傅里叶变换的轴,如果没有指定,默认是使用最后一维,仅参数名不一致。| +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.fft(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.fft(x, s, axes, norm), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft2.md new file mode 100644 index 00000000000..fff366ede03 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fft2.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ] torch.fft.fft2 + +### [torch.fft.fft2](https://pytorch.org/docs/stable/generated/torch.fft.fft2.html?highlight=fft2#torch.fft.fft2) + +```python +torch.fft.fft2(input, s=None, dim=None, norm='backward', *, out=None) +``` + +### [paddle.fft.fft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/fft2_cn.html) + +```python +paddle.fft.fft2(x, s=None, axes=None, norm='backward', name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| s | s | 输出 Tensor 在傅里叶变换轴的长度。 | +| dim | axes | 傅里叶变换的轴,如果没有指定,默认是使用最后一维,仅参数名不一致。| +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.fft2(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.fft2(x, s, axes, norm), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftfreq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftfreq.md new file mode 100644 index 00000000000..094a2ba0f56 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftfreq.md @@ -0,0 +1,65 @@ +## [ torch 参数更多 ] torch.fft.fftfreq + +### [torch.fft.fftfreq](https://pytorch.org/docs/stable/generated/torch.fft.fftfreq.html?highlight=fftfreq#torch.fft.fftfreq) + +```python +torch.fft.fftfreq(n, + d=1.0, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.fft.fftfreq](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/fftfreq_cn.html) + +```python +paddle.fft.fftfreq(n, + d=1.0, + dtype=None, + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| n | n | 窗长度(傅里叶变换点数)。 | +| d | d | 采样间隔,采样率的倒数,默认值为 1。 | +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype |返回 Tensor 的数据类型。 | +| layout |- |表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| device |- |表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad |- |表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.fftfreq(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.fftfreq(x),y) +``` + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.fft.fftfreq(x, requires_grad=True) + +# Paddle 写法 +x = paddle.fft.fftfreq(x) +x.stop_gradient = False +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.fft.fftfreq(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.fft.fftfreq(x) +y.cpu() diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftn.md new file mode 100644 index 00000000000..f9c9fc60661 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftn.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ] torch.fft.fftn + +### [torch.fft.fftn](https://pytorch.org/docs/stable/generated/torch.fft.fftn.html?highlight=fftn#torch.fft.fftn) + +```python +torch.fft.fftn(input, s=None, dim=None, norm='backward', *, out=None) +``` + +### [paddle.fft.fftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/fftn_cn.html) + +```python +paddle.fft.fftn(x, s=None, axes=None, norm='backward', name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| s | s | 输出 Tensor 在傅里叶变换轴的长度。 | +| dim | axes | 傅里叶变换的轴,如果没有指定,默认是使用最后一维,仅参数名不一致。| +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.fftn(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.fftn(x, s, axes, norm), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftshift.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftshift.md new file mode 100644 index 00000000000..87f45af527f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.fftshift.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.fft.fftshift + +### [torch.fft.fftshift](https://pytorch.org/docs/stable/generated/torch.fft.fftshift.html#torch.fft.fftshift) + +```python +torch.fft.fftshift(input, dim=None) +``` + +### [paddle.fft.fftshift](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/fftshift_cn.html) + +```python +paddle.fft.fftshift(x, axes=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axes | 进行移动的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft.md new file mode 100644 index 00000000000..63482bac481 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ] torch.fft.hfft + +### [torch.fft.hfft](https://pytorch.org/docs/stable/generated/torch.fft.hfft.html?highlight=hfft#torch.fft.hfft) + +```python +torch.fft.hfft(input, + n=None, + dim=- 1, + norm='backward', + *, + out=None) +``` + +### [paddle.fft.hfft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/hfft_cn.html) + +```python +paddle.fft.hfft(x, + n=None, + axis=- 1, + norm='backward', + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| n | n | 输出 Tensor 在傅里叶变换轴的长度。 | +| dim | axis | 傅里叶变换的轴,如果没有指定,默认是使用最后一维,仅参数名不一致。| +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.hfft(x, n=5, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.hfft(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft2.md new file mode 100644 index 00000000000..d06bbce1f59 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfft2.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.hfft2 + +### [torch.fft.hfft2](https://pytorch.org/docs/stable/generated/torch.fft.hfft2.html?highlight=torch+fft+hfft2#torch.fft.hfft2) + +```python +torch.fft.hfft2(input, s=None, dim=(- 2, - 1), norm='backward', *, out=None) +``` + +### [paddle.fft.hfft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/hfft2_cn.html) + +```python +paddle.fft.hfft2(x, s=None, axes=(- 2, - 1), norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.hfft2(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.hfft2(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfftn.md new file mode 100644 index 00000000000..f20afd4670c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.hfftn.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.hfftn + +### [torch.fft.hfftn](https://pytorch.org/docs/stable/generated/torch.fft.hfftn.html?highlight=torch+fft+hfftn#torch.fft.hfftn) + +```python +torch.fft.hfftn(input, s=None, dim=None, norm='backward', *, out=None) +``` + +### [paddle.fft.hfftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/hfftn_cn.html) + +```python +paddle.fft.hfftn(x, s=None, axes=None, norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.hfftn(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.hfftn(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft.md new file mode 100644 index 00000000000..7e6d6d1b94d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ] torch.fft.ifft + +### [torch.fft.ifft](https://pytorch.org/docs/stable/generated/torch.fft.ifft.html?highlight=ifft#torch.fft.ifft) + +```python +torch.fft.ifft(input, n=None, dim=- 1, norm='backward', *, out=None) +``` + +### [paddle.fft.ifft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ifft_cn.html) + +```python +paddle.fft.ifft(x, n=None, axis=- 1, norm='backward', name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x |输入 Tensor,仅参数名不一致。 | +| n | n |输出 Tensor 在每一个傅里叶变换轴上的长度。 | +| dim | axis |计算快速傅里叶变换的轴。仅参数名不一致。 | +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ifft(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ifft(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft2.md new file mode 100644 index 00000000000..37d800e29ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifft2.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ] torch.fft.ifft2 + +### [torch.fft.ifft2](https://pytorch.org/docs/stable/generated/torch.fft.ifft2.html?highlight=ifft2#torch.fft.ifft2) + +```python +torch.fft.ifft2(input, + s=None, + dim=None, + norm='backward', + *, + out=None) +``` + +### [paddle.fft.ifft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ifft2_cn.html) + +```python +paddle.fft.ifft2(x, + s=None, + axes=None, + norm='backward', + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x |输入 Tensor,仅参数名不一致。 | +| s | s |输出 Tensor 在每一个傅里叶变换轴上的长度。 | +| dim | axes |计算快速傅里叶变换的轴。仅参数名不一致。 | +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ifft2(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ifft2(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftn.md new file mode 100644 index 00000000000..31f5564dd86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftn.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ] torch.fft.ifftn + +### [torch.fft.ifftn](https://pytorch.org/docs/stable/generated/torch.fft.ifftn.html?highlight=ifftn#torch.fft.ifftn) + +```python +torch.fft.ifftn(input, + s=None, + dim=None, + norm='backward', + *, + out=None) +``` + +### [paddle.fft.ifftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ifftn_cn.html) + +```python +paddle.fft.ifftn(x, + s=None, + axes=None, + norm='backward', + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x |输入 Tensor,仅参数名不一致。 | +| s | s |输出 Tensor 在每一个傅里叶变换轴上的长度。 | +| dim | axes |计算快速傅里叶变换的轴。仅参数名不一致。 | +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ifftn(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ifftn(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftshift.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftshift.md new file mode 100644 index 00000000000..ead0ebdce3d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ifftshift.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.fft.ifftshift + +### [torch.fft.ifftshift](https://pytorch.org/docs/stable/generated/torch.fft.ifftshift.html#torch.fft.ifftshift) + +```python +torch.fft.ifftshift(input, dim=None) +``` + +### [paddle.fft.ifftshift](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ifftshift_cn.html) + +```python +paddle.fft.ifftshift(x, axes=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axes | 进行移动的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft.md new file mode 100644 index 00000000000..8c04291c397 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ] torch.fft.ihfft + +### [torch.fft.ihfft](https://pytorch.org/docs/stable/generated/torch.fft.ihfft.html?highlight=ihfft#torch.fft.ihfft) + +```python +torch.fft.ihfft(input, + n=None, + dim=- 1, + norm='backward', + *, + out=None) +``` + +### [paddle.fft.ihfft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ihfft_cn.html) + +```python +paddle.fft.ihfft(x, + n=None, + axis=- 1, + norm='backward', + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x |输入 Tensor,仅参数名不一致。 | +| n | n |傅里叶变换点数。 | +| dim | axis |傅里叶变换的轴,如果没有指定,默认使用最后一维,仅参数名不一致。| +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ihfft(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ihfft(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft2.md new file mode 100644 index 00000000000..543b74264ee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfft2.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.ihfft2 + +### [torch.fft.ihfft2](https://pytorch.org/docs/stable/generated/torch.fft.ihfft2.html?highlight=torch+fft+ihfft2#torch.fft.ihfft2) + +```python +torch.fft.ihfft2(input, s=None, dim=(- 2, - 1), norm='backward', *, out=None) +``` + +### [paddle.fft.ihfft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ihfft2_cn.html) + +```python +paddle.fft.ihfft2(x, s=None, axes=(- 2, - 1), norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ihfft2(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ihfft2(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfftn.md new file mode 100644 index 00000000000..c61085766c0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.ihfftn.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.ihfftn + +### [torch.fft.ihfftn](https://pytorch.org/docs/stable/generated/torch.fft.ihfftn.html?highlight=torch+fft+ihfftn#torch.fft.ihfftn) + +```python +torch.fft.ihfftn(input, s=None, dim=None, norm='backward', *, out=None) +``` + +### [paddle.fft.ihfftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/ihfftn_cn.html) + +```python +paddle.fft.ihfftn(x, s=None, axes=None, norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.ihfftn(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.ihfftn(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft.md new file mode 100644 index 00000000000..4e478c3dd98 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.irfft + +### [torch.fft.irfft](https://pytorch.org/docs/stable/generated/torch.fft.irfft.html#torch-fft-irfft) + +```python +torch.fft.irfft(input, n=None, dim=- 1, norm='backward', *, out=None) +``` + +### [paddle.fft.irfft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/irfft_cn.html#irfft) + +```python +paddle.fft.irfft(x, n=None, axis=- 1, norm='backward', name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| n | n | 表示在傅里叶变换轴的长度 。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.irfft(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.irfft(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft2.md new file mode 100644 index 00000000000..168b5076d8b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfft2.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.irfft2 + +### [torch.fft.irfft2](https://pytorch.org/docs/stable/generated/torch.fft.irfft2.html#torch-fft-irfft2) + +```python +torch.fft.irfft2(input, s=None, dim=(- 2, - 1), norm='backward', *, out=None) +``` + +### [paddle.fft.irfft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/irfft2_cn.html#irfft2) + +```python +paddle.fft.irfft2(x, s=None, axes=(- 2, - 1), norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.irfft2(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.irfft2(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfftn.md new file mode 100644 index 00000000000..3871946d179 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.irfftn.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ] torch.fft.irfftn + +### [torch.fft.irfftn](https://pytorch.org/docs/stable/generated/torch.fft.irfftn.html?highlight=irfftn#torch.fft.irfftn) + +```python +torch.fft.irfftn(input, + s=None, + dim=None, + norm='backward', + *, + out=None) +``` + +### [paddle.fft.irfftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/irfftn_cn.html) + +```python +paddle.fft.irfftn(x, + s=None, + axes=None, + norm='backward', + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x |输入 Tensor,仅参数名不一致。 | +| s | s |输出 Tensor 在每一个傅里叶变换轴上的长度。 | +| dim | axes |计算快速傅里叶变换的轴。仅参数名不一致。 | +| norm |norm |傅里叶变换的缩放模式,缩放系数由变换的方向和缩放模式同时决定,完全一致。| +| out | - |输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.irfftn(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.irfftn(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft.md new file mode 100644 index 00000000000..ab0dc8f837d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.rfft + +### [torch.fft.rfft](https://pytorch.org/docs/stable/generated/torch.fft.rfft.html#torch-fft-rfft) + +```python +torch.fft.rfft(input, s=None, dim=(- 2, - 1), norm='backward', *, out=None) +``` + +### [paddle.fft.rfft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/rfft_cn.html#rfft) + +```python +paddle.fft.rfft(x, s=None, axes=(- 2, - 1), norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| n | n | 表示在傅里叶变换轴的长度 。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.rfft(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.rfft(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft2.md new file mode 100644 index 00000000000..cce52225849 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfft2.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.rfft2 + +### [torch.fft.rfft2](https://pytorch.org/docs/stable/generated/torch.fft.rfft2.html) + +```python +torch.fft.rfft2(input, s=None, dim=(-2, -1), norm=None, *, out=None) +``` + +### [paddle.fft.rfft2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/rfft2_cn.html#rfft2) + +```python +paddle.fft.rfft2(x, s=None, axes=(- 2, - 1), norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.rfft2(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.rfft2(x, s, dim, norm), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftfreq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftfreq.md new file mode 100644 index 00000000000..7a5b8c7cff1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftfreq.md @@ -0,0 +1,66 @@ +## [ torch 参数更多 ] torch.fft.rfftfreq + +### [torch.fft.rfftfreq](https://pytorch.org/docs/stable/generated/torch.fft.rfftfreq.html?highlight=rfftfreq#torch.fft.rfftfreq) + +```python +torch.fft.rfftfreq(n, + d=1.0, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.fft.rfftfreq](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/rfftfreq_cn.html) + +```python +paddle.fft.rfftfreq(n, + d=1.0, + dtype=None, + name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| n |n | 窗长度(傅里叶变换点数)。 | +| d |d | 采样间隔,采样率的倒数,默认值为 1。 | +| out |- |输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype |dtype | 返回 Tensor 的数据类型。 | +| layout |- |表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| device |- |表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad |- |表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.rfftfreq(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.rfftfreq(x), y) +``` + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.fft.rfftfreq(x, requires_grad=True) + +# Paddle 写法 +x = paddle.fft.rfftfreq(x) +x.stop_gradient = False +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.fft.rfftfreq(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.fft.rfftfreq(x) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftn.md new file mode 100644 index 00000000000..88bf023eee1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/fft/torch.fft.rfftn.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.fft.rfftn + +### [torch.fft.rfftn](https://pytorch.org/docs/stable/generated/torch.fft.rfftn.html#torch-fft-rfftn) + +```python +torch.fft.rfftn(input, s=None, dim=None, norm='backward', *, out=None) +``` + +### [paddle.fft.rfftn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fft/rfftn_cn.html#rfftn) + +```python +paddle.fft.rfftn(x, s=None, axes=None, norm='backward', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| s | s | 表示在傅里叶变换轴的长度 。 | +| dim | axes | 表示进行运算的轴,仅参数名不一致。 | +| norm | norm | 表示傅里叶变换的缩放模式。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fft.rfftn(x, s, dim, norm, out=y) + +# Paddle 写法 +paddle.assign(paddle.fft.rfftn(x, s, dim, norm) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional._Reduction.get_enum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional._Reduction.get_enum.md new file mode 100644 index 00000000000..c208f1d7ff9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional._Reduction.get_enum.md @@ -0,0 +1,34 @@ +## [组合替代实现]torch.nn.functional._Reduction.get_enum + +### [torch.nn.functional._Reduction.get_enum](https://github.com/pytorch/pytorch/blob/3045b16488f14c9d941d33d63417e6ea52fb2544/torch/nn/_reduction.py#L7) + +```python +torch.nn.functional._Reduction.get_enum(reduction) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.functional._Reduction.get_enum(reduction) + +# Paddle 写法 +def get_enum(reduction: str) -> int: + if reduction == 'none': + ret = 0 + elif reduction == 'mean': + ret = 1 + elif reduction == 'elementwise_mean': + warnings.warn("reduction='elementwise_mean' is deprecated, please use reduction='mean' instead.") + ret = 1 + elif reduction == 'sum': + ret = 2 + else: + ret = -1 + raise ValueError("{} is not a valid value for reduction".format(reduction)) + return ret + +get_enum(reduction) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool1d.md new file mode 100644 index 00000000000..591e548083d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool1d.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_avg_pool1d + +### [torch.nn.functional.adaptive_avg_pool1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.adaptive_avg_pool1d.html?highlight=adaptive_avg_pool1d#torch.nn.functional.adaptive_avg_pool1d) + +```python +torch.nn.functional.adaptive_avg_pool1d(input, output_size) +``` + +### [paddle.nn.functional.adaptive_avg_pool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_avg_pool1d_cn.html) + +```python +paddle.nn.functional.adaptive_avg_pool1d(x, output_size, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| output_size | output_size | 表示输出 Tensor 的大小。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool2d.md new file mode 100644 index 00000000000..e8061fac2de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool2d.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_avg_pool2d + +### [torch.nn.functional.adaptive_avg_pool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.adaptive_avg_pool2d.html?highlight=adaptive_avg_pool2d#torch.nn.functional.adaptive_avg_pool2d) + +```python +torch.nn.functional.adaptive_avg_pool2d(input, output_size) +``` + +### [paddle.nn.functional.adaptive_avg_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_avg_pool2d_cn.html) + +```python +paddle.nn.functional.adaptive_avg_pool2d(x, + output_size, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| output_size | output_size | 表示输出 Tensor 的大小。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool3d.md new file mode 100644 index 00000000000..16419fd9b23 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_avg_pool3d.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_avg_pool3d + +### [torch.nn.functional.adaptive_avg_pool3d](https://pytorch.org/docs/stable/generated/torch.ao.nn.quantized.functional.adaptive_avg_pool3d.html?highlight=adaptive_avg_pool3d#torch.ao.nn.quantized.functional.adaptive_avg_pool3d) + +```python +torch.nn.functional.adaptive_avg_pool3d(input, output_size) +``` + +### [paddle.nn.functional.adaptive_avg_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_avg_pool3d_cn.html) + +```python +paddle.nn.functional.adaptive_avg_pool3d(x, + output_size, + data_format='NCDHW', + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| output_size | output_size | 表示输出 Tensor 的大小,仅参数名不一致。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool1d.md new file mode 100644 index 00000000000..40cccf68416 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool1d.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_max_pool1d + +### [torch.nn.functional.adaptive_max_pool1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.adaptive_max_pool1d.html?highlight=torch+nn+functional+adaptive_max_pool1d#torch.nn.functional.adaptive_max_pool1d) + +```python +torch.nn.functional.adaptive_max_pool1d(input, + output_size, + return_indices=False) +``` + +### [paddle.nn.functional.adaptive_max_pool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_max_pool1d_cn.html#adaptive-max-pool1d) + +```python +paddle.nn.functional.adaptive_max_pool1d(x, + output_size, + return_mask=False, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| output_size | output_size | 表示输出 Tensor 的大小,仅参数名不一致。 | +| return_indices | return_mask | 表示是否返回最大值的索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool2d.md new file mode 100644 index 00000000000..1171902520a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool2d.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_max_pool2d + +### [torch.nn.functional.adaptive_max_pool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.adaptive_max_pool2d.html?highlight=adaptive_max_pool2d#torch.nn.functional.adaptive_max_pool2d) + +```python +torch.nn.functional.adaptive_max_pool2d(input, + output_size, + return_indices=False) +``` + +### [paddle.nn.functional.adaptive_max_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_max_pool2d_cn.html) + +```python +paddle.nn.functional.adaptive_max_pool2d(x, + output_size, + return_mask=False, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| output_size | output_size | 表示输出 Tensor 的大小,仅参数名不一致。 | +| return_indices | return_mask | 表示是否返回最大值的索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool3d.md new file mode 100644 index 00000000000..dbd6a7a690c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.adaptive_max_pool3d.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.nn.functional.adaptive_max_pool3d + +### [torch.nn.functional.adaptive_max_pool3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.adaptive_max_pool3d.html?highlight=adaptive_max_pool3d#torch.nn.functional.adaptive_max_pool3d) + +```python +torch.nn.functional.adaptive_max_pool3d(input, + output_size, + return_indices=False) +``` + +### [paddle.nn.functional.adaptive_max_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/adaptive_max_pool3d_cn.html) + +```python +paddle.nn.functional.adaptive_max_pool3d(x, + output_size, + return_mask=False, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| output_size | output_size | 表示输出 Tensor 的大小,仅参数名不一致。 | +| return_indices | return_mask | 表示是否返回最大值的索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.affine_grid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.affine_grid.md new file mode 100644 index 00000000000..a42b3879704 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.affine_grid.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ] torch.nn.functional.affine_grid + +### [torch.nn.functional.affine_grid](https://pytorch.org/docs/stable/generated/torch.nn.functional.affine_grid.html?highlight=affine_grid#torch.nn.functional.affine_grid) + +```python +torch.nn.functional.affine_grid(theta, + size, + align_corners=None) +``` + +### [paddle.nn.functional.affine_grid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/affine_grid_cn.html) + +```python +paddle.nn.functional.affine_grid(theta, + out_shape, + align_corners=True, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| theta | theta | 指定仿射变换矩阵 | +| size | out_shape | 表示指定目标输出图像大小,仅参数名不一致。 | +| align_corners | align_corners | 指定是否是像素中心对齐 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.alpha_dropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.alpha_dropout.md new file mode 100644 index 00000000000..eff8a4be8d2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.alpha_dropout.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.nn.functional.alpha_dropout + +### [torch.nn.functional.alpha\_dropout](https://pytorch.org/docs/stable/generated/torch.nn.functional.alpha_dropout.html) + +```python +torch.nn.functional.alpha_dropout(input, p=0.5, training=False, inplace=False) +``` + +### [paddle.nn.functional.alpha\_dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/alpha_dropout_cn.html#alpha-dropout) + +```python +paddle.nn.functional.alpha_dropout(x, p=0.5, training=True, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率。 | +| training | training | 标记是否为训练阶段,PyTorch 默认值为 False,paddle 默认值为 True。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool1d.md new file mode 100644 index 00000000000..b8085bd1b53 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool1d.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.nn.functional.avg_pool1d + +### [torch.nn.functional.avg_pool1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.avg_pool1d.html#torch.nn.functional.avg_pool1d) + +```python +torch.nn.functional.avg_pool1d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True) +``` + +### [paddle.nn.functional.avg_pool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/avg_pool1d_cn.html#avg-pool1d) +```python +paddle.nn.functional.avg_pool1d(x, kernel_size, stride=None, padding=0, exclusive=True, ceil_mode=False, name=None) +``` + +其中 PyTorch 与 Paddle 参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| ceil_mode | ceil_mode | 是否用 `ceil` 函数计算输出的 height 和 width,如果设置为 `False`,则使用 `floor` 函数来计算,默认为 `False` | +| count_include_pad | exclusive | 是否用额外 padding 的值计算平均池化结果,PyTorch 与 Paddle 的功能相反,需要转写 | + + +### 转写示例 +#### count_include_pad:是否用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.functional.avg_pool1d(input=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, count_include_pad=False) + +# Paddle 写法 +paddle.nn.functional.avg_pool1d(x=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, exlusive=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool2d.md new file mode 100644 index 00000000000..e210504bf88 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool2d.md @@ -0,0 +1,37 @@ +## [ 参数不一致 ]torch.nn.functional.avg_pool2d + +### [torch.nn.functional.avg_pool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.avg_pool2d.html#torch.nn.functional.avg_pool2d) + +```python +torch.nn.functional.avg_pool2d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None) +``` + +### [paddle.nn.functional.avg_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/avg_pool2d_cn.html#avg-pool2d) +```python +paddle.nn.functional.avg_pool2d(x, kernel_size, stride=None, padding=0, ceil_mode=False, exclusive=True, divisor_override=None, data_format='NCHW', name=None) +``` + +其中 PyTorch 与 Paddle 参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| ceil_mode | ceil_mode | 是否用 `ceil` 函数计算输出的 height 和 width,如果设置为 `False`,则使用 `floor` 函数来计算,默认为 `False` | +| divisor_override | divisor_override | 如果指定,它将用作除数,否则根据 `kernel_size` 计算除数。默认 `None` | +| - | data_format | 输入和输出的数据格式, PyTorch 无此参数, 保持默认即可。 | +| count_include_pad | exclusive | 是否用额外 padding 的值计算平均池化结果,PyTorch 与 Paddle 的功能相反,需要转写 | + + +### 转写示例 +#### count_include_pad:是否用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.functional.avg_pool2d(input=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, count_include_pad=False) + +# Paddle 写法 +paddle.nn.AvgPool2D(x=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, exlusive=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool3d.md new file mode 100644 index 00000000000..d8a7151595a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.avg_pool3d.md @@ -0,0 +1,37 @@ +## [ 参数不一致 ]torch.nn.functional.avg_pool3d + +### [torch.nn.functional.avg_pool3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.avg_pool3d.html#torch.nn.functional.avg_pool3d) + +```python +torch.nn.functional.avg_pool3d(input, kernel_size, stride=None, padding=0, ceil_mode=False, count_include_pad=True, divisor_override=None) +``` + +### [paddle.nn.functional.avg_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/avg_pool3d_cn.html#avg-pool3d) +```python +paddle.nn.functional.avg_pool3d(x, kernel_size, stride=None, padding=0, ceil_mode=False, exclusive=True, divisor_override=None, data_format='NCDHW', name=None) +``` + +其中 PyTorch 与 Paddle 参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| ceil_mode | ceil_mode | 是否用 `ceil` 函数计算输出的 height 和 width,如果设置为 `False`,则使用 `floor` 函数来计算,默认为 `False` | +| divisor_override | divisor_override | 如果指定,它将用作除数,否则根据 `kernel_size` 计算除数。默认 `None` | +| - | data_format | 输入和输出的数据格式, PyTorch 无此参数,保持默认即可。 | +| count_include_pad | exclusive | 是否用额外 padding 的值计算平均池化结果,PyTorch 与 Paddle 的功能相反,需要转写 | + + +### 转写示例 +#### count_include_pad:是否用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.functional.avg_pool3d(input=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, count_include_pad=False) + +# Paddle 写法 +paddle.nn.functional.avg_pool3d(x=input, kernel_size=2, stride=2, padding=1, ceil_mode=True, exlusive=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md new file mode 100644 index 00000000000..8224032c8c1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.batch_norm.md @@ -0,0 +1,38 @@ +## [ 参数不一致 ]torch.nn.functional.batch_norm + +### [torch.nn.functional.batch_norm](https://pytorch.org/docs/stable/generated/torch.nn.functional.batch_norm.html#torch.nn.functional.batch_norm) + +```python +torch.nn.functional.batch_norm(input, running_mean, running_var, weight=None, bias=None, training=False, momentum=0.1, eps=1e-05) +``` + +### [paddle.nn.functional.batch_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/batch_norm_cn.html#batch-norm) +```python +paddle.nn.functional.batch_norm(x, running_mean, running_var, weight, bias, training=False, momentum=0.9, epsilon=1e-05, data_format='NCHW', name=None) +``` + +其中 PyTorch 与 Paddle 参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| running_mean | running_mean | 均值的 Tensor。 | +| running_var | running_var | 方差的 Tensor。 | +| weight | weight | 权重的 Tensor。 | +| bias | bias | 偏置的 Tensor。 | +| eps | epsilon | 为了数值稳定加在分母上的值。 | +| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 | +| training | training | 是否可训练。 | +| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### momentum:此值用于计算 moving_mean 和 moving_var +```python +# PyTorch 写法 +torch.nn.functional.batch_norm(input=input, running_mean=running_mean, running_var=running_var, momentum=0.1) + +# Paddle 写法 +paddle.nn.functional.batch_norm(x=input, running_mean=running_mean, running_var=running_var, momentum=0.9) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.bilinear.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.bilinear.md new file mode 100644 index 00000000000..c5c45bb037a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.bilinear.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ]torch.nn.functional.bilinear + +### [torch.nn.functional.bilinear](https://pytorch.org/docs/stable/generated/torch.nn.functional.bilinear.html?highlight=bilinear#torch.nn.functional.bilinear) + +```python +torch.nn.functional.bilinear(input1, + input2, + weight, + bias=None) +``` + +### [paddle.nn.functional.bilinear](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/bilinear_cn.html) + +```python +paddle.nn.functional.bilinear(x1, + x2, + weight, + bias=None, + name=None) +``` + +两者功能一致,参数 `bias` 的 `shape` 不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input1 | x1 | 表示第一个输入的 Tensor ,仅参数名不一致。 | +| input2 | x2 | 表示第二个输入的 Tensor ,仅参数名不一致。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏重 Tensor ,PyTorch bias 参数的 shape 为 (out_features),Paddle bias 参数的 shape 为 (1, out_features),需要转写。 | + +### 转写示例 +#### bias: 偏重 +```python +# PyTorch 写法 +result = F.bilinear(input1, input2, weight=weight, bias=bias) + +# Paddle 写法 +result = F.bilinear(input1, input2, weight=weight, bias=bias.unsqueeze(0)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy.md new file mode 100644 index 00000000000..9416b07e298 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy.md @@ -0,0 +1,44 @@ +## [ torch 参数更多 ]torch.nn.functional.binary_cross_entropy + +### [torch.nn.functional.binary\_cross\_entropy](https://pytorch.org/docs/stable/generated/torch.nn.functional.binary_cross_entropy.html) + +```python +torch.nn.functional.binary_cross_entropy(input, target, weight=None, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.binary\_cross\_entropy](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/binary_cross_entropy_cn.html#binary-cross-entropy) + +```python +paddle.nn.functional.binary_cross_entropy(input, label, weight=None, reduction='mean', name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -- | +| input | input | 输入 Tensor。 | +| target | label | 标签 Tensor。 | +| weight | weight | 手动指定每个 batch 二值交叉熵的权重。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average、reduce +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy_with_logits.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy_with_logits.md new file mode 100644 index 00000000000..808caa2f9b2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.binary_cross_entropy_with_logits.md @@ -0,0 +1,86 @@ +## [torch 参数更多]torch.nn.functional.binary_cross_entropy_with_logits + +### [torch.nn.functional.binary_cross_entropy_with_logits](https://pytorch.org/docs/stable/generated/torch.nn.functional.binary_cross_entropy_with_logits.html?highlight=binary_cross_entropy_with_logits#torch.nn.functional.binary_cross_entropy_with_logits) + +```python +torch.nn.functional.binary_cross_entropy_with_logits(input, target, weight=None, size_average=None, reduce=None, reduction='mean', pos_weight=None) +``` + +### [paddle.nn.functional.binary_cross_entropy_with_logits](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/binary_cross_entropy_with_logits_cn.html) + +```python +paddle.nn.functional.binary_cross_entropy_with_logits(logit, label, weight=None, reduction='mean', pos_weight=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | logit | 表示输入的 Tensor。 | +| target | label | 标签,和 input 具有相同的维度,仅参数名不一致。 | +| weight | weight | 类别权重。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 Paddle 无此参数,需要转写。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 Paddle 无此参数,需要转写。 | +| reduction | reduction | 输出结果的计算方式。 | +| pos_weight | pos_weight | 正类的权重。 | + +### 转写示例 +#### size_average:是否对损失进行平均或求和 +```python +# PyTorch 写法 (size_average 为‘True’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, size_average=True) + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (size_average 为‘False’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, size_average=False) + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='sum') +``` + +#### reduce:是否对损失进行平均或求和 +```python +# PyTorch 写法 (reduce 为‘True’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, reduce=True) + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduce 为‘False’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, reduce=False) + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='sum') +``` + +#### reduction:输出结果的计算方式 +```python +# PyTorch 写法 (reduction 为‘none’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, reduction='none') + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='none') + +# PyTorch 写法 (reduction 为‘mean’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, reduction='mean') + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduction 为‘sum’时) +torch.nn.functional.binary_cross_entropy_with_logits(a, target, reduction='sum') + +# Paddle 写法 +paddle.nn.functional.binary_cross_entropy_with_logits(logit=a, label=target, + reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.celu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.celu.md new file mode 100644 index 00000000000..e746f0444ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.celu.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.functional.celu + +### [torch.nn.functional.celu](https://pytorch.org/docs/stable/generated/torch.nn.functional.celu.html#torch.nn.functional.celu) + +```python +torch.nn.functional.celu(input, alpha=1.0, inplace=False) +``` + +### [paddle.nn.functional.celu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/celu_cn.html) + +```python +paddle.nn.functional.celu(x, alpha=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| alpha | alpha | alpha 参数。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv1d.md new file mode 100644 index 00000000000..2f3ac62bc06 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv1d.md @@ -0,0 +1,41 @@ +## [ 仅参数名不一致 ]torch.nn.functional.conv1d + +### [torch.nn.functional.conv1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv1d.html?highlight=conv1d#torch.nn.functional.conv1d) + +```python +torch.nn.functional.conv1d(input, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1) +``` + +### [paddle.nn.functional.conv1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv1d_cn.html) + +```python +paddle.nn.functional.conv1d(x, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1, + data_format='NCL', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| dilation | dilation | 表示空洞大小 。 | +| groups | groups | 表示分组数 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv2d.md new file mode 100644 index 00000000000..4a60c6dc23e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv2d.md @@ -0,0 +1,41 @@ +## [ 仅参数名不一致 ]torch.nn.functional.conv2d + +### [torch.nn.functional.conv2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv2d.html?highlight=conv2d#torch.nn.functional.conv2d) + +```python +torch.nn.functional.conv2d(input, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1) +``` + +### [paddle.nn.functional.conv2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv2d_cn.html) + +```python +paddle.nn.functional.conv2d(x, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| dilation | dilation | 表示空洞大小 。 | +| groups | groups | 表示分组数 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv3d.md new file mode 100644 index 00000000000..afc7b8c5dfa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv3d.md @@ -0,0 +1,41 @@ +## [ 仅参数名不一致 ]torch.nn.functional.conv3d + +### [torch.nn.functional.conv3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv3d.html?highlight=conv3d#torch.nn.functional.conv3d) + +```python +torch.nn.functional.conv3d(input, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1) +``` + +### [paddle.nn.functional.conv3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv3d_cn.html) + +```python +paddle.nn.functional.conv3d(x, + weight, + bias=None, + stride=1, + padding=0, + dilation=1, + groups=1, + data_format='NCDHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| dilation | dilation | 表示空洞大小 。 | +| groups | groups | 表示分组数 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose1d.md new file mode 100644 index 00000000000..5cdc2efbbd0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose1d.md @@ -0,0 +1,46 @@ +## [仅 paddle 参数更多 ]torch.nn.functional.conv_transpose1d + +### [torch.nn.functional.conv_transpose1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv_transpose1d.html?highlight=conv_trans#torch.nn.functional.conv_transpose1d) + +```python +torch.nn.functional.conv_transpose1d(input, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1) +``` + +### [paddle.nn.functional.conv1d_transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv1d_transpose_cn.html) + +```python +paddle.nn.functional.conv1d_transpose(x, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + output_size=None, + data_format='NCL', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| output_padding | output_padding | 表示输出形状上尾部一侧额外添加的大小 。 | +| groups | groups | 表示分组数 。 | +| dilation | dilation | 表示空洞大小 。 | +| - | output_size | 表示输出 Tensor 的尺寸, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose2d.md new file mode 100644 index 00000000000..00d54843f41 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose2d.md @@ -0,0 +1,46 @@ +## [仅 paddle 参数更多 ]torch.nn.functional.conv_transpose2d + +### [torch.nn.functional.conv_transpose2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv_transpose2d.html?highlight=conv_#torch.nn.functional.conv_transpose2d) + +```python +torch.nn.functional.conv_transpose2d(input, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1) +``` + +### [paddle.nn.functional.conv2d_transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv2d_transpose_cn.html) + +```python +paddle.nn.functional.conv2d_transpose(x, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + data_format='NCHW', + output_size=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| output_padding | output_padding | 表示输出形状上尾部一侧额外添加的大小 。 | +| groups | groups | 表示分组数 。 | +| dilation | dilation | 表示空洞大小 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | output_size | 表示输出 Tensor 的尺寸, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose3d.md new file mode 100644 index 00000000000..32db4e735e6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.conv_transpose3d.md @@ -0,0 +1,46 @@ +## [仅 paddle 参数更多 ]torch.nn.functional.conv_transpose3d + +### [torch.nn.functional.conv_transpose3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.conv_transpose3d.html?highlight=conv_#torch.nn.functional.conv_transpose3d) + +```python +torch.nn.functional.conv_transpose3d(input, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1) +``` + +### [paddle.nn.functional.conv3d_transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/conv3d_transpose_cn.html) + +```python +paddle.nn.functional.conv3d_transpose(x, + weight, + bias=None, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + output_size=None, + data_format='NCDHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示权重 Tensor 。 | +| bias | bias | 表示偏置项 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| output_padding | output_padding | 表示输出形状上尾部一侧额外添加的大小 。 | +| groups | groups | 表示分组数 。 | +| dilation | dilation | 表示空洞大小 。 | +| - | output_size | 表示输出 Tensor 的尺寸, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_embedding_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_embedding_loss.md new file mode 100644 index 00000000000..4b3d8f6e68c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_embedding_loss.md @@ -0,0 +1,44 @@ +## [torch 参数更多]torch.nn.functional.cosine_embedding_loss + +### [torch.nn.functional.cosine_embedding_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.cosine_embedding_loss.html#torch.nn.functional.cosine_embedding_loss) + +```python +torch.nn.functional.cosine_embedding_loss(input1, input2, target, margin=0, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.cosine_embedding_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/cosine_embedding_loss_cn.html) + +```python +paddle.nn.functional.cosine_embedding_loss(input1, input2, label, margin=0, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ---------------------------------------------- | +| input1 | input1 | 输入的 Tensor。 | +| input2 | input2 | 输入的 Tensor。 | +| target | label | 标签,仅参数名不一致。 | +| margin | margin | 可以设置的范围为[-1, 1]。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_similarity.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_similarity.md new file mode 100644 index 00000000000..89648dc3cd9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cosine_similarity.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.nn.functional.cosine_similarity + +### [torch.nn.functional.cosine_similarity](https://pytorch.org/docs/stable/generated/torch.nn.functional.cosine_similarity.html?highlight=cosine#torch.nn.functional.cosine_similarity) + +```python +torch.nn.functional.cosine_similarity(x1, + x2, + dim=1, + eps=1e-08) +``` + +### [paddle.nn.functional.cosine_similarity](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/cosine_similarity_cn.html) + +```python +paddle.nn.functional.cosine_similarity(x1, + x2, + axis=1, + eps=1e-8) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| x1 | x1 | 表示第一个输入的 Tensor 。 | +| x2 | x2 | 表示第二个输入的 Tensor 。 | +| dim | axis | 表示计算的维度,仅参数名不一致。 | +| eps | eps | 表示加到分母上的超参数 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md new file mode 100644 index 00000000000..34285204d3c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.cross_entropy.md @@ -0,0 +1,120 @@ +## [ torch 参数更多 ]torch.nn.functional.cross_entropy + +### [torch.nn.functional.cross_entropy](https://pytorch.org/docs/stable/generated/torch.nn.functional.cross_entropy.html?highlight=cross_#torch.nn.functional.cross_entropy) + +```python +torch.nn.functional.cross_entropy(input, + target, + weight=None, + size_average=None, + ignore_index=- 100, + reduce=None, + reduction='mean', + label_smoothing=0.0) +``` + +### [paddle.nn.functional.cross_entropy](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/cross_entropy_cn.html) + +```python +paddle.nn.functional.cross_entropy(input, + label, + weight=None, + ignore_index=- 100, + reduction='mean', + soft_label=False, + axis=- 1, + use_softmax=True) +``` +两者功能一致,torch 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示预测的 Tensor 。 | +| target | label | 表示真实的 Tensor 。 | +| weight | weight | 表示权重。 | +| size_average | - | 已弃用 。 | +| ignore_index | ignore_index | 表示忽略的标签值 。 | +| reduce | - | 已弃用 。 | +| reduction | reduction | 表示应用于输出结果的计算方式 。 | +| label_smoothing | - | 指定计算损失时的平滑量, Paddle 无此参数,暂无转写方式。| +| - | soft_label | 指明 label 是否为软标签, PyTorch 无此参数, Paddle 保持默认即可。| +| - | axis | 进行 softmax 计算的维度索引, PyTorch 无此参数, Paddle 保持默认即可。| +| - | use_softmax | 指定是否对 input 进行 softmax 归一化, PyTorch 无此参数, Paddle 保持默认即可。| + +### 转写示例 +#### size_average + +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,size_average=True) + +# Paddle 写法 +paddle.nn.functional.cross_entropy(x,y,reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,size_average=False) + +# Paddle 写法 +paddle.nn.functional.cross_entropy(x,y,reduction='sum') +``` + +#### reduce + +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,reduce=True) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(reduction='mean') +``` + +reduce 为 False + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,reduce=False) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(reduction='none') +``` + +#### reduction + +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,reduction='none') + +# Paddle 写法 +paddle.nn.functional.cross_entropy(x,y,reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,reduction='mean') + +# Paddle 写法 +paddle.nn.functional.cross_entropy(x,y,reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.functional.cross_entropy(x,y,reduction='sum') + +# Paddle 写法 +paddle.nn.functional.cross_entropy(x,y,reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md new file mode 100644 index 00000000000..ae66326d426 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.ctc_loss.md @@ -0,0 +1,27 @@ +## [torch 参数更多]torch.nn.functional.ctc_loss + +### [torch.nn.functional.ctc_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.ctc_loss.html#torch.nn.functional.ctc_loss) + +```python +torch.nn.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reduction='mean', zero_infinity=False) +``` + +### [paddle.nn.functional.ctc_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/ctc_loss_cn.html) + +```python +paddle.nn.functional.ctc_loss(log_probs, labels, input_lengths, label_lengths, blank=0, reduction='mean') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------- | ------------------------------------------------------------------ | +| log_probs | log_probs | 经过 padding 的概率序列。 | +| targets | labels | 经过 padding 的标签序列,仅参数名不一致。 | +| input_lengths | input_lengths | 表示输入 log_probs 数据中每个序列的长度。 | +| target_lengths | label_lengths | 表示 label 中每个序列的长度,仅参数名不一致。 | +| blank | blank | 空格标记的 ID 值。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | +| zero_infinity | - | 是否设置 infinity 及关联梯度 为 0,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout.md new file mode 100644 index 00000000000..b527971fc4b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout.md @@ -0,0 +1,26 @@ +## [ torch 参数更多 ]torch.nn.functional.dropout + +### [torch.nn.functional.dropout](https://pytorch.org/docs/stable/generated/torch.nn.functional.dropout.html) + +```python +torch.nn.functional.dropout(input, p=0.5, training=True, inplace=False) +``` + +### [paddle.nn.functional.dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/dropout_cn.html#dropout) + +```python +paddle.nn.functional.dropout(x, p=0.5, axis=None, training=True, mode='upscale_in_train', name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率。 | +| - | axis | 指定对输入 Tensor 进行 dropout 操作的轴,PyTorch 无此参数,Paddle 保持默认即可。 | +| training | training | 标记是否为训练阶段。 | +| - | mode | 丢弃单元的方式,PyTorch 无此参数,Paddle 保持默认即可。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout1d.md new file mode 100644 index 00000000000..ff17f73492b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout1d.md @@ -0,0 +1,26 @@ +## [ torch 参数更多 ]torch.nn.functional.dropout1d + +### [torch.nn.functional.dropout1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.dropout1d.html#torch.nn.functional.dropout1d) + +```python +torch.nn.functional.dropout1d(input, p=0.5, training=True, inplace=False) +``` + +### [paddle.nn.functional.dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/dropout_cn.html) + +```python +paddle.nn.functional.dropout(x, p=0.5, axis=None, training=True, mode='upscale_in_train', name=None) +``` + +PyTorch 对于 dropout1d/dropout2d/dropout3d,是将某个 Channel 以一定概率全部置 0,Paddle 是所有元素以一定概率置 0,但该差异一般不影响网络训练效果。 +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率,即丢弃概率。 | +| training | training | 标记是否为训练阶段。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | axis | 指定对输入 Tensor 进行 dropout 操作的轴,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | mode | 标记是否为训练阶段,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout2d.md new file mode 100644 index 00000000000..5f23ba933f8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout2d.md @@ -0,0 +1,25 @@ +## [ torch 参数更多 ]torch.nn.functional.dropout2d + +### [torch.nn.functional.dropout2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.dropout2d.html#torch.nn.functional.dropout2d) + +```python +torch.nn.functional.dropout2d(input, p=0.5, training=True, inplace=False) +``` + +### [paddle.nn.functional.dropout2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/dropout2d_cn.html) + +```python +paddle.nn.functional.dropout2d(x, p=0.5, training=True, data_format='NCHW', name=None) +``` + +PyTorch 对于 dropout1d/dropout2d/dropout3d,是将某个 Channel 以一定概率全部置 0,Paddle 是所有元素以一定概率置 0,但该差异一般不影响网络训练效果。 +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率,即丢弃概率。 | +| training | training | 标记是否为训练阶段。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | data_format | 指定输入的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout3d.md new file mode 100644 index 00000000000..805fc096ff7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.dropout3d.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.nn.functional.dropout3d + +### [torch.nn.functional.dropout3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.dropout3d.html#torch.nn.functional.dropout3d) + +```python +torch.nn.functional.dropout3d(input, p=0.5, training=True, inplace=False) +``` + +### [paddle.nn.functional.dropout3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/dropout3d_cn.html) + +```python +paddle.nn.functional.dropout3d(x, p=0.5, training=True, name=None) +``` + +PyTorch 对于 dropout1d/dropout2d/dropout3d,是将某个 Channel 以一定概率全部置 0,Paddle 是所有元素以一定概率置 0,但该差异一般不影响网络训练效果。 +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率,即丢弃概率。 | +| training | training | 标记是否为训练阶段。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu.md new file mode 100644 index 00000000000..4350edd0d13 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.functional.elu + +### [torch.nn.functional.elu](https://pytorch.org/docs/stable/generated/torch.nn.functional.elu.html#torch.nn.functional.elu) + +```python +torch.nn.functional.elu(input, alpha=1.0, inplace=False) +``` + +### [paddle.nn.functional.elu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/elu_cn.html) + +```python +paddle.nn.functional.elu(x, alpha=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| alpha | alpha | alpha 参数。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu_.md new file mode 100644 index 00000000000..314c5879b71 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.elu_.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.functional.elu_ + +### [torch.nn.functional.elu_](https://www.paddlepaddle.org.cn/documentation/docs/stable/api/paddle/nn/functional/elu__cn.html) + +```python +torch.nn.functional.elu_(input, alpha=1.0) +``` + +### [paddle.nn.functional.elu_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/relu__cn.html) + +```python +paddle.nn.functional.elu_(x, alpha=1.0, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| alpha | alpha | 表示 rule 激活公式中的超参数 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.embedding.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.embedding.md new file mode 100644 index 00000000000..b68a56ee675 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.embedding.md @@ -0,0 +1,27 @@ +## [torch 参数更多]torch.nn.functional.embedding + +### [torch.nn.functional.embedding](https://pytorch.org/docs/stable/generated/torch.nn.functional.embedding.html) + +```python +torch.nn.functional.embedding(input, weight, padding_idx=None, max_norm=None, norm_type=2.0, scale_grad_by_freq=False, sparse=False) +``` + +### [paddle.nn.functional.embedding](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/embedding_cn.html#embedding) + +```python +paddle.nn.functional.embedding(x, weight, padding_idx=None, sparse=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | -- | +| input | x | 输入 Tensor,仅参数名不同。 | +| weight | weight | 嵌入矩阵权重。 | +| padding_idx | padding_idx | 视为填充的下标,参数完全一致。 | +| max_norm | - | 重新归一化的最大范数,参数不一致,暂无转写方式。 | +| norm_type | - | Paddle 无此参数,参数不一致,暂无转写方式。 | +| scale_grad_by_freq | - | 按词频进行梯度缩放的比例,参数不一致,暂无转写方式。 | +| sparse | sparse | 是否使用稀疏更新。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fold.md new file mode 100644 index 00000000000..4690903b8fc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fold.md @@ -0,0 +1,36 @@ +## [ 仅参数名不一致 ]torch.nn.functional.fold + +### [torch.nn.functional.fold](https://pytorch.org/docs/stable/generated/torch.nn.functional.fold.html?highlight=functional+fold#torch.nn.functional.fold) + +```python +torch.nn.functional.fold(input, + output_size, + kernel_size, + dilation=1, + padding=0, + stride=1) +``` + +### [paddle.nn.functional.fold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/fold_cn.html) + +```python +paddle.nn.functional.fold(x, + output_sizes, + kernel_sizes, + strides=1, + paddings=0, + dilations=1, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| output_size | output_sizes | 表示输出 Tensor 的尺寸。 | +| kernel_size | kernel_sizes | 表示卷积核大小。 | +| dilation | dilations | 表示卷积膨胀的大小。 | +| padding | paddings | 表示每个维度的填充大小。 | +| stride | strides | 表示卷积核步长。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool2d.md new file mode 100644 index 00000000000..65973bb3bc5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool2d.md @@ -0,0 +1,50 @@ +## [ torch 参数更多 ]torch.nn.functional.fractional_max_pool2d + +### [torch.nn.functional.fractional_max_pool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.fractional_max_pool2d.html#torch-nn-functional-fractional-max-pool2d) + +```python +torch.nn.functional.fractional_max_pool2d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None) +``` + +### [paddle.nn.functional.fractional_max_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/fractional_max_pool2d_cn.html) + +```python +paddle.nn.functional.fractional_max_pool2d(x, output_size, kernel_size=None, random_u=None, return_mask=False, name=None) +``` + +PyTorch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。仅参数名不一致。 | +| kernel_size | kernel_size | 表示核大小。参数完全一致。 | +| output_size | output_size | 表示目标输出尺寸,PyTorch 为可选参数,Paddle 为必选参数,仅参数默认值不一致。PyTorch 的 output_size 与 output_ratio 输入二选一,如不输入 output_size,则必须输入 output_ratio,此时需要转写。转写方式与下文 output_ratio 一致。 | +| output_ratio | - | 表示目标输出比例。Paddle 无此参数,需要转写。 | +| return_indices | return_mask | 表示是否返回最大值索引。仅参数名不一致。 | +| _random_samples | random_u | 表示随机数。PyTorch 以列表形式的 Tensor 方式传入,Paddle 以 float 的方式传入,如果 PyTorch 的多个随机数相同,需要转写,如果 PyTorch 的多个随机数不同,暂无转写方式。 | + +### 转写示例 + +#### output_ratio:目标输出比例 + +```python +# 假设 intput 的 with=7, height=7, +# output_ratio = 0.75, 则目标 output 的 width = int(7*0.75) = 5, height = int(7*0.75) = 5 +# Pytorch 写法 +torch.nn.functional.fractional_max_pool2d(input, 2, output_ratio=[0.75, 0.75], return_indices=True) + +# Paddle 写法 +paddle.nn.functional.fractional_max_pool2d(x, output_size=[5, 5], kernel_size=2, return_mask=True) +``` + +#### _random_samples:随机数 + +```python +# Pytorch 写法 +torch.nn.functional.fractional_max_pool2d(input, 2, output_size=[3, 3], return_indices=True, _random_samples=torch.tensor([[[0.3, 0.3]]])) + +# Paddle 写法 +paddle.nn.functional.fractional_max_pool2d(x, output_size=[3, 3], kernel_size=2, return_mask=True, random_u=0.3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool3d.md new file mode 100644 index 00000000000..53acc8b4af7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.fractional_max_pool3d.md @@ -0,0 +1,50 @@ +## [ torch 参数更多 ]torch.nn.functional.fractional_max_pool3d + +### [torch.nn.functional.fractional_max_pool3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.fractional_max_pool3d.html#torch-nn-functional-fractional-max-pool3d) + +```python +torch.nn.functional.fractional_max_pool3d(input, kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None) +``` + +### [paddle.nn.functional.fractional_max_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/fractional_max_pool3d_cn.html) + +```python +paddle.nn.functional.fractional_max_pool3d(x, output_size, kernel_size=None, random_u=None, return_mask=False, name=None) +``` + +PyTorch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。仅参数名不一致。 | +| kernel_size | kernel_size | 表示核大小。参数完全一致。 | +| output_size | output_size | 表示目标输出尺寸,PyTorch 为可选参数,Paddle 为必选参数,仅参数默认值不一致。PyTorch 的 output_size 与 output_ratio 输入二选一,如不输入 output_size,则必须输入 output_ratio,此时需要转写。转写方式与下文 output_ratio 一致。 | +| output_ratio | - | 表示目标输出比例。Paddle 无此参数,需要转写。 | +| return_indices | return_mask | 表示是否返回最大值索引。仅参数名不一致。 | +| _random_samples | random_u | 表示随机数。PyTorch 以列表形式的 Tensor 方式传入,Paddle 以 float 的方式传入,如果 PyTorch 的多个随机数相同,需要转写,如果 PyTorch 的多个随机数不同,暂无转写方式。 | + +### 转写示例 + +#### output_ratio:目标输出比例 + +```python +# 假设 intput 的 depth=7, with=7, height=7, +# output_ratio = 0.75, 则目标 output 的 depth = int(7*0.75) = 5, width = int(7*0.75) = 5, height = int(7*0.75) = 5 +# Pytorch 写法 +torch.nn.functional.fractional_max_pool3d(input, 2, output_ratio=[0.75, 0.75, 0.75], return_indices=True) + +# Paddle 写法 +paddle.nn.functional.fractional_max_pool3d(x, output_size=[5, 5, 5], kernel_size=2, return_mask=True) +``` + +#### _random_samples:随机数 + +```python +# Pytorch 写法 +torch.nn.functional.fractional_max_pool3d(input, 2, output_size=[3, 3, 3], return_indices=True, _random_samples=torch.tensor([[[0.3, 0.3, 0.3]]])) + +# Paddle 写法 +paddle.nn.functional.fractional_max_pool3d(x, output_size=[3, 3, 3], kernel_size=2, return_mask=True, random_u=0.3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gaussian_nll_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gaussian_nll_loss.md new file mode 100644 index 00000000000..53c6974fba0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gaussian_nll_loss.md @@ -0,0 +1,26 @@ +## [仅参数名不一致]torch.nn.functional.gaussian_nll_loss + +### [torch.nn.functional.gaussian_nll_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.gaussian_nll_loss.html#torch.nn.functional.gaussian_nll_loss) + +```python +torch.nn.functional.gaussian_nll_loss(input, target, var, full=False, eps=1e-06, reduction='mean') +``` + +### [paddle.nn.functional.gaussian_nll_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/gaussian_nll_loss_cn.html#gaussian-nll-loss) + +```python +paddle.nn.functional.gaussian_nll_loss(input, label, variance, full=False, epsilon=1e-6, reduction='mean', name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ----------------------------------------------------------------- | +| input | input | 输入 Tensor。 | +| target | label | 输入 Tensor,仅参数名不一致。 | +| var | variance | 输入 Tensor,仅参数名不一致。 | +| full | full | 是否在损失计算中包括常数项。 | +| eps | epsilon | 用于限制 variance 的值,使其不会导致除 0 的出现,仅参数名不一致。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gelu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gelu.md new file mode 100644 index 00000000000..1e5280961cf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gelu.md @@ -0,0 +1,36 @@ +## [参数不一致]torch.nn.functional.gelu + +### [torch.nn.functional.gelu](https://pytorch.org/docs/stable/generated/torch.nn.functional.gelu.html#torch.nn.functional.gelu) + +```python +torch.nn.functional.gelu(input, approximate='none') +``` + +### [paddle.nn.functional.gelu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/gelu_cn.html) + +```python +paddle.nn.functional.gelu(x, approximate=False, name=None) +``` + +其中功能一致, 输入参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ------------------------------------------------------------------------------------ | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| approximate | approximate | 是否使用近似计算,PyTorch 取值 none 和 tanh,Paddle 取值为 bool 类型,需要转写。 | + +### 转写示例 + +#### approximate 参数:是否使用近似计算 + +```python +# PyTorch 写法: +y1 = torch.nn.functional.gelu(x, approximate='tanh') +y2 = torch.nn.functional.gelu(x, approximate='none') + +# Paddle 写法: +y1 = paddle.nn.functional.gelu(x, approximate=True) +y2 = paddle.nn.functional.gelu(x, approximate=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.glu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.glu.md new file mode 100644 index 00000000000..553e65baa75 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.glu.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.functional.glu + +### [torch.nn.functional.glu](https://pytorch.org/docs/stable/generated/torch.nn.functional.glu.html?highlight=glu#torch.nn.functional.glu) + +```python +torch.nn.functional.glu(input, dim=- 1) +``` + +### [paddle.nn.functional.glu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/glu_cn.html) + +```python +paddle.nn.functional.glu(x, axis=- 1, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示划分输入 Tensor 的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.grid_sample.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.grid_sample.md new file mode 100644 index 00000000000..2eab8453def --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.grid_sample.md @@ -0,0 +1,33 @@ +## [ 仅参数名不一致 ] torch.nn.functional.grid_sample + +### [torch.nn.functional.grid_sample](https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html?highlight=grid_sample#torch.nn.functional.grid_sample) + +```python +torch.nn.functional.grid_sample(input, + grid, + mode='bilinear', + padding_mode='zeros', + align_corners=None) +``` + +### [paddle.nn.functional.grid_sample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/grid_sample_cn.html) + +```python +paddle.nn.functional.grid_sample(x, + grid, + mode='bilinear', + padding_mode='zeros', + align_corners=True, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| grid | grid | 输入网格数据张量。 | +| mode | mode | 指定插值方式。 | +| padding_mode | padding_mode | 指定超出边界的填充方式。 | +| align_corners | align_corners | 是否将角落的点进行中心对齐。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.group_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.group_norm.md new file mode 100644 index 00000000000..04e40cc61e3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.group_norm.md @@ -0,0 +1,25 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.group_norm + +### [torch.nn.functional.group_norm](https://pytorch.org/docs/stable/generated/torch.nn.functional.group_norm.html#torch.nn.functional.group_norm) + +```python +torch.nn.functional.group_norm(input, num_groups, weight=None, bias=None, eps=1e-05) +``` + +### [paddle.nn.functional.group_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/group_norm_cn.html#group-norm) +```python +paddle.nn.functional.group_norm(x, num_groups, epsilon=1e-05, weight=None, bias=None, data_format='NCHW', name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| num_groups | num_groups | 输入的通道数。 | +| weight | weight | 权重的 Tensor。 | +| bias | bias | 偏置的 Tensor。 | +| eps | epsilon | 为防止方差除零增加的一个很小的值,仅参数名不一致。 | +| - | data_format | 输入的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gumbel_softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gumbel_softmax.md new file mode 100644 index 00000000000..b7828d74e20 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.gumbel_softmax.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.nn.functional.gumbel_softmax + +### [torch.nn.functional.gumbel_softmax](https://pytorch.org/docs/stable/generated/torch.nn.functional.gumbel_softmax.html#torch.nn.functional.gumbel_softmax) + +```python +torch.nn.functional.gumbel_softmax(logits, tau=1, hard=False, eps=1e-10, dim=- 1) +``` + +### [paddle.nn.functional.gumbel_softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/gumbel_softmax_cn.html) + +```python +paddle.nn.functional.gumbel_softmax(x, temperature=1.0, hard=False, axis=- 1, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------------- | +| logits | x | 一个 N-D Tensor,前 N-1 维用于独立分布 batch 的索引,最后一维表示每个类别的概率,仅参数名不一致。 | +| tau | temperature | 大于 0 的标量,仅参数名不一致。 | +| hard | hard | 如果是 True,返回离散的 one-hot 向量。如果是 False,返回软样本。 | +| eps | - | eps 参数,PyTorch 已废弃不会生效,Paddle 无此参数,对网络无影响,可直接删除。 | +| dim | axis | 按照维度 axis 计算 softmax,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardshrink.md new file mode 100644 index 00000000000..433bbc696ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardshrink.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.nn.functional.hardshrink + +### [torch.nn.functional.hardshrink](https://pytorch.org/docs/stable/generated/torch.nn.functional.hardshrink.html?highlight=hardshrink#torch.nn.functional.hardshrink) + +```python +torch.nn.functional.hardshrink(input, + lambd=0.5) +``` + +### [paddle.nn.functional.hardshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hardshrink_cn.html) + +```python +paddle.nn.functional.hardshrink(x, + threshold=0.5, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| lambd | threshold | 表示 hard_shrink 激活计算公式中的 threshold 值 ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardsigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardsigmoid.md new file mode 100644 index 00000000000..88360ab6825 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardsigmoid.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.hardsigmoid + +### [torch.nn.functional.hardsigmoid](https://pytorch.org/docs/stable/generated/torch.nn.functional.hardsigmoid.html) + +```python +torch.nn.functional.hardsigmoid(input, inplace=False) +``` + +### [paddle.nn.functional.hardsigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/hardsigmoid_cn.html#hardsigmoid) + +```python +paddle.nn.functional.hardsigmoid(x, slope=0.1666667, offset=0.5, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅 paddle 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| - | slope | hardsigmoid 的斜率,PyTorch 无此参数,Paddle 保持默认即可。| +| - | offset | hardsigmoid 的截距,PyTorch 无此参数,Paddle 保持默认即可。| +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardswish.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardswish.md new file mode 100644 index 00000000000..405fb9c5132 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardswish.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.nn.functional.hardswish + +### [torch.nn.functional.hardswish](https://pytorch.org/docs/stable/generated/torch.nn.functional.hardswish.html#torch.nn.functional.hardswish) + +```python +torch.nn.functional.hardswish(input, inplace=False) +``` + +### [paddle.nn.functional.hardswish](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hardswish_cn.html) + +```python +paddle.nn.functional.hardswish(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh.md new file mode 100644 index 00000000000..97c64e6c0b2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.nn.functional.hardtanh + +### [torch.nn.functional.hardtanh](https://pytorch.org/docs/stable/generated/torch.nn.functional.hardtanh.html#torch.nn.functional.hardtanh) + +```python +torch.nn.functional.hardtanh(input, min_val=- 1.0, max_val=1.0, inplace=False) +``` + +### [paddle.nn.functional.hardtanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hardtanh_cn.html) + +```python +paddle.nn.functional.hardtanh(x, min=-1.0, max=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| min_val | min | hardtanh 激活计算公式中的 min 值,仅参数名不一致。 | +| max_val | max | hardtanh 激活计算公式中的 max 值,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh_.md new file mode 100644 index 00000000000..60c5afea788 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hardtanh_.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.nn.functional.hardtanh_ + +### [torch.nn.functional.hardtanh_](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-tensor-methods) + +```python +torch.nn.functional.hardtanh_(input, min_val=-1, max_val=1) +``` + +### [paddle.nn.functional.hardtanh_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hardtanh_cn.html) + +```python +paddle.nn.functional.hardtanh_(x, min=-1.0, max=1.0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| min_val | min | hardtanh 激活计算公式中的 min 值,仅参数名不一致。 | +| max_val | max | hardtanh 激活计算公式中的 max 值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hinge_embedding_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hinge_embedding_loss.md new file mode 100644 index 00000000000..bca40ddab34 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.hinge_embedding_loss.md @@ -0,0 +1,43 @@ +## [torch 参数更多]torch.nn.functional.hinge_embedding_loss + +### [torch.nn.functional.hinge_embedding_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.hinge_embedding_loss.html#torch.nn.functional.hinge_embedding_loss) + +```python +torch.nn.functional.hinge_embedding_loss(input, target, margin=1.0, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.hinge_embedding_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/hinge_embedding_loss_cn.html) + +```python +paddle.nn.functional.hinge_embedding_loss(input, label, margin=1.0, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------------------------------ | +| input | input | 输入的 Tensor。 | +| target | label | 标签,仅参数名不一致。 | +| margin | margin | 当 label 为 -1 时,该值决定了小于 margin 的 input 才需要纳入 hinge embedding loss 的计算。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.huber_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.huber_loss.md new file mode 100644 index 00000000000..d44889a10be --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.huber_loss.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.nn.functional.huber_loss + +### [torch.nn.functional.huber_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.huber_loss.html#torch.nn.functional.huber_loss) + +```python +torch.nn.functional.huber_loss(input, target, reduction='mean', delta=1.0) +``` + +### [paddle.nn.functional.smooth_l1_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/smooth_l1_loss_cn.html) + +```python +paddle.nn.functional.smooth_l1_loss(input, label, reduction='mean', delta=1.0, name=None) +``` + +功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ----------------------------------------- | +| input | input | 输入 Tensor。 | +| target | label | 输入 input 对应的标签值,仅参数名不一致。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | +| delta | delta | 损失的阈值参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md new file mode 100644 index 00000000000..52a56946aa8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.instance_norm.md @@ -0,0 +1,38 @@ +## [ 参数不一致 ]torch.nn.functional.instance_norm + +### [torch.nn.functional.instance_norm](https://pytorch.org/docs/stable/generated/torch.nn.functional.instance_norm.html#torch.nn.functional.instance_norm) + +```python +torch.nn.functional.instance_norm(input, running_mean=None, running_var=None, weight=None, bias=None, use_input_stats=True, momentum=0.1, eps=1e-05) +``` + +### [paddle.nn.functional.instance_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/instance_norm_cn.html#instance-norm) +```python +paddle.nn.functional.instance_norm(x, running_mean=None, running_var=None, weight=None, bias=None, training=False, eps=1e-05, momentum=0.9, use_input_stats=True, data_format='NCHW', name=None) +``` + +其中 PyTorch 与 Paddle 参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| running_mean | running_mean | 均值的 Tensor | +| running_var | running_var | 方差的 Tensor | +| weight | weight | 权重的 Tensor | +| bias | bias | 偏置的 Tensor | +| eps | eps | 为了数值稳定加在分母上的值 | +| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写 | +| - | training | 是否可训练。 PyTorch 无此参数。保持默认即可。 | +| - | data_format | 指定输入数据格式。 PyTorch 无此参数。保持默认即可。 | + + +### 转写示例 +#### momentum:此值用于计算 moving_mean 和 moving_var +```python +# PyTorch 写法 +torch.nn.functional.instance_norm(input=input, running_mean=running_mean, running_var=running_var, momentum=0.1) + +# Paddle 写法 +paddle.nn.functional.instance_norm(x=input, running_mean=running_mean, running_var=running_var, momentum=0.9) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.interpolate.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.interpolate.md new file mode 100644 index 00000000000..2c84774e082 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.interpolate.md @@ -0,0 +1,29 @@ +## [torch 参数更多]torch.nn.functional.interpolate + +### [torch.nn.functional.interpolate](https://pytorch.org/docs/stable/generated/torch.nn.functional.interpolate.html#torch.nn.functional.interpolate) + +```python +torch.nn.functional.interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None, antialias=False) +``` + +### [paddle.nn.functional.interpolate](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/interpolate_cn.html) + +```python +paddle.nn.functional.interpolate(x, size=None, scale_factor=None, mode='nearest', align_corners=False, align_mode=0, data_format=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------------------- | ------------- | ------------------------------------------------------------------------------------------------------ | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| size | size | 输出 Tensor 形状。 | +| scale_factor | scale_factor | 输入的高度或宽度的乘数因子。 | +| mode | mode | 插值方法。 | +| align_corners | align_corners | 一个可选的 bool 型参数,如果为 True,则将输入和输出张量的 4 个角落像素的中心对齐,并保留角点像素的值。 | +| recompute_scale_factor | - | 是否重新计算 scale_factor,Paddle 无此参数,暂无转写方式。 | +| antialias | - | 是否使用 anti-aliasing,Paddle 无此参数,暂无转写方式。 | +| - | align_mode | 双线性插值的可选项,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 指定输入的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md new file mode 100644 index 00000000000..c476ce903ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.kl_div.md @@ -0,0 +1,89 @@ +## [torch 参数更多]torch.nn.functional.kl_div + +### [torch.nn.functional.kl_div](https://pytorch.org/docs/stable/generated/torch.nn.functional.kl_div.html?highlight=kl_div#torch.nn.functional.kl_div) + +```python +torch.nn.functional.kl_div(input, + target, + size_average=None, + reduce=None, + reduction='mean', + log_target=False) +``` + +### [paddle.nn.functional.kl_div](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/kl_div_cn.html) + +```python +paddle.nn.functional.kl_div(input, + label, + reduction='mean') +``` + +其中 PyTorch 相比 Paddle 支持更多的参数,具体如下: + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------ | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示对输出结果的计算方式。 | +| log_target | - | 指定目标是否为 log 空间,Paddle 无此参数,暂无转写方式。 | + +### 转写示例 + +#### size_average:是否对损失进行平均或求和 +```python +# PyTorch 写法 (size_average 为‘True’时) +torch.nn.functional.kl_div(a, target, size_average=True) + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (size_average 为‘False’时) +torch.nn.functional.kl_div(a, target, size_average=False) + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='sum') +``` + +#### reduce:是否对损失进行平均或求和 +```python +# PyTorch 写法 (reduce 为‘True’时) +torch.nn.functional.kl_div(a, target, reduce=True) + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduce 为‘False’时) +torch.nn.functional.kl_div(a, target, reduce=False) + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='sum') +``` + +#### reduction:输出结果的计算方式 +```python +# PyTorch 写法 (reduction 为‘none’时) +torch.nn.functional.kl_div(a, target, reduction='none') + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='none') + +# PyTorch 写法 (reduction 为‘mean’时) +torch.nn.functional.kl_div(a, target, reduction='mean') + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduction 为‘sum’时) +torch.nn.functional.kl_div(a, target, reduction='sum') + +# Paddle 写法 +paddle.nn.functional.kl_div(logit=a, label=target, + reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.l1_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.l1_loss.md new file mode 100644 index 00000000000..e16f3f68c63 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.l1_loss.md @@ -0,0 +1,84 @@ +## [torch 参数更多] torch.nn.functional.l1_loss + +### [torch.nn.functional.l1_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.l1_loss.html?highlight=l1_loss#torch.nn.functional.l1_loss) + +```python +torch.nn.functional.l1_loss(input, target, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.l1_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/l1_loss_cn.html) + +```python +paddle.nn.functional.l1_loss(input, label, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示输入的 Tensor。 +| target | label | 标签,和 input 具有相同的维度,仅参数名不一致。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。Paddle 无此参数,需要转写。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。Paddle 无此参数,需要转写。 | +| reduction | reduction | 输出结果的计算方式 | + +### 转写示例 +#### size_average:是否对损失进行平均或求和 +```python +# PyTorch 写法 (size_average 为‘True’时) +torch.nn.functional.l1_loss(a, target, size_average=True) + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (size_average 为‘False’时) +torch.nn.functional.l1_loss(a, target, size_average=False) + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='sum') +``` + +#### reduce:是否对损失进行平均或求和 +```python +# PyTorch 写法 (reduce 为‘True’时) +torch.nn.functional.l1_loss(a, target, reduce=True) + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduce 为‘False’时) +torch.nn.functional.l1_loss(a, target, reduce=False) + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='sum') +``` + +#### reduction:输出结果的计算方式 +```python +# PyTorch 写法 (reduction 为‘none’时) +torch.nn.functional.l1_loss(a, target, reduction='none') + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='none') + +# PyTorch 写法 (reduction 为‘mean’时) +torch.nn.functional.l1_loss(a, target, reduction='mean') + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='mean') + +# PyTorch 写法 (reduction 为‘sum’时) +torch.nn.functional.l1_loss(a, target, reduction='sum') + +# Paddle 写法 +paddle.nn.functional.l1_loss(logit=a, label=target, + reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.layer_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.layer_norm.md new file mode 100644 index 00000000000..53c5113fd00 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.layer_norm.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.nn.functional.layer_norm + +### [torch.nn.functional.layer_norm](https://pytorch.org/docs/stable/generated/torch.nn.functional.layer_norm.html#torch.nn.functional.layer_norm) + +```python +torch.nn.functional.layer_norm(input, normalized_shape, weight=None, bias=None, eps=1e-05) +``` + +### [paddle.nn.functional.layer_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/layer_norm_cn.html#layer-norm) +```python +paddle.nn.functional.layer_norm(x, normalized_shape, weight=None, bias=None, epsilon=1e-05, name=None) +``` + +两者功能相同,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| normalized_shape | normalized_shape | 需规范化的 shape | +| weight | weight | 权重的 Tensor | +| bias | bias | 偏置的 Tensor | +| eps | epsilon | 为了数值稳定加在分母上的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu.md new file mode 100644 index 00000000000..6df291d9829 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.functional.leaky_relu + +### [torch.nn.functional.leaky_relu](https://pytorch.org/docs/stable/generated/torch.nn.functional.leaky_relu.html#torch.nn.functional.leaky_relu) + +```python +torch.nn.functional.leaky_relu(input, negative_slope=0.01, inplace=False) +``` + +### [paddle.nn.functional.leaky_relu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/leaky_relu_cn.html) + +```python +paddle.nn.functional.leaky_relu(x, negative_slope=0.01, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | -------------- | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| negative_slope | negative_slope | x<0 时的斜率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu_.md new file mode 100644 index 00000000000..9bccbe95da2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.leaky_relu_.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.nn.functional.leaky_relu_ + +### [torch.nn.functional.leaky_relu_](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-tensor-methods) + +```python +torch.nn.functional.leaky_relu_(input, negative_slope=0.01) +``` + +### [paddle.nn.functional.leaky_relu_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/leaky_relu_cn.html) + +```python +paddle.nn.functional.leaky_relu_(x, negative_slope=0.01) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | -------------- | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| negative_slope | negative_slope | x<0 时的斜率。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.linear.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.linear.md new file mode 100644 index 00000000000..2a5bc04005b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.linear.md @@ -0,0 +1,37 @@ +## [ 参数不一致 ]torch.nn.functional.linear + +### [torch.nn.functional.linear](https://pytorch.org/docs/stable/generated/torch.nn.functional.linear.html?highlight=linear#torch.nn.functional.linear) + +```python +torch.nn.functional.linear(input, + weight, + bias=None) +``` + +### [paddle.nn.functional.linear](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/linear_cn.html) + +```python +paddle.nn.functional.linear(x, + weight, + bias=None, + name=None) +``` + +两者功能一致,`weight` 参数的 `shape` 不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| weight | weight | 表示权重 Tensor, PyTorch weight 参数的 shape 为 (out_features,in_features),Paddle weight 参数的 shape 为 (in_features, out_features),两者互为转置,需要转写。 | +| bias | bias | 表示偏重 Tensor 。 | + +### 转写示例 +#### weight +```python +# PyTorch 写法 +result = F.linear(x, weight=weight) + +# Paddle 写法 +result = F.linear(x, weight=weight.T) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.local_response_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.local_response_norm.md new file mode 100644 index 00000000000..d85cb1034da --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.local_response_norm.md @@ -0,0 +1,35 @@ +## [ 仅参数名不一致 ]torch.nn.functional.local_response_norm + +### [torch.nn.functional.local_response_norm](https://pytorch.org/docs/stable/generated/torch.nn.functional.local_response_norm.html?highlight=local_response_norm#torch.nn.functional.local_response_norm) + +```python +torch.nn.functional.local_response_norm(input, + size, + alpha=0.0001, + beta=0.75, + k=1.0) +``` + +### [paddle.nn.functional.local_response_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/local_response_norm_cn.html) + +```python +paddle.nn.functional.local_response_norm(x, + size, + alpha=1e-4, + beta=0.75, + k=1., + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| size | size | 表示累加的通道数 。 | +| alpha | alpha | 表示缩放参数 。 | +| beta | beta | 表示指数 。 | +| k | k | 表示位移。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_sigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_sigmoid.md new file mode 100644 index 00000000000..2e54f69452b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_sigmoid.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.functional.logsigmoid + +### [torch.nn.functional.logsigmoid](https://pytorch.org/docs/stable/generated/torch.nn.functional.logsigmoid.html?highlight=logsigmoid#torch.nn.functional.logsigmoid) + +```python +torch.nn.functional.logsigmoid(input) +``` + +### [paddle.nn.functional.log_sigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/log_sigmoid_cn.html) + +```python +paddle.nn.functional.log_sigmoid(x, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_softmax.md new file mode 100644 index 00000000000..5f55ef8df5b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.log_softmax.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.nn.functional.log_softmax + +### [torch.nn.functional.log_softmax](https://pytorch.org/docs/stable/generated/torch.nn.functional.log_softmax.html#torch.nn.functional.log_softmax) + +```python +torch.nn.functional.log_softmax(input, dim=None, _stacklevel=3, dtype=None) +``` + +### [paddle.nn.functional.log_softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/log_softmax_cn.html) + +```python +paddle.nn.functional.log_softmax(x, axis=- 1, dtype=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| dim | axis | 指定对输入 x 进行运算的轴,仅参数名不一致。 | +| \_stacklevel | - | \_stacklevel 参数,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | dtype | 输入 Tensor 的数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.margin_ranking_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.margin_ranking_loss.md new file mode 100644 index 00000000000..4ee83010b42 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.margin_ranking_loss.md @@ -0,0 +1,54 @@ +## [torch 参数更多 ]torch.nn.functional.margin_ranking_loss + +### [torch.nn.functional.margin_ranking_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.margin_ranking_loss.html?highlight=margin_ranking_loss#torch.nn.functional.margin_ranking_loss) + +```python +torch.nn.functional.margin_ranking_loss(input1, + input2, + target, + margin=0, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.functional.margin_ranking_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/margin_ranking_loss_cn.html) + +```python +paddle.nn.functional.margin_ranking_loss(input, + other, + label, + margin=0.0, + reduction='mean', + name=None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input1 | input | 表示第一个输入的 Tensor ,仅参数名不一致。 | +| input2 | other | 表示第二个输入的 Tensor ,仅参数名不一致。 | +| target | label | 表示训练数据的标签 Tensor ,仅参数名不一致。 | +| margin | margin | 表示用于加和的 margin 值 。 | +| size_average | - | 已弃用 。 | +| reduce | - | 已弃用 。 | +| reduction | reduction | 表示应用于输出结果的计算方式 。 | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool1d.md new file mode 100644 index 00000000000..ab93b4da376 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool1d.md @@ -0,0 +1,27 @@ +## [torch 参数更多]torch.nn.functional.max_pool1d + +### [torch.nn.functional.max_pool1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_pool1d.html#torch.nn.functional.max_pool1d) + +```python +torch.nn.functional.max_pool1d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, return_indices=False) +``` + +### [paddle.nn.functional.max_pool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool1d_cn.html) + +```python +paddle.nn.functional.max_pool1d(x, kernel_size, stride=None, padding=0, return_mask=False, ceil_mode=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------ | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool2d.md new file mode 100644 index 00000000000..8f89ce64b93 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool2d.md @@ -0,0 +1,28 @@ +## [ torch 参数更多 ]torch.nn.functional.max_pool2d + +### [torch.nn.functional.max_pool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_pool2d.html#torch.nn.functional.max_pool2d) + +```python +torch.nn.functional.max_pool2d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, return_indices=False) +``` + +### [paddle.nn.functional.max_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool2d_cn.html) + +```python +paddle.nn.functional.max_pool2d(x, kernel_size, stride=None, padding=0, ceil_mode=False, return_mask=False, data_format='NCHW', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool3d.md new file mode 100644 index 00000000000..370208d4570 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_pool3d.md @@ -0,0 +1,28 @@ +## [torch 参数更多]torch.nn.functional.max_pool3d + +### [torch.nn.functional.max_pool3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_pool3d.html#torch.nn.functional.max_pool3d) + +```python +torch.nn.functional.max_pool3d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False, return_indices=False) +``` + +### [paddle.nn.functional.max_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool3d_cn.html) + +```python +paddle.nn.functional.max_pool3d(x, kernel_size, stride=None, padding=0, ceil_mode=False, return_mask=False, data_format="NCDHW", name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool1d.md new file mode 100644 index 00000000000..595207f82a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool1d.md @@ -0,0 +1,48 @@ +## [ 参数不一致 ]torch.nn.functional.max_unpool1d + +### [torch.nn.functional.max_unpool1d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_unpool1d.html?highlight=max_unpool1d#torch.nn.functional.max_unpool1d) + +```python +torch.nn.functional.max_unpool1d(input, + indices, + kernel_size, + stride=None, + padding=0, + output_size=None) +``` + +### [paddle.nn.functional.max_unpool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_unpool1d_cn.html) + +```python +paddle.nn.functional.max_unpool1d(x, + indices, + kernel_size, + stride=None, + padding=0, + data_format='NCL', + output_size=None, + name=None) +``` + +其中 Paddle 和 PyTorch 的`indices`参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| indices | indices | 表示索引下标,PyTorch 数据类型为 int64, Paddle 数据类型为 int32,需要转写。 | +| kernel_size | kernel_size | 表示滑动窗口大小。 | +| stride | stride | 表示步长。 | +| padding | padding | 表示填充大小。 | +| output_size | output_size | 表示目标输出尺寸。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | + +### 转写示例 +#### indices:索引下标 +```python +# PyTorch 写法 +result = F.max_unpool1d(x, indices, kernel_size=2, padding=0) + +# Paddle 写法 +result = F.max_unpool1d(x, indices.astype('int32'), kernel_size=2, padding=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool2d.md new file mode 100644 index 00000000000..dd0e11882c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool2d.md @@ -0,0 +1,48 @@ +## [ 参数不一致 ]torch.nn.functional.max_unpool2d + +### [torch.nn.functional.max_unpool2d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_unpool2d.html?highlight=max_unpool2d#torch.nn.functional.max_unpool2d) + +```python +torch.nn.functional.max_unpool2d(input, + indices, + kernel_size, + stride=None, + padding=0, + output_size=None) +``` + +### [paddle.nn.functional.max_unpool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_unpool2d_cn.html) + +```python +paddle.nn.functional.max_unpool2d(x, + indices, + kernel_size, + stride=None, + padding=0, + data_format='NCHW', + output_size=None, + name=None) +``` + +其中 Paddle 和 PyTorch 的`indices`参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| indices | indices | 表示索引下标,PyTorch 数据类型为 int64, Paddle 数据类型为 int32,需要转写。 | +| kernel_size | kernel_size | 表示滑动窗口大小。 | +| stride | stride | 表示步长。 | +| padding | padding | 表示填充大小。 | +| output_size | output_size | 表示目标输出尺寸。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | + +### 转写示例 +#### indices:索引下标 +```python +# PyTorch 写法 +result = F.max_unpool2d(x, indices, kernel_size=2, padding=0) + +# Paddle 写法 +result = F.max_unpool2d(x, indices.astype('int32'), kernel_size=2, padding=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool3d.md new file mode 100644 index 00000000000..f4e7d086ac9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.max_unpool3d.md @@ -0,0 +1,48 @@ +## [ 参数不一致 ]torch.nn.functional.max_unpool3d + +### [torch.nn.functional.max_unpool3d](https://pytorch.org/docs/stable/generated/torch.nn.functional.max_unpool3d.html?highlight=max_unpool3d#torch.nn.functional.max_unpool3d) + +```python +torch.nn.functional.max_unpool3d(input, + indices, + kernel_size, + stride=None, + padding=0, + output_size=None) +``` + +### [paddle.nn.functional.max_unpool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_unpool3d_cn.html) + +```python +paddle.nn.functional.max_unpool3d(x, + indices, + kernel_size, + stride=None, + padding=0, + data_format='NCDHW', + output_size=None, + name=None) +``` + +其中 Paddle 和 PyTorch 的`indices`参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| indices | indices | 表示索引下标,PyTorch 数据类型为 int64, Paddle 数据类型为 int32,需要转写。 | +| kernel_size | kernel_size | 表示滑动窗口大小。 | +| stride | stride | 表示步长。 | +| padding | padding | 表示填充大小。 | +| output_size | output_size | 表示目标输出尺寸。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | + +### 转写示例 +#### indices:索引下标 +```python +# PyTorch 写法 +result = F.max_unpool3d(x, indices, kernel_size=2, padding=0) + +# Paddle 写法 +result = F.max_unpool3d(x, indices.astype('int32'), kernel_size=2, padding=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mish.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mish.md new file mode 100644 index 00000000000..8029a7cc3c7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mish.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ]torch.nn.functional.mish + +### [torch.nn.functional.mish](https://pytorch.org/docs/stable/generated/torch.nn.functional.mish.html?highlight=torch+nn+functional+mish#torch.nn.functional.mish) + +```python +torch.nn.functional.mish(input, + inplace=False) +``` + +### [paddle.nn.functional.mish](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/mish_cn.html) + +```python +paddle.nn.functional.mish(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,主要功能为节省显存,一般对网络训练影响不大,Paddle 无此参数,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mse_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mse_loss.md new file mode 100644 index 00000000000..4b5351ba1d7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.mse_loss.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.nn.functional.mse_loss + +### [torch.nn.functional.mse_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.mse_loss.html?highlight=mse_loss#torch.nn.functional.mse_loss) + +```python +torch.nn.functional.mse_loss(input, + target, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.functional.mse_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/mse_loss_cn.html) + +```python +paddle.nn.functional.mse_loss(input, + label, + reduction='mean', + name=None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示预测的 Tensor 。 | +| target | label | 表示真实的 Tensor 。 | +| size_average | - | 已弃用 。 | +| reduce | - | 已弃用 。 | +| reduction | reduction | 表示应用于输出结果的计算方式 。 | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multi_margin_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multi_margin_loss.md new file mode 100644 index 00000000000..d2a370a9917 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multi_margin_loss.md @@ -0,0 +1,46 @@ +## [ torch 参数更多 ]torch.nn.functional.multi_margin_loss + +### [torch.nn.functional.multi\_margin\_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.multi_margin_loss.html) + +```python +torch.nn.functional.multi_margin_loss(input, target, p=1, margin=1, weight=None, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.multi\_margin\_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/multi_margin_loss_cn.html#multi-margin-loss) + +```python +paddle.nn.functional.multi_margin_loss(input, label, p=1, margin=1.0, weight=None, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -- | +| input | input | 输入 Tensor。 | +| target | label | 标签 Tensor,仅参数名不一致。 | +| p | p | 手动指定范数。| +| margin | margin | 手动指定间距。 | +| weight | weight | 手动指定每个 batch 二值交叉熵的权重。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average、reduce +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multilabel_soft_margin_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multilabel_soft_margin_loss.md new file mode 100644 index 00000000000..57889db47ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.multilabel_soft_margin_loss.md @@ -0,0 +1,44 @@ +## [ torch 参数更多 ]torch.nn.functional.multilabel_soft_margin_loss + +### [torch.nn.functional.multilabel\_soft\_margin\_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.multilabel_soft_margin_loss.html) + +```python +torch.nn.functional.multilabel_soft_margin_loss(input, target, weight=None, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.multi\_label\_soft\_margin\_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/multi_label_soft_margin_loss_cn.html#multi-label-soft-margin-loss) + +```python +paddle.nn.functional.multi_label_soft_margin_loss(input, label, weight=None, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -- | +| input | input | 输入 Tensor。 | +| target | label | 标签 Tensor,仅参数名不一致。 | +| weight | weight | 手动指定每个 batch 二值交叉熵的权重。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average、reduce +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.nll_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.nll_loss.md new file mode 100644 index 00000000000..eb4b63288bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.nll_loss.md @@ -0,0 +1,53 @@ +## [ torch 参数更多 ]torch.nn.functional.nll_loss + +### [torch.nn.functional.nll_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.nll_loss.html#torch-nn-functional-nll-loss) + +```python +torch.nn.functional.nll_loss(input, + target, + weight=None, + size_average=None, + ignore_index=- 100, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.functional.nll_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/nll_loss_cn.html#nll-loss) + +```python +paddle.nn.functional.nll_loss(input, + label, + weight=None, + ignore_index=-100, + reduction='mean', + name=None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 输入 Tensor | +| target | label | 输入 Tensor 对应的标签值,仅参数名不一致。 | +| size_average | - | 已弃用 | +| weight | weight | 手动指定每个类别的权重 | +| ignore_index | ignore_index | 指定一个忽略的标签值,此标签值不参与计算 | +| reduce | - | 已弃用 | +| reduction | reduction | 表示应用于输出结果的规约方式,可选值有:'none', 'mean', 'sum' | + +### 转写示例 +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.normalize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.normalize.md new file mode 100644 index 00000000000..968daae3797 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.normalize.md @@ -0,0 +1,42 @@ +## [torch 参数更多 ]torch.nn.functional.normalize + +### [torch.nn.functional.normalize](https://pytorch.org/docs/stable/generated/torch.nn.functional.normalize.html?highlight=normalize#torch.nn.functional.normalize) + +```python +torch.nn.functional.normalize(input, + p=2.0, + dim=1, + eps=1e-12, + out=None) +``` + +### [paddle.nn.functional.normalize](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/normalize_cn.html) + +```python +paddle.nn.functional.normalize(x, + p=2, + axis=1, + epsilon=1e-12, + name=None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输出 Tensor 的 size 。 | +| p | p | 表示范数公式中的指数值 。 | +| dim | axis | 表示要进行归一化的轴 。 | +| eps | epsilon | 表示添加到分母上的值 。 | +| out | - | 表示输出 Tensor 。 | + +### 转写示例 +#### out: 指定输出 +```python +# PyTorch 写法 +torch.nn.functional.normalize(x, out=y) + +# Paddle 写法 +y = paddle.nn.functional.normalize(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.one_hot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.one_hot.md new file mode 100644 index 00000000000..1c014cd8025 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.one_hot.md @@ -0,0 +1,45 @@ +## [ 参数不一致 ]torch.nn.functional.one_hot + +### [torch.nn.functional.one_hot](https://pytorch.org/docs/stable/generated/torch.nn.functional.one_hot.html?highlight=one_hot#torch.nn.functional.one_hot) + +```python +torch.nn.functional.one_hot(tensor, + num_classes=- 1) +``` + +### [paddle.nn.functional.one_hot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/one_hot_cn.html) + +```python +paddle.nn.functional.one_hot(x, + num_classes, + name=None) +``` + +两者功能一致,但 Paddle 的 num_classes 没有指定默认值,需要手动指定,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | x | 表示输入的 Tensor 。 | +| num_classes | num_classes | 表示一个 one-hot 向量的长度, Paddle 无默认值,必须显式指定,需要转写。 | +| 返回值 | 返回值 | PyTorch 返回值类型为 int64,Paddle 返回值类型为 float32,需要转写。 | + +### 转写示例 +#### num_classes: one-hot 向量的长度 +```python +# PyTorch 写法 +y = torch.nn.functional.one_hot(x) + +# Paddle 写法 +y = paddle.nn.functional.one_hot(x, num_classes=x.max().item() + 1) +``` + +#### 返回值 +```python +# PyTorch 写法 +y = torch.nn.functional.one_hot(x, num_classes=2) + +# Paddle 写法 +y = paddle.nn.functional.one_hot(x, num_classes=2).astype('int64') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pad.md new file mode 100644 index 00000000000..e7ba14f81a5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pad.md @@ -0,0 +1,35 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.pad + +### [torch.nn.functional.pad](https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html) + +```python +torch.nn.functional.pad(input, + pad, + mode='constant', + value=None) +``` + +### [paddle.nn.functional.pad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/pad_cn.html#pad) + +```python +paddle.nn.functional.pad(x, + pad, + mode='constant', + value=0.0, + data_format='NCHW', + name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| pad | pad | 表示一个 one-hot 向量的长度 。 | +| mode | mode | 表示填充的模式。 | +| value | value | 表示填充的值,mode 为'constant'时有效 。 | +| - | data_format | 指定输入的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | + +在实际使用过程中,`data_format` 参数需要根据输入参数进行指定 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pairwise_distance.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pairwise_distance.md new file mode 100644 index 00000000000..22fe3877572 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pairwise_distance.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.nn.functional.pairwise_distance + +### [torch.nn.functional.pairwise\_distance](https://pytorch.org/docs/stable/generated/torch.nn.functional.pairwise_distance.html) + +```python +torch.nn.functional.pairwise_distance(x1, x2, p=2.0, eps=1e-6, keepdim=False) +``` + +### [paddle.nn.functional.pairwise\_distance](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/pairwise_distance_cn.html#pairwise-distance) + +```python +paddle.nn.functional.pairwise_distance(x, y, p=2., epsilon=1e-6, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| x1 | x | 输入 Tensor,仅参数名不一致。 | +| x2 | y | 输入 Tensor,仅参数名不一致。 | +| p | p | 指定 p 阶的范数。 | +| eps | epsilon | 添加到分母的一个很小值,避免发生除零错误。仅参数名不一致。 | +| keepdim | keepdim | 是否保留输出 Tensor 减少的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pdist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pdist.md new file mode 100644 index 00000000000..52e72be99a2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pdist.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.nn.functional.pdist + +### [torch.nn.functional.pdist](https://pytorch.org/docs/stable/generated/torch.nn.functional.pdist.html#torch.nn.functional.pdist) + +```python +torch.nn.functional.pdist(input, p=2) +``` + +### [paddle.nn.functional.pdist](https://github.com/PaddlePaddle/Paddle/blob/210442ec30e5038809865a6105dd38308d1df2e0/python/paddle/nn/functional/distance.py#L111) + +```python +paddle.nn.functional.pdist(x, p=2.0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| p | p | 计算 p-norm 距离的 p 参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_shuffle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_shuffle.md new file mode 100644 index 00000000000..84d15682857 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_shuffle.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.pixel_shuffle + +### [torch.nn.functional.pixel_shuffle](https://pytorch.org/docs/stable/generated/torch.nn.functional.pixel_shuffle.html?highlight=pixel_shuffle#torch.nn.functional.pixel_shuffle) + +```python +torch.nn.functional.pixel_shuffle(input, upscale_factor) +``` + +### [paddle.nn.functional.pixel_shuffle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/pixel_shuffle_cn.html) + +```python +paddle.nn.functional.pixel_shuffle(x, upscale_factor, data_format='NCHW', name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| downscale_factor | downscale_factor | 减小空间分辨率的减小因子。 | +| - | data_format | 指定输入张量格式, PyTorch 无此参数, Paddle 保持默认即可 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_unshuffle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_unshuffle.md new file mode 100644 index 00000000000..b85ba90f11f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.pixel_unshuffle.md @@ -0,0 +1,23 @@ +## [ 仅 paddle 参数更多 ] torch.nn.functional.pixel_unshuffle + +### [torch.nn.functional.pixel_unshuffle](https://pytorch.org/docs/stable/generated/torch.nn.functional.pixel_unshuffle.html?highlight=pixel_unshuffle#torch.nn.functional.pixel_unshuffle) + +```python +torch.nn.functional.pixel_unshuffle(input, downscale_factor) +``` + +### [paddle.nn.functional.pixel_unshuffle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/pixel_unshuffle_cn.html) + +```python +paddle.nn.functional.pixel_unshuffle(x, downscale_factor, data_format='NCHW', name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| downscale_factor | downscale_factor | 减小空间分辨率的减小因子。 | +| - | data_format | 指定输入张量格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.poisson_nll_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.poisson_nll_loss.md new file mode 100644 index 00000000000..9a39d396355 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.poisson_nll_loss.md @@ -0,0 +1,46 @@ +## [ torch 参数更多 ]torch.nn.functional.poisson_nll_loss + +### [torch.nn.functional.poisson\_nll\_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.poisson_nll_loss.html) + +```python +torch.nn.functional.poisson_nll_loss(input, target, log_input=True, full=False, size_average=None, eps=1e-08, reduce=None, reduction='mean') +``` + +### [paddle.nn.functional.poisson\_nll\_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/functional/poisson_nll_loss_cn.html#poisson-nll-loss) + +```python +paddle.nn.functional.poisson_nll_loss(input, label, log_input=True, full=False, epsilon=1e-8, reduction='mean', name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -- | +| input | input | 输入 Tensor。 | +| target | label | 标签 Tensor,仅参数名不一致。 | +| log_input | log_input | 输入是否为对数函数映射后结果。 | +| full | full | 是否在损失计算中包括 Stirling 近似项。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| eps | epsilon | 在 log_input 为 True 时使用的常数小量,仅参数名不一致。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average、reduce +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.prelu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.prelu.md new file mode 100644 index 00000000000..fae6eebce60 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.prelu.md @@ -0,0 +1,27 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.prelu + +### [torch.nn.functional.prelu](https://pytorch.org/docs/stable/generated/torch.nn.functional.prelu.html?highlight=prelu#torch.nn.functional.prelu) + +```python +torch.nn.functional.prelu(input, + weight) +``` + +### [paddle.nn.functional.prelu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/prelu_cn.html) + +```python +paddle.nn.functional.prelu(x, + weight, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | +| weight | weight | 表示激活公式中的可训练权重 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu.md new file mode 100644 index 00000000000..0ecc465459c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.nn.functional.relu + +### [torch.nn.functional.relu](https://pytorch.org/docs/stable/generated/torch.nn.functional.relu.html#torch.nn.functional.relu) + +```python +torch.nn.functional.relu(input, inplace=False) +``` + +### [paddle.nn.functional.relu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/relu_cn.html) + +```python +paddle.nn.functional.relu(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu6.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu6.md new file mode 100644 index 00000000000..496c7d1f081 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu6.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.functional.relu6 + +### [torch.nn.functional.relu6](https://pytorch.org/docs/stable/generated/torch.nn.functional.relu6.html?highlight=relu6#torch.nn.functional.relu6) + +```python +torch.nn.functional.relu6(input) +``` + +### [paddle.nn.functional.relu6](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/relu6_cn.html) + +```python +paddle.nn.functional.relu6(x, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu_.md new file mode 100644 index 00000000000..153f1b9eea4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.relu_.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.functional.relu_ + +### [torch.nn.functional.relu_](https://pytorch.org/docs/stable/generated/torch.nn.functional.relu_.html?highlight=relu_#torch.nn.functional.relu_) + +```python +torch.nn.functional.relu_(input) +``` + +### [paddle.nn.functional.relu_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/relu__cn.html) + +```python +paddle.nn.functional.relu_(x, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu.md new file mode 100644 index 00000000000..eb09a30ee29 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.nn.functional.rrelu + +### [torch.nn.functional.rrelu](https://pytorch.org/docs/stable/generated/torch.nn.functional.rrelu.html#torch.nn.functional.rrelu) + +```python +torch.nn.functional.rrelu(input, lower=1.0 / 8, upper=1.0 / 3, training=False, inplace=False) +``` + +### [paddle.nn.functional.rrelu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/rrelu_cn.html) + +```python +paddle.nn.functional.rrelu(x, lower=1. / 8., upper=1. / 3., training=True, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| lower | lower | 负值斜率的随机值范围下限。 | +| upper | upper | 负值斜率的随机值范围上限。 | +| training | training | 标记是否为训练阶段。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu_.md new file mode 100644 index 00000000000..182d7554cec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.rrelu_.md @@ -0,0 +1,24 @@ +## [ 仅参数默认值不一致 ]torch.nn.functional.rrelu_ + +### [torch.nn.functional.rrelu\_](https://pytorch.org/docs/stable/generated/torch.nn.functional.rrelu_.html) + +```python +torch.nn.functional.rrelu_(input, lower=1./8, upper=1./3, training=False) +``` + +### [paddle.nn.functional.rrelu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/rrelu_cn.html) + +```python +paddle.nn.functional.rrelu(x, lower=1./8., upper=1./3., training=True, name=None) +``` + +其中 PyTorch 和 Paddle 功能基本一致,前者会在不变更变量内存地址的情况下,直接改变变量的值,一般对网络训练结果影响不大。参数名与参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | -- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| lower | lower | 负值斜率的随机值范围下限。 | +| upper | upper | 负值斜率的随机值范围上限。 | +| training | training | 标记是否为训练阶段。参数默认值不一致, PyTorch 默认值为 `False`,Paddle 默认值为 `True`,Paddle 需保持与 PyTorch 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.selu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.selu.md new file mode 100644 index 00000000000..1cb53ec3b90 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.selu.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.nn.functional.selu + +### [torch.nn.functional.selu](https://pytorch.org/docs/stable/generated/torch.nn.functional.selu.html#torch.nn.functional.selu) + +```python +torch.nn.functional.selu(input, inplace=False) +``` + +### [paddle.nn.functional.selu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/selu_cn.html) + +```python +paddle.nn.functional.selu(x, scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | scale | selu 激活计算公式中的 scale 值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | alpha | selu 激活计算公式中的 alpha 值,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.sigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.sigmoid.md new file mode 100644 index 00000000000..5dd63b94199 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.sigmoid.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.functional.sigmoid + +### [torch.nn.functional.sigmoid](https://pytorch.org/docs/stable/generated/torch.nn.functional.sigmoid.html?highlight=sigmoid#torch.nn.functional.sigmoid) + +```python +torch.nn.functional.sigmoid(input) +``` + +### [paddle.nn.functional.sigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/sigmoid_cn.html) + +```python +paddle.nn.functional.sigmoid(x, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.silu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.silu.md new file mode 100644 index 00000000000..a1a78855b8b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.silu.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.functional.silu + +### [torch.nn.functional.silu](https://pytorch.org/docs/stable/generated/torch.nn.functional.silu.html) + +```python +torch.nn.functional.silu(input, inplace=False) +``` + +### [paddle.nn.functional.silu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/silu_cn.html#silu) + +```python +paddle.nn.functional.silu(x, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.smooth_l1_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.smooth_l1_loss.md new file mode 100644 index 00000000000..8a699aac659 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.smooth_l1_loss.md @@ -0,0 +1,99 @@ +## [ 参数不一致 ]torch.nn.functional.smooth_l1_loss + +### [torch.nn.functional.smooth_l1_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.smooth_l1_loss.html) + +```python +torch.nn.functional.smooth_l1_loss(input, + target, + size_average=None, + reduce=None, + reduction='mean', + beta=1.0) +``` + +### [paddle.nn.functional.smooth_l1_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/smooth_l1_loss_cn.html#smooth-l1-loss) + +```python +paddle.nn.functional.smooth_l1_loss(input, + label, + reduction='mean', + delta=1.0, + name=None) +``` + +两者功能一致,但 Paddle 的 `delta` 和 PyTorch 的 `beta` 参数在公式中用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 输入 Tensor | +| target | label | 输入 Tensor 对应的标签,仅参数名不一致。 | +| size_average | - | 已弃用 | +| reduce | - | 已弃用 | +| reduction | reduction | 表示应用于输出结果的规约方式,可选值有:'none', 'mean', 'sum' | +| beta | delta | SmoothL1Loss 损失的阈值参数 | + +Torch 中 Smooth L1 loss 的计算方式: + +$$ +\ell(x, y) = \left [l_1, ..., l_N\ \right ]^T +$$ + +其中: + +$$ +l_n = \begin{cases} +0.5 (x_n - y_n)^2 / beta, & \text{if } |x_n - y_n| < beta \\ +|x_n - y_n| - 0.5 * beta, & \text{otherwise } +\end{cases} +$$ + +而 Paddle 中 Smooth L1 loss 的计算方式: + +$$ +loss(x,y) = \left [ z_1, ..., z_N \right ]^T +$$ + +其中: + +$$ +z_i = \begin{cases} + 0.5(x_i - y_i)^2 & {if |x_i - y_i| < delta} \\ + delta * |x_i - y_i| - 0.5 * delta^2 & {otherwise} + \end{cases} +$$ + +所以如果 PyTorch 函数参数 $beta$ 与 Paddle 中的参数 $delta$ 取值相同,则 Paddle 的 loss 要再除以 $delta$ 值才能与 Torch 中的结果对齐。 + + +### 转写示例 + +#### size_average + + +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` + +#### beta +```python +# PyTorch 的 beta 参数转化为 delta 参数 +a=0.8 + +# PyTorch 写法 +output = torch.nn.functional.smooth_l1_loss(input, label, beta=a) + +# Paddle 写法 +output = paddle.nn.functional.smooth_l1_loss(input, label, delta=a) / a +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.soft_margin_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.soft_margin_loss.md new file mode 100644 index 00000000000..5b6d182bfd8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.soft_margin_loss.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.nn.functional.soft_margin_loss + +### [torch.nn.functional.soft_margin_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.soft_margin_loss.html?highlight=soft_margin_loss#torch.nn.functional.soft_margin_loss) + +```python +torch.nn.functional.soft_margin_loss(input, + target, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.functional.soft_margin_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/soft_margin_loss_cn.html) + +```python +paddle.nn.functional.soft_margin_loss(input, + label, + reduction='mean', + name=None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 输入 Tensor 。 | +| target | label | 输入 Tensor 对应的标签值,仅参数名不一致。 | +| size_average | - | 已弃用 | +| reduce | - | 已弃用 | +| reduction | reduction | 表示应用于输出结果的规约方式,可选值有:'none', 'mean', 'sum'。 | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmax.md new file mode 100644 index 00000000000..3474cf8d9e4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmax.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.nn.functional.softmax + +### [torch.nn.functional.softmax](https://pytorch.org/docs/stable/generated/torch.nn.functional.softmax.html?highlight=softmax#torch.nn.functional.softmax) + +```python +torch.nn.functional.softmax(input, + dim=None, + dtype=None) +``` + +### [paddle.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softmax_cn.html) + +```python +paddle.nn.functional.softmax(x, + axis=- 1, + dtype=None, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor ,仅参数名不一致。 | +| dim | axis | 表示对输入 Tensor 运算的轴 ,仅参数名不一致。 | +| dtype | dtype | 表示输入 Tensor 的数据类型 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmin.md new file mode 100644 index 00000000000..76e307b7b1a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softmin.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.nn.functional.softmin + +### [torch.nn.functional.softmin](https://pytorch.org/docs/stable/generated/torch.nn.functional.softmin.html#torch.nn.functional.softmin) + +```python +torch.nn.functional.softmin(input, dim=None, _stacklevel=3, dtype=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.functional.softmin(input, dim=1) + +# Paddle 写法 +paddle.nn.functinal.softmax(-input, axis=1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softplus.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softplus.md new file mode 100644 index 00000000000..784e9453eca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softplus.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.nn.functional.softplus + +### [torch.nn.functional.softplus](https://pytorch.org/docs/stable/generated/torch.nn.functional.softplus.html?highlight=softplus#torch.nn.functional.softplus) + +```python +torch.nn.functional.softplus(input, + beta=1, + threshold=20) +``` + +### [paddle.nn.functional.softplus](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softplus_cn.html) + +```python +paddle.nn.functional.softplus(x, + beta=1, + threshold=20, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示 Softplus 激活计算公式中的 beta 值 ,仅参数名不一致。 | +| beta | beta | 表示 Softplus 激活计算公式中的 threshold 值 。 | +| threshold | threshold | 表示输入的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softshrink.md new file mode 100644 index 00000000000..583beb56e99 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softshrink.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.nn.functional.softshrink + +### [torch.nn.functional.softshrink](https://pytorch.org/docs/stable/generated/torch.nn.functional.softshrink.html?highlight=softshrink#torch.nn.functional.softshrink) + +```python +torch.nn.functional.softshrink(input, + lambd=0.5) +``` + +### [paddle.nn.functional.softshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softshrink_cn.html) + +```python +paddle.nn.functional.softshrink(x, + threshold=0.5, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor ,仅参数名不一致。 | +| lambd | threshold | 表示 Softshrink 公式的 threshold 值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softsign.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softsign.md new file mode 100644 index 00000000000..26e3052ad69 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.softsign.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.functional.softsign + +### [torch.nn.functional.softsign](https://pytorch.org/docs/stable/generated/torch.nn.functional.softsign.html?highlight=softsign#torch.nn.functional.softsign) + +```python +torch.nn.functional.softsign(input) +``` + +### [paddle.nn.functional.softsign](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softsign_cn.html) + +```python +paddle.nn.functional.softsign(x, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanh.md new file mode 100644 index 00000000000..ddb30ea1cca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanh.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.functional.tanh + +### [torch.nn.functional.tanh](https://pytorch.org/docs/stable/generated/torch.nn.functional.tanh.html) + +```python +torch.nn.functional.tanh(input) +``` + +### [paddle.nn.functional.tanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tanh_cn.html#tanh) + +```python +paddle.nn.functional.tanh(x) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanhshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanhshrink.md new file mode 100644 index 00000000000..27b54b0c2a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.tanhshrink.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.functional.tanhshrink + +### [torch.nn.functional.tanhshrink](https://pytorch.org/docs/stable/generated/torch.nn.functional.tanhshrink.html?highlight=tanhshri#torch.nn.functional.tanhshrink) + +```python +torch.nn.functional.tanhshrink(input) +``` + +### [paddle.nn.functional.tanhshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/tanhshrink_cn.html) + +```python +paddle.nn.functional.tanhshrink(x, + name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.threshold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.threshold.md new file mode 100644 index 00000000000..f2e020bdb95 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.threshold.md @@ -0,0 +1,24 @@ +## [torch 参数更多]torch.nn.functional.threshold + +### [torch.nn.functional.threshold](https://pytorch.org/docs/stable/generated/torch.nn.functional.threshold.html#torch.nn.functional.threshold) + +```python +torch.nn.functional.threshold(input, threshold, value, inplace=False) +``` + +### [paddle.nn.functional.thresholded_relu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/thresholded_relu_cn.html) + +```python +paddle.nn.functional.thresholded_relu(x, threshold=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| threshold | threshold | thresholded_relu 激活计算公式中的 threshold 值。 | +| value | - | 不在指定 threshold 范围时的值,Paddle 取值为 0,暂无转写方式。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_loss.md new file mode 100644 index 00000000000..e6a4cdec85f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_loss.md @@ -0,0 +1,63 @@ +## [torch 参数更多 ] torch.nn.functional.triplet_margin_loss + +### [torch.nn.functional.triplet_margin_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.triplet_margin_loss.html?highlight=triplet_margin_loss#torch.nn.functional.triplet_margin_loss) + +```python +torch.nn.functional.triplet_margin_loss(anchor, + positive, + negative, + margin=1.0, + p=2, + eps=1e-06, + swap=False, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.functional.triplet_margin_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/triplet_margin_loss_cn.html) + +```python +paddle.nn.functional.triplet_margin_loss(input, + positive, + negative, + margin: float = 1.0, + p: float = 2.0, + epsilon: float = 1e-6, + swap: bool = False, + reduction: str = 'mean', + name: str = None) +``` + +其中 PyTorch 相⽐ Paddle ⽀持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| anchor | input | 输入 Tensor,仅参数名不一致。 | +| positive | positive | 输入正样本 | +| negative | negative | 输入负样本 | +| margin | margin | 手动指定间距 | +| p | p | 指定范数 | +| eps | epsilon | 防止除数为零的常数 | +| swap | swap | 是否进行交换 | +| size_average | - | 已弃用 | +| reduce | - | 已弃用 | +| reduction | reduction | 表示应用于输出结果的规约方式,可选值有:'none', 'mean', 'sum' | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、 reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_with_distance_loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_with_distance_loss.md new file mode 100644 index 00000000000..c5ef362acd3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.triplet_margin_with_distance_loss.md @@ -0,0 +1,39 @@ +## [ 仅参数名不一致 ] torch.nn.functional.triplet_margin_with_distance_loss + +### [torch.nn.functional.triplet_margin_with_distance_loss](https://pytorch.org/docs/stable/generated/torch.nn.functional.triplet_margin_with_distance_loss.html?highlight=triplet_margin_with_distance_loss#torch.nn.functional.triplet_margin_with_distance_loss) + +```python +torch.nn.functional.triplet_margin_with_distance_loss(anchor, + positive, + negative, *, + distance_function=None, + margin=1.0, + swap=False, + reduction='mean') +``` + +### [paddle.nn.functional.triplet_margin_with_distance_loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/triplet_margin_with_distance_loss_cn.html) + +```python +paddle.nn.functional.triplet_margin_with_distance_loss(input, + positive, + negative, + distance_function=None, + margin: float = 1.0, + swap: bool = False, + reduction: str = 'mean', + name: str = None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| anchor | input | 输入 Tensor,仅参数名不一致。 | +| positive | positive | 输入正样本。 | +| negative | negative | 输入负样本。 | +| distance_function | distance_function | 指定两个张量距离的函数。 | +| margin | margin | 手动指定间距。 | +| swap | swap | 是否进行交换。 | +| reduction | reduction | 表示应用于输出结果的规约方式,可选值有:'none', 'mean', 'sum'。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.unfold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.unfold.md new file mode 100644 index 00000000000..ad350b5825a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.unfold.md @@ -0,0 +1,25 @@ +## [仅参数名不一致]torch.nn.functional.unfold + +### [torch.nn.functional.unfold](https://pytorch.org/docs/stable/generated/torch.nn.functional.unfold.html#torch.nn.functional.unfold) + +```python +torch.nn.functional.unfold(input, kernel_size, dilation=1, padding=0, stride=1) +``` + +### [paddle.nn.functional.unfold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/unfold_cn.html) + +```python +paddle.nn.functional.unfold(x, kernel_size, strides=1, paddings=0, dilation=1, name=None) +``` + +其中功能一致, 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | --------------------------------- | +| input | x | 输入 4-D Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 卷积核的尺寸。 | +| dilation | dilation | 卷积膨胀。 | +| padding | paddings | 每个维度的扩展,仅参数名不一致。 | +| stride | strides | 卷积步长,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample.md new file mode 100644 index 00000000000..baa35710d3e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample.md @@ -0,0 +1,37 @@ +## [ 仅 paddle 参数更多 ] torch.nn.functional.upsample + +### [torch.nn.functional.upsample](https://pytorch.org/docs/stable/generated/torch.nn.functional.upsample.html?highlight=upsample#torch.nn.functional.upsample) + +```python +torch.nn.functional.upsample(input, + size=None, + scale_factor=None, + mode='nearest', + align_corners=None) +``` + +### [paddle.nn.functional.upsample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/upsample_cn.html#upsample) + +```python +paddle.nn.functional.upsample(x, + size=None, + scale_factor=None, + mode='nearest', + align_corners=False, + align_mode=0, + data_format=None, + name=None) +``` + +两者功能一致,其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor,仅参数名不一致。 | +| size | size | 指定输出 Tensor 的大小 。 | +| scale_factor | scale_factor | 指定缩放比例 。 | +| mode | mode | 插值方法。支持"bilinear"或"trilinear"或"nearest"或"bicubic"或"linear"或"area" 。 | +| align_corners | align_corners | 双线性插值的可选项 。 | +| - | align_mode | 表示对输入 Tensor 运算的轴, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | data_format | 表示输入的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_bilinear.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_bilinear.md new file mode 100644 index 00000000000..d95c317ef36 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_bilinear.md @@ -0,0 +1,26 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.upsample_bilinear + +### [torch.nn.functional.upsample_bilinear](https://pytorch.org/docs/stable/generated/torch.nn.functional.upsample_bilinear.html#torch.nn.functional.upsample_bilinear) + +```python +torch.nn.functional.upsample_bilinear(input, size=None, scale_factor=None) +``` + +### [paddle.nn.functional.upsample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/upsample_cn.html#upsample) + +```python +paddle.nn.functional.upsample(x, size=None, scale_factor=None, mode='nearest', align_corners=False, align_mode=0, data_format='NCHW', name=None) +``` + +Paddle 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| size | size | 输出 Tensor 的大小。 | +| scale_factor | scale_factor | 输入的高度或宽度的乘数因子。 | +| - | mode | 插值方法。 PyTorch 无此参数,Paddle 默认为 `’nearest‘`,需要设置为 `‘bilinear'` 。 | +| - | align_corners | 是否将输入和输出张量的 4 个角落像素的中心对齐,并保留角点像素的值。PyTorch 无此参数,Paddle 默认为 `False`,需要设置为 `True`。 | +| - | align_mode | 双线性插值的可选项。PyTorch 无此参数。Paddle 保持默认即可。 | +| - | data_format | 指定输入的数据格式。PyTorch 无此参数。Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_nearest.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_nearest.md new file mode 100644 index 00000000000..ecdb1e6ca81 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/functional/torch.nn.functional.upsample_nearest.md @@ -0,0 +1,26 @@ +## [ 仅 paddle 参数更多 ]torch.nn.functional.upsample_nearest + +### [torch.nn.functional.upsample_nearest](https://pytorch.org/docs/stable/generated/torch.nn.functional.upsample_nearest.html#torch.nn.functional.upsample_nearest) + +```python +torch.nn.functional.upsample_nearest(input, size=None, scale_factor=None) +``` + +### [paddle.nn.functional.upsample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/upsample_cn.html#upsample) + +```python +paddle.nn.functional.upsample(x, size=None, scale_factor=None, mode='nearest', align_corners=False, align_mode=0, data_format='NCHW', name=None) +``` + +仅 paddle 参数更多,具体区别如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| size | size | 输出 Tensor 的大小。 | +| scale_factor | scale_factor | 输入的高度或宽度的乘数因子。 | +| - | mode | 插值方法。 PyTorch 无此参数,Paddle 默认为 `’nearest‘`。 | +| - | align_corners | 是否将输入和输出张量的 4 个角落像素的中心对齐,并保留角点像素的值。PyTorch 无此参数。 | +| - | align_mode | 双线性插值的可选项。PyTorch 无此参数。Paddle 保持默认即可。 | +| - | data_format | 指定输入的数据格式。PyTorch 无此参数。Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.download_url_to_file.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.download_url_to_file.md new file mode 100644 index 00000000000..9b35a3accd5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.download_url_to_file.md @@ -0,0 +1,29 @@ +## [ torch 参数更多 ] torch.hub.download_url_to_file + +### [torch.hub.download_url_to_file](https://pytorch.org/docs/stable/hub.html?highlight=download#torch.hub.download_url_to_file) + +```python +torch.hub.download_url_to_file(url, + dst, + hash_prefix=None, + progress=True) +``` + +### [paddle.utils.download.get_weights_path_from_url](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/download/get_weights_path_from_url_cn.html) + +```python +paddle.utils.download.get_weights_path_from_url(url, + md5sum=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +|url |url |下载的链接。| +|dst |- |指定文件保存的绝对路径,例如:/tmp/temporary_file,Paddle 无此参数,暂无转写方式| +|hash_prefix |- |指定下载的 SHA256 文件的前缀,默认为 None,Paddle 无此参数,暂无转写方式。| +|progress |- |是否显示进度条,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +|- |md5sum |下载文件的 md5 值。PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.help.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.help.md new file mode 100644 index 00000000000..b8ec32c0378 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.help.md @@ -0,0 +1,33 @@ +## [torch 参数更多] torch.hub.help + +### [torch.hub.help](https://pytorch.org/docs/stable/hub.html?highlight=hub+help#torch.hub.help) + +```python +torch.hub.help(github, + model, + force_reload=False, + skip_validation=False, + trust_repo=None) +``` + +### [paddle.hub.help](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hub/help_cn.html) + +```python +paddle.hub.help(repo_dir, + model, + source='github', + force_reload=False) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| github | repo_dir |repo 地址,支持 git 地址形式和 local 地址,仅参数名不一致。 | +| model | model |模型的名字。 | +| force_reload | force_reload |指定是否强制拉取。 | +| skip_validation| - |检查由 github 参数指定的分支或提交是否属于存储库所有者,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| trust_repo | - |在 v1.14 中被移除;Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +|- |source |指定 repo 托管的位置,PyTorch 无此参数,Paddle 保持默认即可| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.list.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.list.md new file mode 100644 index 00000000000..84941d9d5ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.list.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ] torch.hub.list + +### [torch.hub.list](https://pytorch.org/docs/stable/hub.html?highlight=hub+list#torch.hub.list) + +```python +torch.hub.list(github, + force_reload=False, + skip_validation=False, + trust_repo=None) +``` + +### [paddle.hub.list](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hub/list_cn.html) + +```python +paddle.hub.list(repo_dir, + source='github', + force_reload=False) +``` + + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| github | repo_dir |repo 地址,支持 git 地址形式和 local 地址,仅参数名不一致。| +| force_reload | force_reload |指定是否强制拉取,默认值: False。 | +| skip_validation| - |检查由 github 参数指定的分支或提交是否属于存储库所有者,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| trust_repo | - |在 v1.14 中被移除;Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| - |source |指定 repo 托管的位置,PyTorch 无此参数,Paddle 保持默认即可| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.load.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.load.md new file mode 100644 index 00000000000..1bb749b0274 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/hub/torch.hub.load.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ] torch.hub.load + +### [torch.hub.load](https://pytorch.org/docs/stable/hub.html?highlight=hub+load#torch.hub.load) + +```python +torch.hub.load(repo_or_dir, + model, + *args, + source='github', + trust_repo=None, + force_reload=False, + verbose=True, + skip_validation=False, + **kwargs) +``` + +### [paddle.hub.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hub/load_cn.html) + +```python +paddle.hub.load(repo_dir, + model, + source='github', + force_reload=False, + **kwargs) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| repo_or_dir |repo_dir |repo 地址,支持 git 地址形式和 local 地址,仅参数名不同。| +| model | model |模型的名字。| +| *args | - |model 调用时的位置参数。暂无转写方式。| +| source |source |指定 repo 托管的位置。| +| trust_repo | - |在 v1.14 中被移除;Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| force_reload | force_reload |指定是否强制拉取。 | +| verbose | - |是否显示关于命中本地缓存的消息,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| skip_validation| - |检查由 github 参数指定的分支或提交是否属于存储库所有者,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| **kwargs | **kwargs |model 调用时的关键字参数。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.calculate_gain.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.calculate_gain.md new file mode 100644 index 00000000000..caf41fc41ca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.calculate_gain.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ] torch.nn.init.calculate_gain + +### [torch.nn.init.calculate_gain](https://pytorch.org/docs/stable/nn.init.html?highlight=gain#torch.nn.init.calculate_gain) + +```python +torch.nn.init.calculate_gain(nonlinearity, param=None) +``` + +### [paddle.nn.initializer.calculate_gain](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/calculate_gain_cn.html) + +```python +paddle.nn.initializer.calculate_gain(nonlinearity, param=None) +``` + +两者参数和用法完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| nonlinearity | nonlinearity | 非线性激活函数的名称,两者参数和用法完全一致。 | +| param | param | 某些激活函数的参数,默认为 None,两者参数和用法完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.constant_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.constant_.md new file mode 100644 index 00000000000..0aab387a278 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.constant_.md @@ -0,0 +1,35 @@ +## [ 组合替代实现 ]torch.nn.init.constant_ + +### [torch.nn.init.constant_](https://pytorch.org/docs/stable/nn.init.html?highlight=constant_#torch.nn.init.constant_) + +```python +torch.nn.init.constant_(tensor, + val) +``` + +### [paddle.nn.initializer.Constant](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Constant_cn.html) + +```python +paddle.nn.initializer.Constant(value=0.0) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的。PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| val | value | 用于初始化输入变量的值。PyTorch 无默认值,Paddle 默认值为`0.0`。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.constant_(conv.weight, val=1.0) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_constant = paddle.nn.initializer.Constant(value=1.0) +init_constant(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.dirac_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.dirac_.md new file mode 100644 index 00000000000..d30d2b24394 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.dirac_.md @@ -0,0 +1,36 @@ +## [ 组合替代实现 ]torch.nn.init.dirac_ + +### [torch.nn.init.dirac_](https://pytorch.org/docs/stable/nn.init.html?highlight=dirac_#torch.nn.init.dirac_) + +```python +torch.nn.init.dirac_(tensor, + groups=1) +``` + +### [paddle.nn.initializer.Dirac](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Dirac_cn.html) + +```python +paddle.nn.initializer.Dirac(groups=1, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的。PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| groups | groups | 将参数在 0 维上进行等分为 groups 份,每一份执行相同的初始化。参数名和默认值一致。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.dirac_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_dirac = paddle.nn.initializer.Dirac() +init_dirac(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.eye_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.eye_.md new file mode 100644 index 00000000000..fbb69e6d09c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.eye_.md @@ -0,0 +1,35 @@ +## [ 组合替代实现 ]torch.nn.init.eye_ + +### [torch.nn.init.eye_](https://pytorch.org/docs/stable/nn.init.html?highlight=eye_#torch.nn.init.eye_) + +```python +torch.nn.init.eye_(tensor) +``` + +### [paddle.nn.initializer.Assign](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Assign_cn.html) + +```python +paddle.nn.initializer.Assign(value, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| - | value | 用于初始化参数的一个 Numpy 数组、Python 列表、Tensor。PyTorch 无此参数。此处 Paddle 应使用 paddle.eye 进行参数设置。 | + +### 转写示例 +```python +# PyTorch 写法 +w = torch.empty(3, 5) +torch.nn.init.eye_(w) + +# Paddle 写法 +w = paddle.empty([3, 5]) +init_eye = paddle.nn.initializer.Assign(paddle.eye(w.shape[0], w.shape[1])) +init_eye(w) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md new file mode 100644 index 00000000000..4b7784effb8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_normal_.md @@ -0,0 +1,42 @@ +## [ 组合替代实现 ]torch.nn.init.kaiming_normal_ + +### [torch.nn.init.kaiming_normal_](https://pytorch.org/docs/stable/nn.init.html?highlight=kaiming_normal_#torch.nn.init.kaiming_normal_) + +```python +torch.nn.init.kaiming_normal_(tensor, + a=0, + mode='fan_in', + nonlinearity='leaky_relu') +``` + +### [paddle.nn.initializer.KaimingNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/KaimingNormal_cn.html) + +```python +paddle.nn.initializer.KaimingNormal(fan_in=None, + negative_slope=0.0, + nonlinearity='relu') +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| a | negative_slope | 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。仅参数名不一致。 | +| nonlinearity | nonlinearity | 非线性激活函数。参数默认值不一样,PyTorch 默认值为`leaky_relu`,Paddle 默认值为`relu`,Paddle 需保持与 PyTorch 一致。 | +| mode | - | "fan_in"(默认)或 "fan_out"。Paddle 无此参数,mode="fan_out"时,Paddle 无此参数,暂无转写方式。 | +| - | fan_in | 可训练的 Tensor 的 in_features 值。PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.kaiming_normal_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_kaimingNormal = paddle.nn.initializer.KaimingNormal(nonlinearity='leaky_relu') +init_kaimingNormal(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_uniform_.md new file mode 100644 index 00000000000..c54aeba60ee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.kaiming_uniform_.md @@ -0,0 +1,42 @@ +## [ 组合替代实现 ]torch.nn.init.kaiming_uniform_ + +### [torch.nn.init.kaiming_uniform_](https://pytorch.org/docs/stable/nn.init.html?highlight=kaiming_uniform_#torch.nn.init.kaiming_uniform_) + +```python +torch.nn.init.kaiming_uniform_(tensor, + a=0, + mode='fan_in', + nonlinearity='leaky_relu') +``` + +### [paddle.nn.initializer.KaimingUniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/KaimingUniform_cn.html) + +```python +paddle.nn.initializer.KaimingUniform(fan_in=None, + negative_slope=0.0, + nonlinearity='relu') +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| a | negative_slope | 只适用于使用 leaky_relu 作为激活函数时的 negative_slope 参数。仅参数名不一致。 | +| nonlinearity | nonlinearity | 非线性激活函数。参数默认值不一样,PyTorch 默认值为`leaky_relu`,Paddle 默认值为`relu`,Paddle 需保持与 PyTorch 一致。 | +| mode | - | "fan_in"(默认)或 "fan_out"。Paddle 无此参数,mode="fan_out"时,Paddle 无此参数,暂无转写方式。 | +| - | fan_in | 可训练的 Tensor 的 in_features 值。PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.kaiming_uniform_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_kaimingUniform = paddle.nn.initializer.KaimingUniform(nonlinearity='leaky_relu') +init_kaimingUniform(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.normal_.md new file mode 100644 index 00000000000..f3f87da19b0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.normal_.md @@ -0,0 +1,39 @@ +## [ 组合替代实现 ]torch.nn.init.normal_ + +### [torch.nn.init.normal_](https://pytorch.org/docs/stable/nn.init.html?highlight=normal_#torch.nn.init.normal_) + +```python +torch.nn.init.normal_(tensor, + mean=0.0, + std=1.0) +``` + +### [paddle.nn.initializer.Normal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Normal_cn.html) + +```python +paddle.nn.initializer.Normal(mean=0.0, + std=1.0, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的。PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| mean | mean | 正态分布的平均值。参数名和默认值一致。 | +| std | std | 正态分布的标准差。参数名和默认值一致。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.normal_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_normal = paddle.nn.initializer.Normal() +init_normal(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.ones_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.ones_.md new file mode 100644 index 00000000000..88cebca42bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.ones_.md @@ -0,0 +1,34 @@ +## [ 组合替代实现 ]torch.nn.init.ones_ + +### [torch.nn.init.ones_](https://pytorch.org/docs/stable/nn.init.html?highlight=ones_#torch.nn.init.ones_) + +```python +torch.nn.init.ones_(tensor) +``` + +### [paddle.nn.initializer.Constant](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Constant_cn.html) + +```python +paddle.nn.initializer.Constant(value=0.0) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| - | value | 用于初始化输入变量的值。PyTorch 无此参数,Paddle 默认值为`0.0`,需设置为`1.0`。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.ones_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_constant = paddle.nn.initializer.Constant(value=1.0) +init_constant(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md new file mode 100644 index 00000000000..becbfd8c431 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.orthogonal_.md @@ -0,0 +1,36 @@ +## [ 组合替代实现 ]torch.nn.init.orthogonal_ + +### [torch.nn.init.orthogonal_](https://pytorch.org/docs/stable/nn.init.html?highlight=orthogonal_#torch.nn.init.orthogonal_) + +```python +torch.nn.init.orthogonal_(tensor, + gain=1) +``` + +### [paddle.nn.initializer.Orthogonal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Orthogonal_cn.html) + +```python +paddle.nn.initializer.Orthogonal(gain=1.0, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的。PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| gain | gain | 参数初始化的增益系数。参数名和参数默认值均一致。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.orthogonal_(conv.weight, gain=2) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_orthogonal = paddle.nn.initializer.Orthogonal(gain=2) +init_orthogonal(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md new file mode 100644 index 00000000000..b86874f2f3e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.uniform_.md @@ -0,0 +1,39 @@ +## [ 组合替代实现 ]torch.nn.init.uniform_ + +### [torch.nn.init.uniform_](https://pytorch.org/docs/stable/nn.init.html?highlight=uniform_#torch.nn.init.uniform_) + +```python +torch.nn.init.uniform_(tensor, + a=0.0, + b=1.0) +``` + +### [paddle.nn.initializer.Uniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Uniform_cn.html) + +```python +paddle.nn.initializer.Uniform(low=-1.0, + high=1.0, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的。PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| a | low | 均匀分布的下界,参数默认值不一致, PyTorch 默认为`0.0`,Paddle 为`-1.0`,Paddle 需保持与 PyTorch 一致。 | +| b | high | 均匀分布的上界,仅参数名不一致。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.uniform_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_uniform = paddle.nn.initializer.Uniform(low=0.0) +init_uniform(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_normal_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_normal_.md new file mode 100644 index 00000000000..c31a95dc74a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_normal_.md @@ -0,0 +1,40 @@ +## [ 组合替代实现 ]torch.nn.init.xavier_normal_ + +### [torch.nn.init.xavier_normal_](https://pytorch.org/docs/stable/nn.init.html?highlight=xavier_normal_#torch.nn.init.xavier_normal_) + +```python +torch.nn.init.xavier_normal_(tensor, + gain=1.0) +``` + +### [paddle.nn.initializer.XavierNormal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/XavierNormal_cn.html) + +```python +paddle.nn.initializer.XavierNormal(fan_in=None, + fan_out=None, + gain=1.0, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| gain | gain | 缩放因子。 | +| - | fan_in | 用于泽维尔初始化的 fan_in。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | fan_out | 用于泽维尔初始化的 fan_out。PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.xavier_normal_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_xaiverNormal = paddle.nn.initializer.XavierNormal() +init_xaiverNormal(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md new file mode 100644 index 00000000000..809c56a90ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.xavier_uniform_.md @@ -0,0 +1,40 @@ +## [ 组合替代实现 ]torch.nn.init.xavier_uniform_ + +### [torch.nn.init.xavier_uniform_](https://pytorch.org/docs/stable/nn.init.html?highlight=xavier_uniform_#torch.nn.init.xavier_uniform_) + +```python +torch.nn.init.xavier_uniform_(tensor, + gain=1.0) +``` + +### [paddle.nn.initializer.XavierUniform](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/XavierUniform_cn.html) + +```python +paddle.nn.initializer.XavierUniform(fan_in=None, + fan_out=None, + gain=1.0, + name=None) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| gain | gain | 缩放因子。 | +| - | fan_in | 用于泽维尔初始化的 fan_in。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | fan_out | 用于泽维尔初始化的 fan_out。PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.xavier_uniform_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_xaiverUniform = paddle.nn.initializer.XavierUniform() +init_xaiverUniform(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.zeros_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.zeros_.md new file mode 100644 index 00000000000..010ebace8b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/init/torch.nn.init.zeros_.md @@ -0,0 +1,34 @@ +## [ 组合替代实现 ]torch.nn.init.zeros_ + +### [torch.nn.init.zeros_](https://pytorch.org/docs/stable/nn.init.html?highlight=zeros_#torch.nn.init.zeros_) + +```python +torch.nn.init.zeros_(tensor) +``` + +### [paddle.nn.initializer.Constant](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/initializer/Constant_cn.html) + +```python +paddle.nn.initializer.Constant(value=0.0) +``` + +两者用法不同:torch 是 inplace 的用法,paddle 是类设置的,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | - | n 维 tensor。Paddle 无此参数,因为是通过调用类的 __call__ 函数来进行 tensor 的初始化。 | +| - | value | 用于初始化输入变量的值。PyTorch 无此参数,Paddle 默认值为`0.0`,保持默认即可。 | + +### 转写示例 +```python +# PyTorch 写法 +conv = torch.nn.Conv2d(4, 6, (3, 3)) +torch.nn.init.zeros_(conv.weight) + +# Paddle 写法 +conv = nn.Conv2D(in_channels=4, out_channels=6, kernel_size=(3,3)) +init_constant = paddle.nn.initializer.Constant() +init_constant(conv.weight) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cholesky.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cholesky.md new file mode 100644 index 00000000000..50d19b46018 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cholesky.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.linalg.cholesky + +### [torch.linalg.cholesky](https://pytorch.org/docs/stable/generated/torch.linalg.cholesky.html?highlight=linalg+cholesky#torch.linalg.cholesky) + +```python +torch.linalg.cholesky(A,*,upper=False,out=None) +``` + +### [paddle.linalg.cholesky](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cholesky_cn.html) + +```python +paddle.linalg.cholesky(x,upper=False,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| A | x | 表示输入参数为多维 Tensor,它的维度应该为 [*, M, N],其中*为零或更大的批次尺寸,并且最里面的两个维度上的矩阵都应为对称的正定矩阵,仅参数名不一致。 | +| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.linalg.cholesky(x, upper=False, out=output) + + +# Paddle 写法 +paddle.assign(paddle.linalg.cholesky(x, upper=False),output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cond.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cond.md new file mode 100644 index 00000000000..c2694b7828d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cond.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.linalg.cond + +### [torch.linalg.cond](https://pytorch.org/docs/stable/generated/torch.linalg.cond.html#torch.linalg.cond) + +```python +# PyTorch 文档有误,第一个参数名为 input +torch.linalg.cond(input, p=None, *, out=None) +``` + +### [paddle.linalg.cond](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/cond_cn.html) + +```python +paddle.linalg.cond(x, p=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| p | p | 范数种类。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.cond(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.cond(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cross.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cross.md new file mode 100644 index 00000000000..da4d225eebc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.cross.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.linalg.cross + +### [torch.linalg.cross](https://pytorch.org/docs/stable/generated/torch.linalg.cross.html?highlight=torch+linalg+cross#torch.linalg.cross) + +```python +torch.linalg.cross(input, other, *, dim=- 1, out=None) +``` + +### [paddle.cross](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cross_cn.html) + +```python +paddle.cross(x, y, axis=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的维度,参数默认值不一致。PyTorch 默认为`-1`,Paddle 默认为 `None`。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.linalg.cross(input, other, dim=1, out=y) + +# Paddle 写法 +paddle.assign(paddle.cross(input, other, axis=1) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.det.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.det.md new file mode 100644 index 00000000000..6d559257ad1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.det.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.linalg.det +### [torch.linalg.det](https://pytorch.org/docs/stable/generated/torch.linalg.det.html#torch.linalg.det) + +```python +torch.linalg.det(A, *, out=None) +``` + +### [paddle.linalg.det](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/det_cn.html#det) + +```python +paddle.linalg.det(x) +``` + +torch 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出 Tensor, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.det(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.det(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.diagonal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.diagonal.md new file mode 100644 index 00000000000..349fb450188 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.diagonal.md @@ -0,0 +1,27 @@ +## [ 仅参数默认值不一致 ]torch.linalg.diagonal +### [torch.linalg.diagonal](https://pytorch.org/docs/stable/generated/torch.linalg.diagonal.html#torch.linalg.diagonal) + +```python +torch.linalg.diagonal(A, *, offset=0, dim1=-2, dim2=-1) +``` + +### [paddle.diagonal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diagonal_cn.html#diagonal) + +```python +paddle.diagonal(x, + offset=0, + axis1=0, + axis2=1, + name=None) +``` + +两者功能一致且参数用法一致,仅参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 表示输入的 Tensor ,仅参数名不一致。 | +| offset | offset | 表示对角线偏移量。 | +| dim1 | axis1 | 获取对角线的二维平面的第一维,仅参数默认值不一致。PyTorch 默认为`-2`,Paddle 默认为`0`,Paddle 需设置为与 PyTorch 一致。 | +| dim2 | axis2 | 获取对角线的二维平面的第二维,仅参数默认值不一致。PyTorch 默认为`-1`,Paddle 默认为`1`,Paddle 需设置为与 PyTorch 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eig.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eig.md new file mode 100644 index 00000000000..36eb3e90005 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eig.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.linalg.eig + +### [torch.linalg.eig](https://pytorch.org/docs/stable/generated/torch.linalg.eig.html?highlight=torch+linalg+eig#torch.linalg.eig) + +```python +torch.linalg.eig(input, *, out=None) +``` + +### [paddle.linalg.eig](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eig_cn.html) + +```python +paddle.linalg.eig(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 tuple,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.eig(t, out=(L,V)) + +# Paddle 写法 +L,V=paddle.linalg.eig(t) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigh.md new file mode 100644 index 00000000000..55991e7599c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigh.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.linalg.eigh + +### [torch.linalg.eigh](https://pytorch.org/docs/stable/generated/torch.linalg.eigh.html#torch.linalg.eigh) + +```python +torch.linalg.eigh(input, UPLO='L', *, out=None) +``` + +### [paddle.linalg.eigh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eigh_cn.html) + +```python +paddle.linalg.eigh(x, UPLO='L', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| UPLO | UPLO | 表示计算上三角或者下三角矩阵 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.eigh(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.eigh(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvals.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvals.md new file mode 100644 index 00000000000..fcef69daee7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvals.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.linalg.eigvals + +### [torch.linalg.eigvals](https://pytorch.org/docs/stable/generated/torch.linalg.eigvals.html?highlight=torch+linalg+eigvals#torch.linalg.eigvals) + +```python +torch.linalg.eigvals(A, + out=None) +``` + +### [paddle.linalg.eigvals](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eigvals_cn.html) + +```python +paddle.linalg.eigvals(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| A | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.eigvals(t, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.eigvals(t), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvalsh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvalsh.md new file mode 100644 index 00000000000..6a9ec14aa65 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.eigvalsh.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.linalg.eigvalsh + +### [torch.linalg.eigvalsh](https://pytorch.org/docs/stable/generated/torch.linalg.eigvalsh.html#torch.linalg.eigvalsh) + +```python +torch.linalg.eigvalsh(A, UPLO='L', *, out=None) +``` + +### [paddle.linalg.eigvalsh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eigvalsh_cn.html) + +```python +paddle.linalg.eigvalsh(x, UPLO='L', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| A | x | 输入 Tensor,仅参数名不一致。 | +| UPLO | UPLO | 表示计算上三角或者下三角矩阵 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.eigvalsh(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.eigvalsh(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.householder_product.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.householder_product.md new file mode 100644 index 00000000000..28f57d4ab7a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.householder_product.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.linalg.householder_product + +### [torch.linalg.householder_product](https://pytorch.org/docs/stable/generated/torch.linalg.householder_product.html#torch.linalg.householder_product) + +```python +torch.linalg.householder_product(A, tau, *, out=None) +``` + +### [paddle.linalg.householder_product](https://github.com/PaddlePaddle/Paddle/blob/d6ea911bd1bfda5604807eeb18318e71b395ac58/python/paddle/tensor/linalg.py#L3744) + +```python +paddle.linalg.householder_product(x, tau, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------- | +| A | x | 表示输入的 Tensor,仅参数名不一致。 | +| tau | tau | 表示输入的 Tensor。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.householder_product(x, tau, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.householder_product(x, tau), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.inv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.inv.md new file mode 100644 index 00000000000..ae4336d9dce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.inv.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.linalg.inv + +### [torch.linalg.inv](https://pytorch.org/docs/stable/generated/torch.linalg.inv.html#torch.linalg.inv) + +```python +torch.linalg.inv(A, *, out=None) +``` + +### [paddle.linalg.inv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/inv_cn.html) + +```python +paddle.linalg.inv(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| A | x | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.inv(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.inv(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lstsq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lstsq.md new file mode 100644 index 00000000000..bd1120c5304 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lstsq.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.linalg.lstsq +### [torch.linalg.lstsq](https://pytorch.org/docs/stable/generated/torch.linalg.lstsq.html?highlight=lstsq#torch.linalg.lstsq) + +```python +torch.linalg.lstsq(A, B, rcond=None, *, driver=None) +``` + +### [paddle.linalg.lstsq](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lstsq_cn.html) + +```python +paddle.linalg.lstsq(x, y, rcond=None, driver=None, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 表示输入的 Tensor 。 | +| B | y | 表示输入的 Tensor 。 | +| rcond | rcond | 用来决定 x 有效秩的 float 型浮点数。 | +| driver | driver | 用来指定计算使用的 LAPACK 库方法。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu.md new file mode 100644 index 00000000000..f2ca24122fe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ]torch.linalg.lu + +### [torch.linalg.lu](https://pytorch.org/docs/stable/generated/torch.linalg.lu.html?highlight=torch+linalg+lu#torch.linalg.lu) + +```python +torch.linalg.lu(A, *, pivot=True, out=None) +``` + +Paddle 无此 API,需要组合实现。 +PyTorch 中 torch.linalg.lu 返回值为 (P, L, U),Paddle 中 paddle.linalg.lu 返回值为(LU, P),需要转写。 + +### 转写示例 + +```python +# PyTorch 写法 +P, L, U = torch.linalg.lu(x) + +# Paddle 写法 +lu, p = paddle.linalg.lu(x) +P, L, U = paddle.linalg.lu_unpack(lu, p) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor.md new file mode 100644 index 00000000000..07ed2a62ef3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor.md @@ -0,0 +1,37 @@ +## [ torch 参数更多 ]torch.linalg.lu_factor + +### [torch.linalg.lu_factor](https://pytorch.org/docs/stable/generated/torch.linalg.lu_factor.html#torch.linalg.lu_factor) + +```python +torch.linalg.lu_factor(A, *, bool pivot=True, out=None) +``` + +### [paddle.linalg.lu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lu_cn.html) + +```python +paddle.linalg.lu(x, pivot=True, get_infos=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------- | +| A | x | 表示需要进行 LU 分解的输入 Tensor ,仅参数名不一致。 | +| pivot | pivot | 表示 LU 分解时是否进行旋转。 | +| - | get_infos | 表示是否返回分解状态信息 , Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor 元组 , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.lu_factor(A, out=(LU, pivots)) + +# Paddle 写法 +y = paddle.linalg.lu(A) +paddle.assign(y[0], out[0]), paddle.assign(y[1], out[1]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor_ex.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor_ex.md new file mode 100644 index 00000000000..8a8debe3298 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.lu_factor_ex.md @@ -0,0 +1,51 @@ +## [ torch 参数更多 ]torch.linalg.lu_factor_ex + +### [torch.linalg.lu_factor_ex](https://pytorch.org/docs/stable/generated/torch.linalg.lu_factor_ex.html?highlight=lu_factor_ex#torch.linalg.lu_factor_ex) + +```python +torch.linalg.lu_factor_ex(A, *, pivot=True, check_errors=False, out=None) +``` + +### [paddle.linalg.lu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lu_cn.html) + +```python +paddle.linalg.lu(x, pivot=True, get_infos=True, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ----------------------------------------------------------------------------------------------------- | +| A | x | 表示需要进行 LU 分解的输入 Tensor ,仅参数名不一致。 | +| pivot | pivot | 表示 LU 分解时是否进行旋转。 | +| - | get_infos | 表示是否返回分解状态信息 ,PyTorch 返回 infos 信息,Paddle 需要设置为 True。 | +| check_errors | - | 检查 infos 的内容,如果为非 0 抛出错误, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor 元组 ,Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | 表示返回的 Tensor 元组 ,PyTorch 返回 info 的 shape 为[],Paddle 返回 info 的 shape 为[1],需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.lu_factor_ex(A, out=(LU, pivots, info)) + +# Paddle 写法 +y = paddle.linalg.lu(A, get_infos=True) +y[2] = paddle.to_tensor(y[2].item(), dtype='int32') +paddle.assign(y[0], out[0]), paddle.assign(y[1], out[1]), paddle.assign(y[2], out[2]) +``` + +#### 返回值 + +```python +# PyTorch 写法 +y = torch.linalg.lu_factor_ex(A) + +# Paddle 写法 +y = paddle.linalg.lu(A, get_infos=True) +y[2] = paddle.to_tensor(y[2].item(), dtype='int32') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matmul.md new file mode 100644 index 00000000000..5ee08682133 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matmul.md @@ -0,0 +1,37 @@ +## [torch 参数更多]torch.linalg.matmul + +### [torch.linalg.matmul](https://pytorch.org/docs/stable/generated/torch.linalg.matmul.html#torch.linalg.matmul) + +```python +torch.linalg.matmul(input, other, *, out=None) +``` + +### [paddle.matmul](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/matmul_cn.html) + +```python +paddle.matmul(x, y, transpose_x=False, transpose_y=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------- | +| input | x | 输入变量,仅参数名不一致。 | +| other | y | 输入变量,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| - | transpose_x | 相乘前是否转置 x,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | transpose_y | 相乘前是否转置 y,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.matmul(x1, x2, out=y) + +# Paddle 写法: +paddle.assign(paddle.matmul(x1, x2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_exp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_exp.md new file mode 100644 index 00000000000..6e5dc17ccff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_exp.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.linalg.matrix_exp +### [torch.linalg.matrix_exp](https://pytorch.org/docs/stable/generated/torch.linalg.matrix_exp.html#torch.linalg.matrix_exp) + +```python +torch.linalg.matrix_exp(A) +``` + +### [paddle.linalg.matrix_exp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_exp_cn.html) + +```python +paddle.linalg.matrix_exp(x, name=None) +``` + +PyTorch 相比 Paddle 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 输入的方阵,类型为 Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_norm.md new file mode 100644 index 00000000000..362e7717aef --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_norm.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.linalg.matrix_norm + +### [torch.linalg.matrix_norm](https://pytorch.org/docs/stable/generated/torch.linalg.matrix_norm.html#torch.linalg.matrix_norm) + +```python +torch.linalg.matrix_norm(input, ord='fro', dim=(-2, -1), keepdim=False, *, dtype=None, out=None) +``` + +### [paddle.linalg.matrix_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_norm_cn.html) + +```python +paddle.linalg.matrix_norm(x, p='fro', axis=[-2,-1], keepdim=False, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| ord | p | 范数的种类,仅参数名不一致。 | +| dim | axis | 使用范数计算的轴 ,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 | +| dtype | - | 表示输出 Tensor 的数据类型, Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.matrix_norm(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.matrix_norm(x), y) +``` + +#### dtype:表示输出 Tensor 的数据类型 + +```python +# PyTorch 写法 +torch.linalg.matrix_norm(x, dtype=torch.float64) + +# Paddle 写法 +paddle.linalg.matrix_norm(x.astype(paddle.float64)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_power.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_power.md new file mode 100644 index 00000000000..456240161ea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_power.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.linalg.matrix_power +### [torch.linalg.matrix_power](https://pytorch.org/docs/stable/generated/torch.linalg.matrix_power.html?highlight=torch+linalg+matrix_power#torch.linalg.matrix_power) + +```python +torch.linalg.matrix_power(A, + n, + *, + out=None) +``` + +### [paddle.linalg.matrix_power](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_power_cn.html) + +```python +paddle.linalg.matrix_power(x, + n, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 输入的欲进行 n 次幂运算的一个或一批方阵,类型为 Tensor,仅参数名不一致。 | +| n | n | 输入的幂次,类型为 int。 | +|out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.linalg.matrix_power(x, 3, out = y) + +# Paddle 写法 +paddle.assign(paddle.linalg.matrix_power(x, 3), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_rank.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_rank.md new file mode 100644 index 00000000000..89d03a72381 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.matrix_rank.md @@ -0,0 +1,31 @@ +## [torch 参数更多 ]torch.linalg.matrix_rank +### [torch.linalg.matrix_rank](https://pytorch.org/docs/stable/generated/torch.linalg.matrix_rank.html?highlight=matrix_rank#torch.linalg.matrix_rank) +```python +torch.linalg.matrix_rank(A, tol=None, hermitian=False, *, out=None) +``` + +### [paddle.linalg.matrix_rank](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_rank_cn.html) +```python +paddle.linalg.matrix_rank(x, tol=None, hermitian=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 输入的 Tensor ,仅参数名不一致。 | +| tol | tol | 输入的 Tensor 或者 float,参数完全一致。 | +| hermitian | hermitian | 输入的 bool ,参数完全一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.linalg.matrix_rank(torch.ones(3, 4, 5, 5), tol=0.01, hermitian=True, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.matrix_rank(paddle.ones(shape=[3, 4, 5, 5]), tol=0.01, hermitian=True), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.multi_dot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.multi_dot.md new file mode 100644 index 00000000000..ab723dc0633 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.multi_dot.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.linalg.multi_dot + +### [torch.linalg.multi_dot](https://pytorch.org/docs/stable/generated/torch.linalg.multi_dot.html?highlight=torch+linalg+multi_dot#torch.linalg.multi_dot) + +```python +torch.linalg.multi_dot(tensors, + out=None) +``` + +### [paddle.linalg.multi_dot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/multi_dot_cn.html) + +```python +paddle.linalg.multi_dot(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的一个 tensor 列表 ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.multi_dot(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.multi_dot(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.norm.md new file mode 100644 index 00000000000..5721eaa3f3d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.norm.md @@ -0,0 +1,47 @@ +## [ torch 参数更多 ]torch.linalg.norm + +### [torch.linalg.norm](https://pytorch.org/docs/stable/generated/torch.linalg.norm.html#torch.linalg.norm) + +```python +torch.linalg.norm(input, ord=None, dim=None, keepdim=False, *, out=None, dtype=None) +``` + +### [paddle.linalg.norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/norm_cn.html#norm) + +```python +paddle.linalg.norm(x, p='fro', axis=None, keepdim=False, name=None) +``` + +PyTorch 支持更多的参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的一个 tensor 列表 ,仅参数名不一致。 | +| ord | p | 范数的种类。参数不一致。PyTorch 支持负实数的范数,Paddle 不支持,暂无转写方式。 | +| dim | axis | 使用范数计算的轴 ,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| dtype | - | 表示输出 Tensor 的数据类型, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.norm(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.norm(x), y) +``` + +#### dtype:表示输出 Tensor 的数据类型 + +```python +# PyTorch 写法 +torch.linalg.norm(x, dtype=torch.float64) + +# Paddle 写法 +paddle.linalg.norm(x.astype(paddle.float64)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.pinv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.pinv.md new file mode 100644 index 00000000000..3c661692c1f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.pinv.md @@ -0,0 +1,37 @@ +## [torch 参数更多]torch.linalg.pinv + +### [torch.linalg.pinv](https://pytorch.org/docs/stable/generated/torch.linalg.pinv.html#torch.linalg.pinv) + +```python +torch.linalg.pinv(input, *, atol=None, rtol=None, hermitian=False, out=None) +``` + +### [paddle.linalg.pinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/pinv_cn.html) + +```python +paddle.linalg.pinv(x, rcond=1e-15, hermitian=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ------------------------------------------------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| atol | - | 绝对阈值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| rtol | rcond | 奇异值(特征值)被截断的阈值,仅参数名不一致。 | +| hermitian | hermitian | 是否为 hermitian 矩阵或者实对称矩阵。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.pinv(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.pinv(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.qr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.qr.md new file mode 100644 index 00000000000..ddba2b3bbde --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.qr.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.linalg.qr + +### [torch.linalg.qr](https://pytorch.org/docs/stable/generated/torch.linalg.qr.html#torch.linalg.qr) + +```python +torch.linalg.qr(A, mode='reduced', *, out=None) +``` + +### [paddle.linalg.qr](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/qr_cn.html) + +```python +paddle.linalg.qr(x, mode='reduced', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| A | x | 输入 Tensor,仅参数名不一致。 | +| mode | mode | 控制正交三角分解的行为。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.qr(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.qr(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.slogdet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.slogdet.md new file mode 100644 index 00000000000..7c38073ba43 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.slogdet.md @@ -0,0 +1,46 @@ +## [ 参数不一致 ]torch.linalg.slogdet +### [torch.linalg.slogdet](https://pytorch.org/docs/stable/generated/torch.linalg.slogdet.html#torch.linalg.slogdet) + +```python +torch.linalg.slogdet(A, *, out=None) +``` + +### [paddle.linalg.slogdet](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/slogdet_cn.html#slogdet) + +```python +paddle.linalg.slogdet(x) +``` + +两者功能一致,返回参数个数不同,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出 Tensor,Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | PyTorch 返回两个 Tensor,Paddle 返回一个 Tensor,需要转写。 | + + +### 转写示例 + +#### 返回值 +```python +# PyTorch 写法 +torch.linalg.slogdet(x) + +# Paddle 写法 +y = paddle.linalg.slogdet(x) +(y[0], y[1]) +``` + +#### out:输出的 Tensor +```python +# PyTorch 写法 +torch.linalg.slogdet(x, out=(y1, y2)) + +# Paddle 写法 +z = paddle.linalg.slogdet(a) +paddle.assign(z[0], output=y1) +paddle.assign(z[1], output=y2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve.md new file mode 100644 index 00000000000..a5345f6941d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.linalg.solve + +### [torch.linalg.solve](https://pytorch.org/docs/stable/generated/torch.linalg.solve.html#torch.linalg.solve) + +```python +torch.linalg.solve(A, B, *, left=True, out=None) +``` + +### [paddle.linalg.solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/solve_cn.html) + +```python +paddle.linalg.solve(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------ | +| A | x | 输入线性方程组求解的一个或一批方阵,仅参数名不一致。 | +| B | y | 输入线性方程组求解的右值,仅参数名不一致。 | +| left | - | 是否求解 AX = B 或 XA = B,Paddle 无此参数,暂无转写方式。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.solve(x1, x2, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.solve(x1, x2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve_triangular.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve_triangular.md new file mode 100644 index 00000000000..45665f57303 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.solve_triangular.md @@ -0,0 +1,55 @@ +## [ torch 参数更多 ]torch.linalg.solve_triangular + +### [torch.linalg.solve_triangular](https://pytorch.org/docs/stable/generated/torch.linalg.solve_triangular.html?highlight=torch+linalg+solve_triangular#torch.linalg.solve_triangular) + +```python +# PyTorch 文档有误,测试第一个参数为 input +torch.linalg.solve_triangular(input, B, *, upper, left=True, unitriangular=False, out=None) +``` + +### [paddle.linalg.triangular_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/triangular_solve_cn.html) + +```python +paddle.linalg.triangular_solve(x, y, upper=True, transpose=False, unitriangular=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | ----------------------------------------------------------------------------------------------------------------- | +| input | x | 表示线性方程组左边的系数 Tensor ,仅参数名不一致。 | +| B | y | 表示线性方程组右边的 Tensor ,仅参数名不一致。 | +| upper | upper | 表示对系数 Tensor 取上三角还是下三角。 | +| left | transpose | 表示是否对系数 Tensor 进行转置 ,PyTorch 和 Paddle 取值相反,PyTorch 默认为 True,Paddle 默认为 False,需要转写。 | +| unitriangular | unitriangular | 表示是否将系数 Tensor 对角线元素假设为 1 来求解方程。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### left:表示系数 Tensor 的位置设置 + +```python +# PyTorch 写法, left 为 True +torch.linalg.solve_triangular(input, B, upper, left=True) + +# Paddle 写法 +paddle.linalg.triangular_solve(input, B, upper, transpose=False) + +# PyTorch 写法, left 为 False +torch.linalg.solve_triangular(input, B, upper, left=False) + +# Paddle 写法 +paddle.linalg.triangular_solve(input, B, upper, transpose=True) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.solve_triangular(input, B, upper, left, unitriangular, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.triangular_solve(input, B, upper, transpose, unitriangular) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svd.md new file mode 100644 index 00000000000..591fb5a9e06 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svd.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ] torch.linalg.svd + +### [torch.linalg.svd](https://pytorch.org/docs/stable/generated/torch.linalg.svd.html?highlight=svd#torch.linalg.svd) + +```python +torch.linalg.svd(A, full_matrices=True, *, driver=None, out=None) +``` + +### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/svd_cn.html) + +```python +paddle.linalg.svd(x, full_matrices=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | ---------------------------------------------------------------------------------------------- | +| A | x | 输入 Tensor,仅参数名不一致。 | +| full_matrices | full_matrices | 是否计算完整的 U 和 V 矩阵,PyTorch 为 True,Paddle 为 False,Paddle 需设置为与 PyTorch 一致。 | +| driver | - | cuSOLVER 方法名,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.svd(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.svd(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svdvals.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svdvals.md new file mode 100644 index 00000000000..23d0090d9de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.svdvals.md @@ -0,0 +1,47 @@ +## [ torch 参数更多 ] torch.linalg.svdvals + +### [torch.linalg.svdvals](https://pytorch.org/docs/stable/generated/torch.linalg.svdvals.html#torch.linalg.svdvals) + +```python +torch.linalg.svdvals(A, *, driver=None, out=None) +``` + +### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/svd_cn.html) + +```python +paddle.linalg.svd(x, full_matrices=False, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------- | ------------------------------------------------------------------------------------ | +| A | x | 输入 Tensor,仅参数名不一致。 | +| driver | - | cuSOLVER 方法名,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | full_matrices | 是否计算完整的 U 和 V 矩阵,Paddle 为 False,PyTorch 无此参数,Paddle 使用默认即可。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | PyTorch 返回值为 S,Paddle 返回 U、S、VH,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.linalg.svdvals(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.svd(x)[1], y) +``` + +#### 返回值 + +```python +# PyTorch 写法: +y = torch.linalg.svdvals(x) + +# Paddle 写法: +y = paddle.linalg.svd(x)[1] +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vander.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vander.md new file mode 100644 index 00000000000..18a9131c6d4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vander.md @@ -0,0 +1,35 @@ +## [仅 paddle 参数更多]torch.linalg.vander + +### [torch.linalg.vander](https://pytorch.org/docs/stable/generated/torch.linalg.vander.html#torch.linalg.vander) + +```python +torch.linalg.vander(x, N=None) +``` + +### [paddle.vander](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/vander_cn.html) + +```python +paddle.vander(x, n=None, increasing=False, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------ | +| x | x | 输入的 Tensor。 | +| N | n | 输出中的列数, 仅参数名不一致。 | +| - | increasing | 列的幂次顺序,PyTorch 无此参数,Paddle 设置为 True,需要转写。 | + +### 转写示例 + +#### increasing:列的幂次顺序 + +```python +# PyTorch 写法 +torch.linalg.vander(x) + +# Paddle 写法 +paddle.vander(x, increasing=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vector_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vector_norm.md new file mode 100644 index 00000000000..22a27ac7f5d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/linalg/torch.linalg.vector_norm.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.linalg.vector_norm + +### [torch.linalg.vector_norm](https://pytorch.org/docs/stable/generated/torch.linalg.vector_norm.html#torch.linalg.vector_norm) + +```python +torch.linalg.vector_norm(x, ord=2, dim=None, keepdim=False, *, dtype=None, out=None) +``` + +### [paddle.linalg.vector_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/vector_norm_cn.html) + +```python +paddle.linalg.vector_norm(x, p=2.0, axis=None, keepdim=False, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------- | +| x | x | 输入 Tensor。 | +| ord | p | 范数的种类,仅参数名不一致。 | +| dim | axis | 使用范数计算的轴 ,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 | +| dtype | - | 表示输出 Tensor 的数据类型, Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linalg.vector_norm(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.vector_norm(x), y) +``` + +#### dtype:表示输出 Tensor 的数据类型 + +```python +# PyTorch 写法 +torch.linalg.vector_norm(x, dtype=torch.float64) + +# Paddle 写法 +paddle.linalg.vector_norm(x.astype(paddle.float64)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool1d.md new file mode 100644 index 00000000000..0468943a3c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool1d.md @@ -0,0 +1,15 @@ +## [ 参数完全一致 ] torch.nn.AdaptiveAvgPool1d + +### [torch.nn.AdaptiveAvgPool1d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool1d.html) + +```python +torch.nn.AdaptiveAvgPool1d(output_size) +``` + +### [paddle.nn.AdaptiveAvgPool1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/AdaptiveAvgPool1D_cn.html#adaptiveavgpool1d) + +```python +paddle.nn.AdaptiveAvgPool1D(output_size, name=None) +``` + +两者功能一致,参数完全一致。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool2d.md new file mode 100644 index 00000000000..b59d7637594 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool2d.md @@ -0,0 +1,21 @@ +## [ 仅 paddle 参数更多 ] torch.nn.AdaptiveAvgPool2d + +### [torch.nn.AdaptiveAvgPool2d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool2d.html) + +```python +torch.nn.AdaptiveAvgPool2d(output_size) +``` + +### [paddle.nn.AdaptiveAvgPool2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/AdaptiveAvgPool2D_cn.html#adaptiveavgpool2d) + +```python +paddle.nn.AdaptiveAvgPool2D(output_size, data_format='NCHW', name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_size | 表示输出 Tensor 的 size 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool3d.md new file mode 100644 index 00000000000..f0c012e9ee5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveAvgPool3d.md @@ -0,0 +1,21 @@ +## [ 仅 paddle 参数更多 ] torch.nn.AdaptiveAvgPool3d + +### [torch.nn.AdaptiveAvgPool3d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveAvgPool3d.html) + +```python +torch.nn.AdaptiveAvgPool3d(output_size) +``` + +### [paddle.nn.AdaptiveAvgPool3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/AdaptiveAvgPool3D_cn.html#adaptiveavgpool3d) + +```python +paddle.nn.AdaptiveAvgPool3D(output_size, data_format='NCDHW', name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_size | 表示输出 Tensor 的 size 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool1d.md new file mode 100644 index 00000000000..06ebda32596 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool1d.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.nn.AdaptiveMaxPool1d +### [torch.nn.AdaptiveMaxPool1d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveMaxPool1d.html?highlight=adaptivemaxpool1d#torch.nn.AdaptiveMaxPool1d) + +```python +torch.nn.AdaptiveMaxPool1d(output_size, + return_indices=False) +``` + +### [paddle.nn.AdaptiveMaxPool1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AdaptiveMaxPool1D_cn.html#adaptivemaxpool1d) + +```python +paddle.nn.AdaptiveMaxPool1D(output_size, + return_mask=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_size | 表示输出 Tensor 的大小。 | +| return_indices | return_mask | 如果设置为 True,则会与输出一起返回最大值的索引,默认为 False,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool2d.md new file mode 100644 index 00000000000..1fd40b4fbf1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool2d.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.nn.AdaptiveMaxPool2d +### [torch.nn.AdaptiveMaxPool2d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveMaxPool2d.html?highlight=adaptivemaxpool2d#torch.nn.AdaptiveMaxPool2d) + +```python +torch.nn.AdaptiveMaxPool2d(output_size, + return_indices=False) +``` + +### [paddle.nn.AdaptiveMaxPool2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AdaptiveMaxPool2D_cn.html#adaptivemaxpool2d) + +```python +paddle.nn.AdaptiveMaxPool2D(output_size, + return_mask=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_size | 表示输出 Tensor 的大小。 | +| return_indices | return_mask | 如果设置为 True,则会与输出一起返回最大值的索引,默认为 False,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool3d.md new file mode 100644 index 00000000000..3e81f24a6d3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AdaptiveMaxPool3d.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.nn.AdaptiveMaxPool3d +### [torch.nn.AdaptiveMaxPool3d](https://pytorch.org/docs/stable/generated/torch.nn.AdaptiveMaxPool3d.html?highlight=adaptivemaxpool3d#torch.nn.AdaptiveMaxPool3d) + +```python +torch.nn.AdaptiveMaxPool3d(output_size, + return_indices=False) +``` + +### [paddle.nn.AdaptiveMaxPool3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AdaptiveMaxPool3D_cn.html#adaptivemaxpool3d) + +```python +paddle.nn.AdaptiveMaxPool3D(output_size, + return_mask=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_size | 表示输出 Tensor 的大小。 | +| return_indices| return_mask | 如果设置为 True,则会与输出一起返回最大值的索引,默认为 False,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AlphaDropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AlphaDropout.md new file mode 100644 index 00000000000..87684f418fe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AlphaDropout.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.nn.AlphaDropout + +### [torch.nn.AlphaDropout](https://pytorch.org/docs/stable/generated/torch.nn.AlphaDropout.html#torch.nn.AlphaDropout) + +```python +torch.nn.AlphaDropout(p=0.5, inplace=False) +``` + +### [paddle.nn.AlphaDropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AlphaDropout_cn.html) + +```python +paddle.nn.AlphaDropout(p=0.5, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| p | p | 将输入节点置 0 的概率,即丢弃概率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool1d.md new file mode 100644 index 00000000000..3d36659f015 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool1d.md @@ -0,0 +1,43 @@ +## [ 参数不一致 ]torch.nn.AvgPool1d +### [torch.nn.AvgPool1d](https://pytorch.org/docs/stable/generated/torch.nn.AvgPool1d.html?highlight=avgpool1d#torch.nn.AvgPool1d) + +```python +torch.nn.AvgPool1d(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + count_include_pad=True) +``` + +### [paddle.nn.AvgPool1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AvgPool1D_cn.html#avgpool1d) + +```python +paddle.nn.AvgPool1D(kernel_size, + stride=None, + padding=0, + exclusive=True, + ceil_mode=False, + name=None) +``` + +其中 PyTorch 的 count_include_pad 与 Paddle 的 exclusive 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核的尺寸大小 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | +| count_include_pad | - | 是否使用额外 padding 的值计算平均池化结果,默认为 True 。 | +| - | exclusive | 是否不使用额外 padding 的值计算平均池化结果,默认为 True 。 | + +### 转写示例 +#### count_include_pad:是否使用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.AvgPool1D(kernel_size=2, stride=2, count_include_pad=True) + +# Paddle 写法 +paddle.nn.AvgPool1D(kernel_size=2, stride=2, exclusive=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool2d.md new file mode 100644 index 00000000000..b921da13117 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool2d.md @@ -0,0 +1,48 @@ +## [ 参数不一致 ]torch.nn.AvgPool2d +### [torch.nn.AvgPool2d](https://pytorch.org/docs/stable/generated/torch.nn.AvgPool2d.html?highlight=avgpool2d#torch.nn.AvgPool2d) + +```python +torch.nn.AvgPool2d(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + count_include_pad=True, + divisor_override=None) +``` + +### [paddle.nn.AvgPool2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AvgPool2D_cn.html#avgpool2d) + +```python +paddle.nn.AvgPool2D(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + exclusive=True, + divisor_override=None, + data_format='NCHW', + name=None) +``` + +其中 PyTorch 的 count_include_pad 与 Paddle 的 exclusive 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核的尺寸大小 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | +| count_include_pad | - | 是否使用额外 padding 的值计算平均池化结果,默认为 True 。 Paddle 无此参数,需要转写。 | +| divisor_override | divisor_override | 如果指定,它将用作除数,否则根据 kernel_size 计算除数。默认 None 。 | +| - | exclusive | 是否不使用额外 padding 的值计算平均池化结果,默认为 True。 | +| - | data_format | 输入和输出的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | + +### 转写示例 +#### count_include_pad:是否使用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.AvgPool2D(kernel_size=2, stride=2, count_include_pad=True) + +# Paddle 写法 +paddle.nn.AvgPool2D(kernel_size=2, stride=2, exclusive=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool3d.md new file mode 100644 index 00000000000..334035eb893 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.AvgPool3d.md @@ -0,0 +1,48 @@ +## [ 参数不一致 ]torch.nn.AvgPool3d +### [torch.nn.AvgPool3d](https://pytorch.org/docs/stable/generated/torch.nn.AvgPool3d.html?highlight=avgpool3d#torch.nn.AvgPool3d) + +```python +torch.nn.AvgPool3d(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + count_include_pad=True, + divisor_override=None) +``` + +### [paddle.nn.AvgPool3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/AvgPool3D_cn.html#avgpool3d) + +```python +paddle.nn.AvgPool3D(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + exclusive=True, + divisor_override=None, + data_format='NCDHW', + name=None) +``` + +其中 PyTorch 的 count_include_pad 与 Paddle 的 exclusive 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核的尺寸大小 。 | +| stride | stride | 表示步长 。 | +| padding | padding | 表示填充大小 。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | +| count_include_pad | - | 是否使用额外 padding 的值计算平均池化结果,默认为 True 。 Paddle 无此参数,需要转写。 | +| divisor_override | divisor_override | 如果指定,它将用作除数,否则根据 kernel_size 计算除数。默认 None 。 | +| - | exclusive | 是否不使用额外 padding 的值计算平均池化结果,默认为 True。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### count_include_pad:是否使用额外 padding 的值计算平均池化结果 +```python +# PyTorch 写法 +torch.nn.AvgPool3D(kernel_size=2, stride=2, count_include_pad=True) + +# Paddle 写法 +paddle.nn.AvgPool3D(kernel_size=2, stride=2, exclusive=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md new file mode 100644 index 00000000000..b9dad3236b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCELoss.md @@ -0,0 +1,94 @@ +## [ torch 参数更多 ]torch.nn.BCELoss +### [torch.nn.BCELoss](https://pytorch.org/docs/stable/generated/torch.nn.BCELoss.html?highlight=bceloss#torch.nn.BCELoss) + +```python +torch.nn.BCELoss(weight=None, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.BCELoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/BCELoss_cn.html#bceloss) + +```python +paddle.nn.BCELoss(weight=None, + reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| weight | weight | 表示每个 batch 二值交叉熵的权重。 | +| size_average | - | PyTorch 已弃用,paddle 需要转写。 | +| reduce | - | PyTorch 已弃用,paddle 需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 +#### size_average +size_average 为 True +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='mean') +``` + +size_average 为 False +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='mean') +``` + +reduce 为 False +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='none') +``` + +reduction 为'mean' +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='mean') +``` + +reduction 为'sum' +```python +# PyTorch 写法 +torch.nn.BCELoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.BCELoss(weight=w, reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md new file mode 100644 index 00000000000..b79e5fdfa26 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BCEWithLogitsLoss.md @@ -0,0 +1,97 @@ +## [ torch 参数更多 ]torch.nn.BCEWithLogitsLoss +### [torch.nn.BCEWithLogitsLoss](https://pytorch.org/docs/stable/generated/torch.nn.BCEWithLogitsLoss.html#bcewithlogitsloss) + +```python +torch.nn.BCEWithLogitsLoss(weight=None, + size_average=None, + reduce=None, + reduction='mean', + pos_weight=None) +``` + +### [paddle.nn.BCEWithLogitsLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/BCEWithLogitsLoss_cn.html#bcewithlogitsloss) + +```python +paddle.nn.BCEWithLogitsLoss(weight=None, + reduction='mean', + pos_weight=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| weight | weight | 表示每个 batch 二值交叉熵的权重。 | +| size_average | - | PyTorch 已弃用,paddle 需要转写。 | +| reduce | - | PyTorch 已弃用,paddle 需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | +| pos_weight | pos_weight | 表示正类的权重。 | + +### 转写示例 +#### size_average +size_average 为 True +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean') +``` + +size_average 为 False +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean') +``` + +reduce 为 False +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='none') +``` + +reduction 为'mean' +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' +```python +# PyTorch 写法 +torch.nn.BCEWithLogitsLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.BCEWithLogitsLoss(weight=w, reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm1d.md new file mode 100644 index 00000000000..3b8bf8fe0f1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm1d.md @@ -0,0 +1,91 @@ +## [ 参数不一致 ]torch.nn.BatchNorm1d +### [torch.nn.BatchNorm1d](https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm1d.html?highlight=torch%20nn%20batchnorm1d#torch.nn.BatchNorm1d) + +```python +torch.nn.BatchNorm1d(num_features, + eps=1e-05, + momentum=0.1, + affine=True, + track_running_stats=True) +``` + +### [paddle.nn.BatchNorm1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/BatchNorm1D_cn.html#batchnorm1d) + +```python +paddle.nn.BatchNorm1D(num_features, + momentum=0.9, + epsilon=1e-05, + weight_attr=None, + bias_attr=None, + data_format='NCL', + use_global_stats=True, + name=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |-----------------------------------------------------------------------------------------------------------------------------| +| num_features | num_features | 表示输入 Tensor 通道数。 | +| eps | epsilon | 为了数值稳定加在分母上的值,仅参数名不一致。 | +| momentum | momentum | 表示归一化函数中的超参数, PyTorch 和 Paddle 公式实现细节不一致,两者正好是相反的,需要转写。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | +| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| affine | - | 是否进行反射变换, Paddle 无此参数,需要转写。 | +| track_running_stats | use_global_stats | 指示是否使用全局均值和方差,PyTorch 设置为 True,Paddle 需设置为 False;PyTorch 设置为 None,Paddle 需设置为 True;PyTorch 设置为 False,Paddle 需设置为 True,需要转写。 | + +### 转写示例 +#### affine:是否进行反射变换 +```python +affine=False 时,表示不更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, affine=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24, weight_attr=False, bias_attr=False) + +affine=True 时,表示更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24) +``` + +#### momentum: +```python +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, momentum=0.2) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24, momentum=0.8) +``` + +#### track_running_stats:指示是否使用全局均值和方差 + +```python +track_running_stats=None 时: +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, track_running_stats=None) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24, use_global_stats=True) + +track_running_stats=True 时: +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, track_running_stats=True) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24, use_global_stats=False) + +track_running_stats=False 时: +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, track_running_stats=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24, use_global_stats=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md new file mode 100644 index 00000000000..bffb8efdb2d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm2d.md @@ -0,0 +1,100 @@ +## [ 参数不一致 ]torch.nn.BatchNorm2d + +### [torch.nn.BatchNorm2d](https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm2d.html?highlight=batchnorm2d#torch.nn.BatchNorm2d) + +```python +torch.nn.BatchNorm2d(num_features, + eps=1e-05, + momentum=0.1, + affine=True, + track_running_stats=True) +``` + +### [paddle.nn.BatchNorm2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/BatchNorm2D_cn.html#batchnorm2d) + +```python +paddle.nn.BatchNorm2D(num_features, + momentum=0.9, + epsilon=1e-05, + weight_attr=None, + bias_attr=None, + data_format='NCHW', + use_global_stats=True, + name=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------------------|------------------|---------------------------------------------------------------------------------------------------------------------| +| num_features | num_features | 表示输入 Tensor 通道数。 | +| eps | epsilon | 为了数值稳定加在分母上的值,仅参数名不一致。 | +| momentum | momentum | 表示归一化函数中的超参数, PyTorch 和 Paddle 公式实现细节不一致,两者正好是相反的,需要转写。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | +| - | data_format | 指定输入数据格式, PyTorch 无此参数,Paddle 保持默认即可。 | +| affine | - | 是否进行反射变换, Paddle 无此参数,需要转写。 | +| track_running_stats | use_global_stats | 指示是否使用全局均值和方差,PyTorch 设置为 True,Paddle 需设置为 False;PyTorch 设置为 None,Paddle 需设置为 True;PyTorch 设置为 False,Paddle 需设置为 True,需要转写。 | + + + +### 转写示例 + +#### affine:是否进行反射变换 + +```python +affine = False +时,表示不更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm2D(24, affine=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24, weight_attr=False, bias_attr=False) + +affine = True +时,表示更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm2D(24) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24) +``` + +#### momentum: + +```python +# PyTorch 写法 +m = torch.nn.BatchNorm2D(24, momentum=0.2) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24, momentum=0.8) +``` + +#### track_running_stats:指示是否使用全局均值和方差 + +```python +track_running_stats=None 时: +# PyTorch 写法 +m = torch.nn.BatchNorm2D(24, track_running_stats=None) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24, use_global_stats=True) + +track_running_stats=True 时: +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, track_running_stats=True) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24, use_global_stats=False) + +track_running_stats=False 时: +# PyTorch 写法 +m = torch.nn.BatchNorm2D(24, track_running_stats=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm2D(24, use_global_stats=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm3d.md new file mode 100644 index 00000000000..6e30b4c9354 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.BatchNorm3d.md @@ -0,0 +1,90 @@ +## [ 参数不一致 ]torch.nn.BatchNorm3d +### [torch.nn.BatchNorm3d](https://pytorch.org/docs/stable/generated/torch.nn.BatchNorm3d.html?highlight=torch%20nn%20batchnorm3d#torch.nn.BatchNorm3d) + +```python +torch.nn.BatchNorm3d(num_features, + eps=1e-05, + momentum=0.1, + affine=True, + track_running_stats=True) +``` + +### [paddle.nn.BatchNorm3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/BatchNorm3D_cn.html#batchnorm3d) + +```python +paddle.nn.BatchNorm3D(num_features, + momentum=0.9, + epsilon=1e-05, + weight_attr=None, + bias_attr=None, + data_format='NCDHW', + use_global_stats=True, + name=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_features | num_features | 表示输入 Tensor 通道数。 | +| eps | epsilon | 为了数值稳定加在分母上的值,仅参数名不一致。 | +| momentum | momentum | 表示归一化函数中的超参数, PyTorch 和 Paddle 公式实现细节不一致,两者正好是相反的,需要转写。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | +| - | data_format | 指定输入数据格式, PyTorch 无此参数,Paddle 保持默认即可。 | +| affine | - | 是否进行反射变换, Paddle 无此参数,需要转写。 | +| track_running_stats | use_global_stats | 指示是否使用全局均值和方差,PyTorch 设置为 True,Paddle 需设置为 False;PyTorch 设置为 None,Paddle 需设置为 True;PyTorch 设置为 False,Paddle 需设置为 True,需要转写。 | + +### 转写示例 +#### affine:是否进行反射变换 +```python +affine=False 时,表示不更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24, affine=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24, weight_attr=False, bias_attr=False) + +affine=True 时,表示更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24) +``` + +#### momentum: +```python +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24, momentum=0.2) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24, momentum=0.8) +``` +#### track_running_stats:指示是否使用全局均值和方差 + +```python +track_running_stats=None 时: +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24, track_running_stats=None) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24, use_global_stats=True) + +track_running_stats=True 时: +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24, track_running_stats=True) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24, use_global_stats=False) + +track_running_stats=False 时: +# PyTorch 写法 +m = torch.nn.BatchNorm3D(24, track_running_stats=False) + +# Paddle 写法 +m = paddle.nn.BatchNorm3D(24, use_global_stats=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Bilinear.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Bilinear.md new file mode 100644 index 00000000000..800b69c04e6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Bilinear.md @@ -0,0 +1,53 @@ +## [torch 参数更多]torch.nn.Bilinear + +### [torch.nn.Bilinear](https://pytorch.org/docs/stable/generated/torch.nn.Bilinear.html#torch.nn.Bilinear) + +```python +torch.nn.Bilinear(in1_features, in2_features, out_features, bias=True, device=None, dtype=None) +``` + +### [paddle.nn.Bilinear](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Bilinear_cn.html) + +```python +paddle.nn.Bilinear(in1_features, in2_features, out_features, weight_attr=None, bias_attr=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | --------------------------------------------------------------- | +| in1_features | in1_features | 每个 x1 元素的维度。 | +| in2_features | in2_features | 每个 x2 元素的维度。 | +| out_features | out_features | 输出张量的维度。 | +| bias | bias_attr | 指定偏置参数属性的对象,Paddle 支持更多功能,同时支持 bool 用法。 | +| device | - | Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### device:Tensor 的设备 + +```python +# PyTorch 写法 +m = torch.nn.Bilinear(in1_features, in2_features, out_features,device=torch.device('cpu')) +y = m(x) + +# Paddle 写法 +m = paddle.nn.Bilinear(in1_features, in2_features, out_features) +y = m(x).cpu() +``` + +#### dtype:Tensor 的数据类型 + +```python +# PyTorch 写法 +m = torch.nn.Bilinear(in1_features, in2_features, out_features,dtype=torch.float32) +y = m(x) + +# Paddle 写法 +m = paddle.nn.Bilinear(in1_features, in2_features, out_features) +y = m(x).astype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CELU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CELU.md new file mode 100644 index 00000000000..c35de1e2db3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CELU.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.nn.CELU + +### [torch.nn.CELU](https://pytorch.org/docs/stable/generated/torch.nn.CELU.html#torch.nn.CELU) + +```python +torch.nn.CELU(alpha=1.0, inplace=False) +``` + +### [paddle.nn.CELU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/CELU_cn.html) + +```python +paddle.nn.CELU(alpha=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| alpha | alpha | CELU 的 alpha 值。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md new file mode 100644 index 00000000000..a77cc48eb00 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CTCLoss.md @@ -0,0 +1,26 @@ +## [torch 参数更多]torch.nn.CTCLoss + +### [torch.nn.CTCLoss](https://pytorch.org/docs/stable/generated/torch.nn.CTCLoss.html#torch.nn.CTCLoss) + +```python +torch.nn.CTCLoss(blank=0, + reduction='mean', + zero_infinity=False) +``` + +### [paddle.nn.CTCLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/CTCLoss_cn.html#ctcloss) + +```python +paddle.nn.CTCLoss(blank=0, + reduction='mean') +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------- | --------- | ------------------------------------------------------------ | +| blank | blank | 空格标记的 ID 值。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | +| zero_infinity | - | 是否将无穷大损失及其梯度置 0,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ChannelShuffle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ChannelShuffle.md new file mode 100644 index 00000000000..288689366d6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ChannelShuffle.md @@ -0,0 +1,21 @@ +## [ 仅 paddle 参数更多 ]torch.nn.ChannelShuffle + +### [torch.nn.ChannelShuffle](https://pytorch.org/docs/stable/generated/torch.nn.ChannelShuffle.html?highlight=channelshuffle#torch.nn.ChannelShuffle) + +```python +torch.nn.ChannelShuffle(groups) +``` + +### [paddle.nn.ChannelShuffle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ChannelShuffle_cn.html) + +```python +paddle.nn.ChannelShuffle(groups, data_format='NCHW', name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| groups | groups | 表示要把通道分成的组数 。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad1d.md new file mode 100644 index 00000000000..2bf6c4540e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad1d.md @@ -0,0 +1,39 @@ +## [ 仅 paddle 参数更多 ]torch.nn.ConstantPad1d +### [torch.nn.ConstantPad1d](https://pytorch.org/docs/stable/generated/torch.nn.ConstantPad1d.html?highlight=constantpad1d#torch.nn.ConstantPad1d) + +```python +torch.nn.ConstantPad1d(padding, + value) +``` + +### [paddle.nn.Pad1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad1D_cn.html#pad1d) + +```python +paddle.nn.Pad1D(padding, + mode='constant', + value=0.0, + data_format='NCL', + name=None) +``` + +其中 Paddle 和 PyTorch 的 padding 参数所支持的类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| value | value | 以 'constant' 模式填充区域时填充的值。默认值为 0.0 。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ConstantPad1d((3, 1), 3.5) +m(input) + +# Paddle 写法 +m = nn.Pad1D([3, 1], value=3.5) +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad2d.md new file mode 100644 index 00000000000..38da3a0fc1f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad2d.md @@ -0,0 +1,37 @@ +## [ 仅 paddle 参数更多 ]torch.nn.ConstantPad2d +### [torch.nn.ConstantPad2d](https://pytorch.org/docs/stable/generated/torch.nn.ConstantPad2d.html?highlight=pad#torch.nn.ConstantPad2d) +```python +torch.nn.ConstantPad2d(padding, + value) +``` + +### [paddle.nn.Pad2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad2D_cn.html#pad2d) +```python +paddle.nn.Pad2D(padding, + mode='constant', + value=0.0, + data_format='NCHW', + name=None) +``` + +其中 Paddle 和 PyTorch 的 padding 参数所支持的类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| value | value | 以 'constant' 模式填充区域时填充的值。默认值为 0.0 。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ConstantPad2d((3, 1), 3.5) +m(input) + +# Paddle 写法 +m = nn.Pad2D([3, 1], value=3.5) +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad3d.md new file mode 100644 index 00000000000..1f529aff1d1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConstantPad3d.md @@ -0,0 +1,37 @@ +## [ 仅 paddle 参数更多 ]torch.nn.ConstantPad3d +### [torch.nn.ConstantPad3d](https://pytorch.org/docs/stable/generated/torch.nn.ConstantPad3d.html?highlight=pad#torch.nn.ConstantPad3d) +```python +torch.nn.ConstantPad3d(padding, + value) +``` + +### [paddle.nn.Pad3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad3D_cn.html#pad3d) +```python +paddle.nn.Pad3D(padding, + mode='constant', + value=0.0, + data_format='NCDHW', + name=None) +``` + +其中 Paddle 和 PyTorch 的 padding 参数所支持的类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| value | value | 以 'constant' 模式填充区域时填充的值。默认值为 0.0 。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ConstantPad3d((3, 1), 3.5) +m(input) + +# Paddle 写法 +m = nn.Pad3D([3, 1], value=3.5) +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv1d.md new file mode 100644 index 00000000000..59a23497a62 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv1d.md @@ -0,0 +1,70 @@ +## [ 参数不一致 ]torch.nn.Conv1d +### [torch.nn.Conv1d](https://pytorch.org/docs/stable/generated/torch.nn.Conv1d.html?highlight=conv1d#torch.nn.Conv1d) + +```python +torch.nn.Conv1d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + bias=True, + padding_mode='zeros', + device=None, + dtype=None) +``` + +### [paddle.nn.Conv1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv1D_cn.html#conv1d) + +```python +paddle.nn.Conv1D(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + padding_mode='zeros', + weight_attr=None, + bias_attr=None, + data_format='NCL') +``` + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | dilation | 表示空洞大小。 | +| groups | groups | 表示分组数。 | +| `bias` | - | 是否在输出中添加可学习的 bias, Paddle 无此参数,需要转写。 | +| padding_mode | padding_mode | 表示填充模式。 | +| device | - | 指定 Tensor 的设备,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 指定权重参数属性的对象,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | Tensor 的所需数据类型,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.Conv1D(16, 33, 3, bias=True) + +# Paddle 写法 +paddle.nn.Conv1D(16, 33, 3) +``` +```python +# PyTorch 写法 +torch.nn.Conv1D(16, 33, 3, bias=False) + +# Paddle 写法 +paddle.nn.Conv1D(16, 33, 3, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv2d.md new file mode 100644 index 00000000000..a02fda3aece --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv2d.md @@ -0,0 +1,70 @@ +## [ 参数不一致 ]torch.nn.Conv2d +### [torch.nn.Conv2d](https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html?highlight=conv2d#torch.nn.Conv2d) + +```python +torch.nn.Conv2d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + bias=True, + padding_mode='zeros', + device=None, + dtype=None) +``` + +### [paddle.nn.Conv2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv2D_cn.html#conv2d) + +```python +paddle.nn.Conv2D(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + padding_mode='zeros', + weight_attr=None, + bias_attr=None, + data_format='NCHW') +``` + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | dilation | 表示空洞大小。 | +| groups | groups | 表示分组数。 | +| `bias` | - | 是否在输出中添加可学习的 bias。 | +| padding_mode | padding_mode | 表示填充模式。 | +| device | - | 指定 Tensor 的设备,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 指定权重参数属性的对象,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | Tensor 的所需数据类型,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.Conv2D(16, 33, 3, bias=True) + +# Paddle 写法 +paddle.nn.Conv2D(16, 33, 3) +``` +```python +# PyTorch 写法 +torch.nn.Conv2D(16, 33, 3, bias=False) + +# Paddle 写法 +paddle.nn.Conv2D(16, 33, 3, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv3d.md new file mode 100644 index 00000000000..801cfaf2d38 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Conv3d.md @@ -0,0 +1,71 @@ +## [ 参数不一致 ]torch.nn.Conv3d +### [torch.nn.Conv3d](https://pytorch.org/docs/stable/generated/torch.nn.Conv3d.html?highlight=conv3d#torch.nn.Conv3d) + +```python +torch.nn.Conv3d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + bias=True, + padding_mode='zeros', + device=None, + dtype=None) +``` + +### [paddle.nn.Conv3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv3D_cn.html#conv3d) + +```python +paddle.nn.Conv3D(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + dilation=1, + groups=1, + padding_mode='zeros', + weight_attr=None, + bias_attr=None, + data_format='NCDHW') +``` + + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | dilation | 表示空洞大小。 | +| groups | groups | 表示分组数。 | +| `bias` | - | 是否在输出中添加可学习的 bias。 | +| padding_mode | padding_mode | 表示填充模式。 | +| device | - | 指定 Tensor 的设备,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 指定权重参数属性的对象,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | Tensor 的所需数据类型,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.Conv3D(16, 33, 3, bias=True) + +# Paddle 写法 +paddle.nn.Conv3D(16, 33, 3) +``` +```python +# PyTorch 写法 +torch.nn.Conv3D(16, 33, 3, bias=False) + +# Paddle 写法 +paddle.nn.Conv3D(16, 33, 3, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose1d.md new file mode 100644 index 00000000000..9c1fda904bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose1d.md @@ -0,0 +1,70 @@ +## [ 参数不一致 ]torch.nn.ConvTranspose1d +### [torch.nn.ConvTranspose1d](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose1d.html?highlight=convtranspose1d#torch.nn.ConvTranspose1d) +```python +torch.nn.ConvTranspose1d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + bias=True, + dilation=1, + padding_mode='zeros', + device=None, + dtype=None) +``` + +### [paddle.nn.Conv1DTranspose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv1DTranspose_cn.html#conv1dtranspose) +```python +paddle.nn.Conv1DTranspose(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + weight_attr=None, + bias_attr=None, + data_format='NCL') +``` + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| output_padding | output_padding | 表示输出 Tensor 额外添加的大小。 | +| groups | groups | 表示分组数。 | +| `bias` | - | 是否在输出中添加可学习的 bias。 | +| dilation | dilation | 表示空洞大小。 | +| padding_mode | - | 填充模式,Paddle 无此参数,暂无转写方式。 | +| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.ConvTranspose1d(2, 1, 2, bias=True) + +# Paddle 写法 +paddle.nn.Conv1DTranspose(2, 1, 2) +``` +```python +# PyTorch 写法 +torch.nn.ConvTranspose1d(2, 1, 2, bias=False) + +# Paddle 写法 +paddle.nn.Conv1DTranspose(2, 1, 2, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose2d.md new file mode 100644 index 00000000000..c34c41dba40 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose2d.md @@ -0,0 +1,68 @@ +## [ 参数不一致 ]torch.nn.ConvTranspose2d +### [torch.nn.ConvTranspose2d](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html?highlight=convtranspose2d#torch.nn.ConvTranspose2d) +```python +torch.nn.ConvTranspose2d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + bias=True, + dilation=1, + padding_mode='zeros') +``` + +### [paddle.nn.Conv2DTranspose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv2DTranspose_cn.html#conv2dtranspose) +```python +paddle.nn.Conv2DTranspose(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + weight_attr=None, + bias_attr=None, + data_format='NCHW') +``` + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| output_padding | output_padding | 表示输出 Tensor 额外添加的大小。 | +| groups | groups | 表示分组数。 | +| `bias` | - | 是否在输出中添加可学习的 bias。 | +| dilation | dilation | 表示空洞大小。 | +| padding_mode | - | 填充模式,Paddle 无此参数,暂无转写方式。 | +| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.ConvTranspose2d(4, 6, (3, 3), bias=True) + +# Paddle 写法 +paddle.nn.Conv2DTranspose(4, 6, (3, 3)) +``` +```python +# PyTorch 写法 +torch.nn.ConvTranspose2d(4, 6, (3, 3), bias=False) + +# Paddle 写法 +paddle.nn.Conv2DTranspose(4, 6, (3, 3), bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose3d.md new file mode 100644 index 00000000000..a33c7b93b2b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ConvTranspose3d.md @@ -0,0 +1,69 @@ +## [ 参数不一致 ]torch.nn.ConvTranspose3d +### [torch.nn.ConvTranspose3d](https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose3d.html?highlight=convtranspose3d#torch.nn.ConvTranspose3d) +```python +torch.nn.ConvTranspose3d(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + bias=True, + dilation=1, + padding_mode='zeros') +``` + +### [paddle.nn.Conv3DTranspose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Conv3DTranspose_cn.html#conv3dtranspose) +```python +paddle.nn.Conv3DTranspose(in_channels, + out_channels, + kernel_size, + stride=1, + padding=0, + output_padding=0, + groups=1, + dilation=1, + weight_attr=None, + bias_attr=None, + data_format='NCDHW') +``` + + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_channels | in_channels | 表示输入 Tensor 通道数。 | +| out_channels | out_channels | 表示输出 Tensor 通道数。 | +| kernel_size | kernel_size | 表示卷积核大小。 | +| stride | stride | 表示卷积核步长。 | +| padding | padding | 表示填充大小。 | +| output_padding | output_padding | 表示输出 Tensor 额外添加的大小。 | +| groups | groups | 表示分组数。 | +| `bias ` | - | 是否在输出中添加可学习的 bias。 | +| dilation | dilation | 表示空洞大小。 | +| padding_mode | - | 填充模式,Paddle 无此参数,暂无转写方式。 | +| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,当`bias_attr`设置为 bool 类型与 PyTorch 的作用一致。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.ConvTranspose3d(4, 6, (3, 3, 3), bias=True) + +# Paddle 写法 +paddle.nn.Conv3DTranspose(4, 6, (3, 3, 3)) +``` +```python +# PyTorch 写法 +torch.nn.ConvTranspose3d(4, 6, (3, 3, 3), bias=False) + +# Paddle 写法 +paddle.nn.Conv3DTranspose(4, 6, (3, 3, 3), bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineEmbeddingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineEmbeddingLoss.md new file mode 100644 index 00000000000..330c7d26585 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineEmbeddingLoss.md @@ -0,0 +1,41 @@ +## [torch 参数更多]torch.nn.CosineEmbeddingLoss + +### [torch.nn.CosineEmbeddingLoss](https://pytorch.org/docs/stable/generated/torch.nn.CosineEmbeddingLoss.html#torch.nn.CosineEmbeddingLoss) + +```python +torch.nn.CosineEmbeddingLoss(margin=0.0, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.CosineEmbeddingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/CosineEmbeddingLoss_cn.html) + +```python +paddle.nn.CosineEmbeddingLoss(margin=0, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ---------------------------------------------- | +| margin | margin | 可以设置的范围为[-1, 1]。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineSimilarity.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineSimilarity.md new file mode 100644 index 00000000000..987a49d45c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CosineSimilarity.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.CosineSimilarity +### [torch.nn.CosineSimilarity](https://pytorch.org/docs/stable/generated/torch.nn.CosineSimilarity.html?highlight=nn+cosinesimilarity#torch.nn.CosineSimilarity) + +```python +torch.nn.CosineSimilarity(dim=1, + eps=1e-08) +``` + +### [paddle.nn.CosineSimilarity](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/CosineSimilarity_cn.html#cosinesimilarity) + +```python +paddle.nn.CosineSimilarity(axis=1, + eps=1e-8) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定计算的维度,会在该维度上计算余弦相似度,默认值为 1。 | +| eps | eps | 表示计算余弦相似度公式中的超参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md new file mode 100644 index 00000000000..9defe9873a0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.CrossEntropyLoss.md @@ -0,0 +1,103 @@ +## [torch 参数更多]torch.nn.CrossEntropyLoss +### [torch.nn.CrossEntropyLoss](https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html#torch.nn.CrossEntropyLoss) + +```python +torch.nn.CrossEntropyLoss(weight=None, + size_average=None, + ignore_index=- 100, + reduce=None, + reduction='mean', + label_smoothing=0.0) +``` + +### [paddle.nn.CrossEntropyLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/CrossEntropyLoss_cn.html#crossentropyloss) + +```python +paddle.nn.CrossEntropyLoss(weight=None, + ignore_index=-100, + reduction='mean', + soft_label=False, + axis=-1, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| weight | weight | 表示每个类别的权重。 | +| size_average | - | PyTorch 已弃用,Paddle 无此参数,需要转写。| +| ignore_index | ignore_index | 表示忽略的一个标签值。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | +| label_smoothing | - | 指定计算损失时的平滑量,Paddle 无此参数,暂无转写方式。 | +| - | soft_label | 指明 label 是否为软标签,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | axis | 进行 softmax 计算的维度索引,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### size_average +size_average 为 True +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='mean') +``` + +size_average 为 False +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='sum') +``` + +#### reduce +reduce 为 True +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='mean') +``` + +reduce 为 False +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='none') +``` + +#### reduction +reduction 为'none' +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='none') +``` + +reduction 为'mean' +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' +```python +# PyTorch 写法 +torch.nn.CrossEntropyLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.CrossEntropyLoss(weight=w, reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.DataParallel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.DataParallel.md new file mode 100644 index 00000000000..d99352dc8a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.DataParallel.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ]torch.nn.DataParallel +### [torch.nn.DataParallel](https://pytorch.org/docs/stable/generated/torch.nn.DataParallel.html?highlight=dataparallel#torch.nn.DataParallel) + +```python +torch.nn.DataParallel(module, + device_ids=None, + output_device=None, + dim=0) +``` + +### [paddle.DataParallel](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/DataParallel_cn.html#dataparallel) + +```python +paddle.DataParallel(layers, + strategy=None, + comm_buffer_size=25, + last_comm_buffer_size=1, + find_unused_parameters=False) +``` + +两者功能一致但参数不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| module | layers | 需要通过数据并行方式执行的模型。 | +| device_ids | - | 表示训练在哪几块 GPU 上,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| output_device | - | 表示结果输出在哪一块 GPU 上,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dim | - | 表示哪一维度上的数据进行划分,Paddle 无此参数。 | +| - | strategy | PaddlePaddle 即将废弃参数。 | +| - | comm_buffer_size | 它是通信调用(如 NCCLAllReduce)时,参数梯度聚合为一组的内存大小(MB),PyTorch 无此参数,Paddle 保持默认即可。 | +| - | last_comm_buffer_size | 它限制通信调用中最后一个缓冲区的内存大小(MB),PyTorch 无此参数,Paddle 保持默认即可。 | +| - | find_unused_parameters | 是否在模型 forward 函数的返回值的所有张量中,遍历整个向后图,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 功能差异 +#### 使用差异 +***PyTorch***:在 API 中即可通过设置参数使用的 GPU id。 +***PaddlePaddle***:只能在启动代码时设置 GPU id,设置方式如下: +> python -m paddle.distributed.launch –selected_gpus=0,1 demo.py +> 其中 demo.py 脚本的代码可以是下面的示例代码。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout.md new file mode 100644 index 00000000000..fb8b79c425f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.nn.Dropout +### [torch.nn.Dropout](https://pytorch.org/docs/stable/generated/torch.nn.Dropout.html?highlight=dropout#torch.nn.Dropout) +```python +torch.nn.Dropout(p=0.5, + inplace=False) +``` + +### [paddle.nn.Dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Dropout_cn.html#dropout) +```python +paddle.nn.Dropout(p=0.5, + axis=None, + mode="upscale_in_train”, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| p | p | 表示丢弃概率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | axis | 指定对输入 Tensor 进行 Dropout 操作的轴,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | mode | 表示丢弃单元的方式,PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout1d.md new file mode 100644 index 00000000000..bc6cee01650 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout1d.md @@ -0,0 +1,28 @@ +## [ torch 参数更多 ]torch.nn.Dropout1d + +### [torch.nn.Dropout1d](https://pytorch.org/docs/stable/generated/torch.nn.Dropout1d.html#torch.nn.Dropout1d) + +```python +torch.nn.Dropout1d(p=0.5, + inplace=False) +``` + +### [paddle.nn.Dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Dropout_cn.html#dropout) + +```python +paddle.nn.Dropout(p=0.5, + axis=None, + mode="upscale_in_train”, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| p | p | 表示丢弃概率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | axis | 指定对输入 Tensor 进行 Dropout 操作的轴,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | mode | 表示丢弃单元的方式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout2d.md new file mode 100644 index 00000000000..17517ea24ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout2d.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ] torch.nn.Dropout2d + +### [torch.nn.Dropout2d](https://pytorch.org/docs/stable/generated/torch.nn.Dropout2d.html?highlight=dropout2d#torch.nn.Dropout2d) +```python +torch.nn.Dropout2d(p=0.5, + inplace=False) +``` +### [paddle.nn.Dropout2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Dropout2D_cn.html#dropout2d) +```python +paddle.nn.Dropout2D(p=0.5, + data_format='NCHW', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| p | p | 表示丢弃概率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | data_format | 指定对输入的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout3d.md new file mode 100644 index 00000000000..d8fa53768a1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Dropout3d.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ]torch.nn.Dropout3d + +### [torch.nn.Dropout3d](https://pytorch.org/docs/stable/generated/torch.nn.Dropout3d.html?highlight=dropout3d#torch.nn.Dropout3d) +```python +torch.nn.Dropout3d(p=0.5, + inplace=False) +``` +### [paddle.nn.Dropout3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Dropout3D_cn.html#dropout3d) +```python +paddle.nn.Dropout3D(p=0.5, + data_format='NCDHW', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| p | p | 表示丢弃概率。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | data_format | 指定对输入的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ELU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ELU.md new file mode 100644 index 00000000000..52ee45bb8dc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ELU.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ]torch.nn.ELU +### [torch.nn.ELU](https://pytorch.org/docs/stable/generated/torch.nn.ELU.html?highlight=elu#torch.nn.ELU) + +```python +torch.nn.ELU(alpha=1.0, + inplace=False) +``` + +### [paddle.nn.ELU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ELU_cn.html#elu) + +```python +paddle.nn.ELU(alpha=1.0, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| alpha | alpha | 表示公式中的超参数。 | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Embedding.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Embedding.md new file mode 100644 index 00000000000..35c994ae034 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Embedding.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.nn.Embedding +### [torch.nn.Embedding](https://pytorch.org/docs/stable/generated/torch.nn.Embedding.html?highlight=embedding#torch.nn.Embedding) + +```python +torch.nn.Embedding(num_embeddings, + embedding_dim, + padding_idx=None, + max_norm=None, + norm_type=2.0, + scale_grad_by_freq=False, + sparse=False) +``` +### [paddle.nn.Embedding](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Embedding_cn.html#embedding) + +```python +paddle.nn.Embedding(num_embeddings, + embedding_dim, + padding_idx=None, + sparse=False, + weight_attr=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_embeddings | num_embeddings | 表示嵌入字典的大小。 | +| embedding_dim | embedding_dim | 表示每个嵌入向量的维度。 | +| padding_idx | padding_idx | 在此区间内的参数及对应的梯度将会以 0 进行填充 | +| max_norm | - | 如果给定,Embeddding 向量的范数(范数的计算方式由 norm_type 决定)超过了 max_norm 这个界限,就要再进行归一化,Paddle 无此参数,暂无转写方式。 | +| norm_type | - | 为 maxnorm 选项计算 p-范数的 p。默认值 2,Paddle 无此参数,暂无转写方式。 | +| scale_grad_by_freq | - | 是否根据单词在 mini-batch 中出现的频率,对梯度进行放缩,Paddle 无此参数,暂无转写方式。 | +| sparse | sparse | 表示是否使用稀疏更新。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Flatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Flatten.md new file mode 100644 index 00000000000..174f177c46f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Flatten.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.Flatten +### [torch.nn.Flatten](https://pytorch.org/docs/stable/generated/torch.nn.Flatten.html?highlight=nn+flatten#torch.nn.Flatten) + +```python +torch.nn.Flatten(start_dim=1, + end_dim=-1) +``` + +### [paddle.nn.Flatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Flatten_cn.html#flatten) + +```python +paddle.nn.Flatten(start_axis=1, + stop_axis=-1) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| start_dim | start_axis | 展开的起始维度,默认值为 1。 | +| end_dim | stop_axis | 展开的结束维度,默认值为 -1。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Fold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Fold.md new file mode 100644 index 00000000000..970d40819a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Fold.md @@ -0,0 +1,32 @@ +## [ 仅参数名不一致 ]torch.nn.Fold +### [torch.nn.Fold](https://pytorch.org/docs/stable/generated/torch.nn.Fold.html?highlight=nn+fold#torch.nn.Fold) + +```python +torch.nn.Fold(output_size, + kernel_size, + dilation=1, + padding=0, + stride=1) +``` + +### [paddle.nn.Fold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Fold_cn.html#fold) + +```python +paddle.nn.Fold(output_sizes, + kernel_sizes, + dilations=1, + paddings=0, + strides=1, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| output_size | output_sizes | 输出尺寸,整数或者整型列表。 | +| kernel_size | kernel_sizes | 卷积核大小,整数或者整型列表。 | +| dilation | dilations | 卷积膨胀,整型列表或者整数。 | +| padding | paddings | 每个维度的扩展,整数或者整型列表。 | +| stride | strides | 步长大小,整数或者整型列表。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool2d.md new file mode 100644 index 00000000000..6b106778d3f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool2d.md @@ -0,0 +1,49 @@ +## [ torch 参数更多 ]torch.nn.FractionalMaxPool2d + +### [torch.nn.FractionalMaxPool2d](https://pytorch.org/docs/stable/generated/torch.nn.FractionalMaxPool2d.html#fractionalmaxpool2d) + +```python +torch.nn.FractionalMaxPool2d(kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None) +``` + +### [paddle.nn.FractionalMaxPool2D](https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/nn/FractionalMaxPool2D_cn.html) + +```python +paddle.nn.FractionalMaxPool2D(output_size, kernel_size=None, random_u=None, return_mask=False, name=None) +``` + +PyTorch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示核大小。参数完全一致。 | +| output_size | output_size | 表示目标输出尺寸,PyTorch 为可选参数,Paddle 为必选参数,仅参数默认值不一致。PyTorch 的 output_size 与 output_ratio 输入二选一,如不输入 output_size,则必须输入 output_ratio,此时需要转写。转写方式与下文 output_ratio 一致。 | +| output_ratio | - | 表示目标输出比例。Paddle 无此参数,需要转写。 | +| return_indices | return_mask | 表示是否返回最大值索引。仅参数名不一致。 | +| _random_samples | random_u | 表示随机数。PyTorch 以列表形式的 Tensor 方式传入,Paddle 以 float 的方式传入,如果 PyTorch 的多个随机数相同,需要转写,如果 PyTorch 的多个随机数不同,暂无转写方式。 | + +### 转写示例 + +#### output_ratio:目标输出比例 + +```python +# 假设 intput 的 with=7, height=7, +# output_ratio = 0.75, 则目标 output 的 width = int(7*0.75) = 5, height = int(7*0.75) = 5 +# Pytorch 写法 +torch.nn.FractionalMaxPool2d(2, output_ratio=[0.75, 0.75], return_indices=True) + +# Paddle 写法 +paddle.nn.FractionalMaxPool2D(output_size=[5, 5], kernel_size=2, return_mask=True) +``` + +#### _random_samples:随机数 + +```python +# Pytorch 写法 +torch.nn.FractionalMaxPool2d(2, output_size=[3, 3], return_indices=True, _random_samples=torch.tensor([[[0.3, 0.3]]])) + +# Paddle 写法 +paddle.nn.FractionalMaxPool2D(output_size=[3, 3], kernel_size=2, return_mask=True, random_u=0.3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool3d.md new file mode 100644 index 00000000000..c54931dbde4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.FractionalMaxPool3d.md @@ -0,0 +1,49 @@ +## [ torch 参数更多 ]torch.nn.FractionalMaxPool3d + +### [torch.nn.FractionalMaxPool3d](https://pytorch.org/docs/stable/generated/torch.nn.FractionalMaxPool3d.html#fractionalmaxpool3d) + +```python +torch.nn.FractionalMaxPool3d(kernel_size, output_size=None, output_ratio=None, return_indices=False, _random_samples=None) +``` + +### [paddle.nn.FractionalMaxPool3D](https://www.paddlepaddle.org.cn/documentation/docs/en/develop/api/paddle/nn/FractionalMaxPool3D_cn.html) + +```python +paddle.nn.FractionalMaxPool3D(output_size, kernel_size=None, random_u=None, return_mask=False, name=None) +``` + +PyTorch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示核大小。参数完全一致。 | +| output_size | output_size | 表示目标输出尺寸,PyTorch 为可选参数,Paddle 为必选参数,仅参数默认值不一致。PyTorch 的 output_size 与 output_ratio 输入二选一,如不输入 output_size,则必须输入 output_ratio,此时需要转写。转写方式与下文 output_ratio 一致。 | +| output_ratio | - | 表示目标输出比例。Paddle 无此参数,需要转写。 | +| return_indices | return_mask | 表示是否返回最大值索引。仅参数名不一致。 | +| _random_samples | random_u | 表示随机数。PyTorch 以列表形式的 Tensor 方式传入,Paddle 以 float 的方式传入,如果 PyTorch 的多个随机数相同,需要转写,如果 PyTorch 的多个随机数不同,暂无转写方式。 | + +### 转写示例 + +#### output_ratio:目标输出比例 + +```python +# 假设 intput 的 depth=7, with=7, height=7, +# output_ratio = 0.75, 则目标 output 的 depth = int(7*0.75) = 5, width = int(7*0.75) = 5, height = int(7*0.75) = 5 +# Pytorch 写法 +torch.nn.FractionalMaxPool3d(2, output_ratio=[0.75, 0.75, 0.75], return_indices=True) + +# Paddle 写法 +paddle.nn.FractionalMaxPool2D(output_size=[5, 5, 5], kernel_size=2, return_mask=True) +``` + +#### _random_samples:随机数 + +```python +# Pytorch 写法 +torch.nn.FractionalMaxPool3d(2, output_size=[3, 3, 3], return_indices=True, _random_samples=torch.tensor([[[0.3, 0.3, 0.3]]])) + +# Paddle 写法 +paddle.nn.FractionalMaxPool3D(output_size=[3, 3, 3], kernel_size=2, return_mask=True, random_u=0.3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GELU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GELU.md new file mode 100644 index 00000000000..95f0f5eb9c7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GELU.md @@ -0,0 +1,43 @@ +## [参数不一致]torch.nn.GELU + +### [torch.nn.GELU](https://pytorch.org/docs/stable/generated/torch.nn.GELU.html#torch.nn.GELU) + +```python +torch.nn.GELU(approximate='none') +``` + +### [paddle.nn.GELU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/GELU_cn.html) + +```python +paddle.nn.GELU(approximate=False, name=None) +``` + +其中功能一致, 输入参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ------------------------------------------------------------------------------------ | +| approximate | approximate | 是否使用近似计算,PyTorch 取值 none 和 tanh,Paddle 取值为 bool 类型,需要转写。 | + +### 转写示例 + +#### approximate 参数:是否使用近似计算 + +```python +# 取值为 tanh,PyTorch 写法: +m = torch.nn.GELU(approximate='tanh') +y = m(x) + +# Paddle 写法: +m = paddle.nn.GELU(approximate=True) +y = m(x) + +# 取值为 none,PyTorch 写法: +m = torch.nn.GELU(approximate='none') +y = m(x) + +# Paddle 写法: +m = paddle.nn.GELU(approximate=False) +y = m(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md new file mode 100644 index 00000000000..0b709d36414 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRU.md @@ -0,0 +1,83 @@ +## [ 参数不一致 ]torch.nn.GRU +### [torch.nn.GRU](https://pytorch.org/docs/stable/generated/torch.nn.GRU.html?highlight=torch%20nn%20gru#torch.nn.GRU) +```python +torch.nn.GRU(input_size, + hidden_size, + num_layers=1, + bias=True, + batch_first=False, + dropout=0, + bidirectional=False) +``` + +### [paddle.nn.GRU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/GRU_cn.html#gru) +```python +paddle.nn.GRU(input_size, + hidden_size, + num_layers=1, + direction='forward', + dropout=0., + time_major=False, + weight_ih_attr=None, + weight_hh_attr=None, + bias_ih_attr=None, + bias_hh_attr=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| num_layers | num_layers | 表示循环网络的层数。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | +| dropout | dropout | 表示 dropout 概率。 | +| bidirectional | direction | PyTorch 表示是否进行双向 GRU,Paddle 使用字符串表示是双向 GRU(`bidirectional`)还是单向 GRU(`forward`)。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | + + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.GRU(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.GRU(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` + +#### batch_first:batch size 是否为第一维 +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, batch_first=True) + +# Paddle 写法 +paddle.nn.GRU(16, 32, time_major=False) +``` + +#### bidirectional:是否进行双向 +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bidirectional=True) + +# Paddle 写法 +paddle.nn.GRU(16, 32, direction='bidirectional') +``` +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bidirectional=False) + +# Paddle 写法 +paddle.nn.GRU(16, 32, direction='forward') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md new file mode 100644 index 00000000000..fce44973abe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GRUCell.md @@ -0,0 +1,41 @@ +## [ 参数不一致 ]torch.nn.GRUCell +### [torch.nn.GRUCell](https://pytorch.org/docs/stable/generated/torch.nn.GRUCell.html#torch.nn.GRUCell) +```python +torch.nn.GRUCell(input_size, hidden_size, bias=True, device=None, dtype=None) +``` + +### [paddle.nn.GRUCell](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/GRUCell_cn.html#grucell) +```python +paddle.nn.GRUCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) +``` + +两者功能一致但参数不一,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的所需数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | + + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.GRU(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.GRU(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.GRU(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GaussianNLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GaussianNLLLoss.md new file mode 100644 index 00000000000..eedfd169408 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GaussianNLLLoss.md @@ -0,0 +1,23 @@ +## [仅参数名不一致]torch.nn.GaussianNLLLoss + +### [torch.nn.GaussianNLLLoss](https://pytorch.org/docs/stable/generated/torch.nn.GaussianNLLLoss) + +```python +torch.nn.GaussianNLLLoss(*, full=False, eps=1e-06, reduction='mean') +``` + +### [paddle.nn.GaussianNLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/GaussianNLLLoss_cn.html) + +```python +paddle.nn.GaussianNLLLoss(full=False, epsilon=1e-6, reduction='mean', name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ---------------------------------------------------------------------------------- | +| full | full | 是否在损失计算中包括常数项。默认情况下为 False,表示忽略最后的常数项。 | +| eps | epsilon | 一个很小的数字,用于限制 variance 的值,使其不会导致除 0 的出现。默认值为 1e-6,仅参数名不一致。 | +| reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GroupNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GroupNorm.md new file mode 100644 index 00000000000..075ceaf6da8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.GroupNorm.md @@ -0,0 +1,53 @@ +## [ torch 参数更多 ]torch.nn.GroupNorm +### [torch.nn.GroupNorm](https://pytorch.org/docs/stable/generated/torch.nn.GroupNorm.html?highlight=groupnorm#torch.nn.GroupNorm) + +```python +torch.nn.GroupNorm(num_groups, + num_channels, + eps=1e-05, + affine=True, + device=True, + dtype=None) +``` + +### [paddle.nn.GroupNorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/GroupNorm_cn.html#groupnorm) + +```python +paddle.nn.GroupNorm(num_groups, + num_channels, + epsilon=1e-05, + weight_attr=None, + bias_attr=None, + data_format='NCHW', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| eps | epsilon | 为了数值稳定加在分母上的值。 | +| affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 | +| device | - | 设备类型,Paddle 无此参数。 | +| dtype | - | 参数类型,Paddle 无此参数。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | +| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### affine:是否进行仿射变换 +```python +# 当 PyTorch 的 affine 为`False`,表示 weight 和 bias 不进行更新,torch 写法 +torch.nn.GroupNorm(num_groups=5, num_channels=50, eps=1e-05, affine=False) + +# paddle 写法 +paddle.nn.GroupNorm(num_groups=5, num_channels=50, epsilon=1e-05, weight_attr=False, bias_attr=False) + +# 当 PyTorch 的 affine 为`True`,torch 写法 +torch.nn.GroupNorm(num_groups=5, num_channels=50, eps=1e-05, affine=True) + +# paddle 写法 +paddle.nn.GroupNorm(num_groups=5, num_channels=50, epsilon=1e-05) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardshrink.md new file mode 100644 index 00000000000..d34da516022 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardshrink.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.Hardshrink +### [torch.nn.Hardshrink](https://pytorch.org/docs/stable/generated/torch.nn.Hardshrink.html?highlight=hardshrink#torch.nn.Hardshrink) + +```python +torch.nn.Hardshrink(lambd=0.5) +``` + +### [paddle.nn.Hardshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Hardshrink_cn.html#hardshrink) + +```python +paddle.nn.Hardshrink(threshold=0.5, + name=None) +``` +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| lambd | threshold | Hardshrink 激活计算公式中的阈值,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardsigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardsigmoid.md new file mode 100644 index 00000000000..f1bf94a23ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardsigmoid.md @@ -0,0 +1,19 @@ +## [torch 参数更多 ]torch.nn.Hardsigmoid +### [torch.nn.Hardsigmoid](https://pytorch.org/docs/stable/generated/torch.nn.Hardsigmoid.html?highlight=hardsigmoid#torch.nn.Hardsigmoid) + +```python +torch.nn.Hardsigmoid(inplace=False) +``` + +### [paddle.nn.Hardsigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Hardsigmoid_cn.html#hardsigmoid) + +```python +paddle.nn.Hardsigmoid(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardswish.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardswish.md new file mode 100644 index 00000000000..d065c0c867c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardswish.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.nn.Hardswish + +### [torch.nn.Hardswish](https://pytorch.org/docs/stable/generated/torch.nn.Hardswish.html#torch.nn.Hardswish) + +```python +torch.nn.Hardswish(inplace=False) +``` + +### [paddle.nn.Hardswish](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Hardswish_cn.html) + +```python +paddle.nn.Hardswish(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------------------------------------------------------- | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardtanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardtanh.md new file mode 100644 index 00000000000..b118b73481a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Hardtanh.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.Hardtanh + +### [torch.nn.Hardtanh](https://pytorch.org/docs/stable/generated/torch.nn.Hardtanh.html#torch.nn.Hardtanh) + +```python +torch.nn.Hardtanh(min_val=- 1.0, max_val=1.0, inplace=False) +``` + +### [paddle.nn.Hardtanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Hardtanh_cn.html) + +```python +paddle.nn.Hardtanh(min=- 1.0, max=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------------------------------------------------------- | +| min_val | min | Hardtanh 激活计算公式中的 min 值,仅参数名不一致。 | +| max_val | max | Hardtanh 激活计算公式中的 max 值,仅参数名不一致。 | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md new file mode 100644 index 00000000000..45a0bc68acf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HingeEmbeddingLoss.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.nn.HingeEmbeddingLoss + +### [torch.nn.HingeEmbeddingLoss](https://pytorch.org/docs/stable/generated/torch.nn.HingeEmbeddingLoss.html#hingeembeddingloss) + +```python +torch.nn.HingeEmbeddingLoss(margin=1.0, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.HingeEmbeddingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/HingeEmbeddingLoss_cn.html#hingeembeddingloss) + +```python +paddle.nn.HingeEmbeddingLoss(margin=1.0, + reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | ------------------------------------------------------------ | +| margin | margin | 当 label 为-1 时,该值决定了小于 margin 的 input 才需要纳入 hinge embedding loss 的计算。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HuberLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HuberLoss.md new file mode 100644 index 00000000000..5d287e7f1f8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.HuberLoss.md @@ -0,0 +1,22 @@ +## [参数完全一致]torch.nn.HuberLoss + +### [torch.nn.HuberLoss](https://pytorch.org/docs/stable/generated/torch.nn.HuberLoss.html#torch.nn.HuberLoss) + +```python +torch.nn.HuberLoss(reduction='mean', delta=1.0) +``` + +### [paddle.nn.SmoothL1Loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SmoothL1Loss_cn.html) + +```python +paddle.nn.SmoothL1Loss(reduction='mean', delta=1.0, name=None) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ------------------------------ | +| reduction | reduction | 指定应用于输出结果的计算方式。 | +| delta | delta | 损失的阈值参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Identity.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Identity.md new file mode 100644 index 00000000000..0a256b1ae27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Identity.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.nn.Identity +### [torch.nn.Identity](https://pytorch.org/docs/stable/generated/torch.nn.Identity.html#identity) + +```python +torch.nn.Identity(*args, **kwargs) +``` + +### [paddle.nn.Identity](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Identity_cn.html#cn-api-paddle-nn-layer-common-identity) + +```python +paddle.nn.Identity(*args, **kwargs) +``` + +两者功能一致,参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------------------------------------ | +| args | args | 任意的参数 | +|kwargs | kwargs | 任意的关键字参数 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md new file mode 100644 index 00000000000..9c7b147e2fe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm1d.md @@ -0,0 +1,49 @@ +## [ 参数不一致 ]torch.nn.InstanceNorm1d + +### [torch.nn.InstanceNorm1d](https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm1d.html#torch.nn.InstanceNorm1d) + +```python +torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False, device=None, dtype=None) +``` + +### [paddle.nn.InstanceNorm1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/InstanceNorm1D_cn.html#instancenorm1d) +```python +paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format="NCL", name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_features | num_features | 指明输入的通道数量 | +| eps | epsilon | 为了数值稳定加在分母上的值 | +| momentum | momentum | 此值用于计算 moving_mean 和 moving_var, 值的大小 Paddle = 1 - PyTorch,需要转写。 | +| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数,需要转写。可通过 weight_attr 和 bias_attr 控制。 | +| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数,暂无转写方式。 | +| dtype | - | 输出数据类型, Paddle 无此参数, 需要转写。Paddle 应使用 astype 对计算结果做类型转换。 | +| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 | +| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 | +| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 | + + +### 转写示例 +#### affine:是否使用可学习的仿射参数 +```python +# PyTorch 写法 +IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False) + +# Paddle 写法 +IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False) +``` + +#### dtype:输出数据类型 +```python +# PyTorch 写法 +IN = torch.nn.InstanceNorm1d(num_features, eps=1e-05, momentum=0.1, affine=False, dtype=torch.float32) +y = IN(x) + +# Paddle 写法 +IN = paddle.nn.InstanceNorm1D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False) +y = IN(x).astype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md new file mode 100644 index 00000000000..c2018600613 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm2d.md @@ -0,0 +1,38 @@ +## [ 参数不一致 ]torch.nn.InstanceNorm2d + +### [torch.nn.InstanceNorm2d](https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm2d.html#torch.nn.InstanceNorm2d) + +```python +torch.nn.InstanceNorm2d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False, device=None, dtype=None) +``` + +### [paddle.nn.InstanceNorm2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/InstanceNorm2D_cn.html#instancenorm2d) +```python +paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format="NCL", name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_features | num_features | 指明输入的通道数量。 | +| eps | epsilon | 为了数值稳定加在分母上的值。 | +| momentum | momentum | 此值用于计算 moving_mean 和 moving_var,值的大小 Paddle = 1 - PyTorch,需要转写。 | +| affine | - | 是否使用可学习的仿射参数,Paddle 无此参数。可通过 weight_attr 和 bias_attr 控制。 | +| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 | +| dtype | - | 输出数据类型, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 可学习参数——权重的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 | +| - | bias_attr | 可学习参数——偏差的属性,默认为 None,表示使用默认可学习参数。 PyTorch 无此参数。 | +| - | data_format | 指定输入数据格式。 PyTorch 无此参数。 | + + +### 转写示例 +#### affine:是否使用可学习的仿射参数 +```python +# PyTorch 写法 +IN = torch.nn.InstanceNorm2d(num_features, eps=1e-05, momentum=0.1, affine=False) + +# Paddle 写法 +IN = paddle.nn.InstanceNorm2D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=False, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md new file mode 100644 index 00000000000..7bbe3561b2f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.InstanceNorm3d.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.nn.InstanceNorm3d + +### [torch.nn.InstanceNorm3d](https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm3d.html#torch.nn.InstanceNorm3d) + +```python +torch.nn.InstanceNorm3d(num_features, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False, device=None, dtype=None) +``` + +### [paddle.nn.InstanceNorm3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/InstanceNorm3D_cn.html) + +```python +paddle.nn.InstanceNorm3D(num_features, epsilon=1e-05, momentum=0.9, weight_attr=None, bias_attr=None, data_format="NCDHW", name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------- | ------------ | --------------------------------------------------------------- | +| num_features | num_features | 输入 Tensor 的通道数量。 | +| eps | epsilon | 为了数值稳定加在分母上的值,仅参数名不一致。 | +| momentum | momentum | 此值用于计算 moving_mean 和 moving_var。 | +| affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 | +| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 参数类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### affine:是否进行仿射变换 + +```python +# 当 PyTorch 的 affine 为`False`,表示 weight 和 bias 不进行更新,torch 写法 +torch.nn.InstanceNorm3d(num_features, affine=False) + +# paddle 写法 +paddle.nn.InstanceNorm3d(num_features, weight_attr=False, bias_attr=False) + +# 当 PyTorch 的 affine 为`True`,torch 写法 +torch.nn.InstanceNorm3d(num_features, affine=True) + +# paddle 写法 +paddle.nn.InstanceNorm3d(num_features) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md new file mode 100644 index 00000000000..ddd231e6d6c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.KLDivLoss.md @@ -0,0 +1,41 @@ +## [torch 参数更多 ]torch.nn.KLDivLoss +### [torch.nn.KLDivLoss](https://pytorch.org/docs/stable/generated/torch.nn.KLDivLoss.html?highlight=kldivloss#torch.nn.KLDivLoss) + +```python +torch.nn.KLDivLoss(size_average=None, + reduce=None, + reduction='mean', + log_target=False) +``` + +### [paddle.nn.KLDivLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/KLDivLoss_cn.html#kldivloss) + +```python +paddle.nn.KLDivLoss(reduction='mean') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示对输出结果的计算方式。 | +| log_target | - | 指定目标是否为日志空间,Paddle 无此参数,暂无转写方式。 | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.L1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.L1Loss.md new file mode 100644 index 00000000000..5bc5f9ce4df --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.L1Loss.md @@ -0,0 +1,41 @@ +## [ torch 参数更多 ]torch.nn.L1Loss +### [torch.nn.L1Loss](https://pytorch.org/docs/stable/generated/torch.nn.L1Loss.html?highlight=l1loss#torch.nn.L1Loss) + +```python +torch.nn.L1Loss(size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.L1Loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/L1Loss_cn.html#l1loss) + +```python +paddle.nn.L1Loss(reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size_average | - | 已弃用。 | +| reduce | - | 已弃用。 | +| reduction | reduction | 表示对输出结果的计算方式。 | + +### 转写示例 +#### size_average +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md new file mode 100644 index 00000000000..156e322e8b3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTM.md @@ -0,0 +1,86 @@ +## [ 参数不一致 ]torch.nn.LSTM +### [torch.nn.LSTM](https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html?highlight=lstm#torch.nn.LSTM) + +```python +torch.nn.LSTM(input_size, + hidden_size, + num_layers=1, + bias=True, + batch_first=False, + dropout=0, + bidirectional=False, + proj_size=0) +``` + +### [paddle.nn.LSTM](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LSTM_cn.html#lstm) + +```python +paddle.nn.LSTM(input_size, + hidden_size, + num_layers=1, + direction='forward', + dropout=0., + time_major=False, + weight_ih_attr=None, + weight_hh_attr=None, + bias_ih_attr=None, + bias_hh_attr=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| num_layers | num_layers | 表示循环网络的层数。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | +| dropout | dropout | 表示 dropout 概率。 | +| bidirectional | direction | PyTorch 表示是否进行双向,Paddle 使用字符串表示是双向 LSTM(`bidirectional`)还是单向 LSTM(`forward`)| +| proj_size | - | 表示 LSTM 后将映射到对应的大小,Paddle 无此参数,暂无转写方式。 | +| - |weight_ih_attr| weight_ih 的参数,PyTorch 无此参数,Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.LSTM(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.LSTM(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` + +#### batch_first:batch size 是否为第一维 +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, batch_first=True) + +# Paddle 写法 +paddle.nn.LSTM(16, 32, time_major=False) +``` + +#### bidirectional:是否进行双向 +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bidirectional=True) + +# Paddle 写法 +paddle.nn.LSTM(16, 32, direction='bidirectional') +``` +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bidirectional=False) + +# Paddle 写法 +paddle.nn.LSTM(16, 32, direction='forward') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md new file mode 100644 index 00000000000..787c5a06f83 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LSTMCell.md @@ -0,0 +1,41 @@ +## [ 参数不一致 ]torch.nn.LSTMCell +### [torch.nn.LSTMCell](https://pytorch.org/docs/stable/generated/torch.nn.LSTMCell.html#torch.nn.LSTMCell) +```python +torch.nn.LSTMCell(input_size, hidden_size, bias=True, device=None, dtype=None) +``` + +### [paddle.nn.LSTMCell](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LSTMCell_cn.html#lstmcell) +```python +paddle.nn.LSTMCell(input_size, hidden_size, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) +``` + +两者功能一致但参数不一,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| device | - | 指定 Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的所需数据类型,一般对网络训练结果影响不大,可直接删除。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | + + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.LSTM(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.LSTM(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.LSTM(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LayerNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LayerNorm.md new file mode 100644 index 00000000000..4a1ca96b243 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LayerNorm.md @@ -0,0 +1,48 @@ +## [torch 参数更多 ]torch.nn.LayerNorm +### [torch.nn.LayerNorm](https://pytorch.org/docs/stable/generated/torch.nn.LayerNorm.html?highlight=layernorm#torch.nn.LayerNorm) + +```python +torch.nn.LayerNorm(normalized_shape, + eps=1e-05, + elementwise_affine=True, + device=None, + dtype=None) +``` + +### [paddle.nn.LayerNorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LayerNorm_cn.html#layernorm) + +```python +paddle.nn.LayerNorm(normalized_shape, + epsilon=1e-05, + weight_attr=None, + bias_attr=None, + name=None) +``` + +两者功能一致但参数不一致,torch 参数更多,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| elementwise_affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 | +| device | - | 设备类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 参数类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| eps | epsilon | 为了数值稳定加在分母上的值。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | + + +### 转写示例 +#### elementwise_affine:是否进行仿射变换 +```python +# 当 PyTorch 的 elementwise_affine 为`False`,表示 weight 和 bias 不进行更新,torch 写法 +torch.nn.LayerNorm(normalized_shape=(256, 256), eps=1e-05, elementwise_affine=False) + +# paddle 写法 +paddle.nn.GroupNorm(normalized_shape=(256, 256), epsilon=1e-05, weight_attr=False, bias_attr=False) + +# 当 PyTorch 的 elementwise_affine 为`True`,torch 写法 +torch.nn.LayerNorm(normalized_shape=(256, 256), eps=1e-05, elementwise_affine=True) + +# paddle 写法 +paddle.nn.LayerNorm(normalized_shape=(256, 256), epsilon=1e-05) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LeakyReLU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LeakyReLU.md new file mode 100644 index 00000000000..fba19fde2b4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LeakyReLU.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ]torch.nn.LeakyReLU +### [torch.nn.LeakyReLU](https://pytorch.org/docs/stable/generated/torch.nn.LeakyReLU.html?highlight=leakyrelu#torch.nn.LeakyReLU) + +```python +torch.nn.LeakyReLU(negative_slope=0.01, + inplace=False) +``` + +### [paddle.nn.LeakyReLU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LeakyReLU_cn.html#leakyrelu) + +```python +paddle.nn.LeakyReLU(negative_slope=0.01, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| negative_slope | negative_slope | 表示 x<0 时的斜率。 | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Linear.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Linear.md new file mode 100644 index 00000000000..20c7d865ae9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Linear.md @@ -0,0 +1,46 @@ +## [ 参数不一致 ]torch.nn.Linear +### [torch.nn.Linear](https://pytorch.org/docs/stable/generated/torch.nn.Linear.html?highlight=linear#torch.nn.Linear) + +```python +torch.nn.Linear(in_features, + out_features, + bias=True) +``` + +### [paddle.nn.Linear](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Linear_cn.html#linear) + +```python +paddle.nn.Linear(in_features, + out_features, + weight_attr=None, + bias_attr=None, + name=None) +``` + +其中 PyTorch 的 `bias` 与 Paddle 的 `bias_attr` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| in_features | in_features | 表示线性变换层输入单元的数目。 | +| out_features | out_features | 表示线性变换层输出单元的数目。 | +| bias | - | 是否在输出中添加可学习的 bias。 | +| - | weight_attr | 指定权重参数的属性,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数的属性, 当`bias_attr`设置为 bool 类型时与 PyTorch 的作用一致。 | + +### 转写示例 +#### bias: 是否在输出中添加可学习的 bias +```python +# PyTorch 写法 +torch.nn.Linear(2, 4, bias=True) + +# Paddle 写法 +paddle.nn.Linear(2, 4) +``` +```python +# PyTorch 写法 +torch.nn.Linear(2, 4, bias=False) + +# Paddle 写法 +paddle.nn.Linear(2, 4, bias_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LocalResponseNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LocalResponseNorm.md new file mode 100644 index 00000000000..0feff098e4f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LocalResponseNorm.md @@ -0,0 +1,31 @@ +## [ 仅 paddle 参数更多]torch.nn.LocalResponseNorm +### [torch.nn.LocalResponseNorm](https://pytorch.org/docs/stable/generated/torch.nn.LocalResponseNorm.html?highlight=localre#torch.nn.LocalResponseNorm) + +```python +torch.nn.LocalResponseNorm(size, + alpha=0.0001, + beta=0.75, + k=1.0) +``` + +### [paddle.nn.LocalResponseNorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LocalResponseNorm_cn.html) + +```python +paddle.nn.LocalResponseNorm(size, + alpha=0.0001, + beta=0.75, + k=1.0, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | size | 表示累加的通道数。 | +| alpha | alpha | 表示缩放参数。 | +| beta | beta | 表示指数。 | +| k | k | 表示位移。 | +| - | data_format | 指定输入的 format , PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSigmoid.md new file mode 100644 index 00000000000..352776fe8fc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSigmoid.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.nn.LogSigmoid + +### [torch.nn.LogSigmoid](https://pytorch.org/docs/stable/generated/torch.nn.LogSigmoid.html) + +```python +torch.nn.LogSigmoid(*args, **kwargs) +``` + +### [paddle.nn.LogSigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/LogSigmoid_cn.html#logsigmoid) + +```python +paddle.nn.LogSigmoid(name=None) +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSoftmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSoftmax.md new file mode 100644 index 00000000000..6748fd4e989 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.LogSoftmax.md @@ -0,0 +1,18 @@ +## [ 仅参数名不一致 ]torch.nn.LogSoftmax +### [torch.nn.LogSoftmax](https://pytorch.org/docs/stable/generated/torch.nn.LogSoftmax.html?highlight=nn+logsoftmax#torch.nn.LogSoftmax) + +```python +torch.nn.LogSoftmax(dim=None) +``` + +### [paddle.nn.LogSoftmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LogSoftmax_cn.html#logsoftmax) + +```python +paddle.nn.LogSoftmax(axis=- 1, name=None) +``` +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md new file mode 100644 index 00000000000..8f8904c4ede --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MSELoss.md @@ -0,0 +1,110 @@ +## [torch 参数更多 ]torch.nn.MSELoss +### [torch.nn.MSELoss](https://pytorch.org/docs/stable/generated/torch.nn.MSELoss.html?highlight=mseloss#torch.nn.MSELoss) + +```python +torch.nn.MSELoss(size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.MSELoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MSELoss_cn.html#mseloss) + +```python +paddle.nn.MSELoss(reduction='mean') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size_average | - | 已弃用。 | +| reduce | - | 已弃用。 | +| reduction | reduction | 表示对输出结果的计算方式。 | + +### 转写示例 +#### size_average + +```python +# Paddle 写法 +torch.nn.MSELoss(size_average=True) + +# Paddle 写法 +paddle.nn.MSELoss(reduction='mean') +``` + +#### size_average + +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.MSELoss(size_average=True) + +# Paddle 写法 +paddle.nn.MSELoss(reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.MSELoss(size_average=False) + +# Paddle 写法 +paddle.nn.MSELoss(reduction='sum') +``` + +#### reduce + +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.MSELoss(reduce=True) + +# Paddle 写法 +paddle.nn.MSELoss(reduction='mean') +``` + +reduce 为 False + +```python +# PyTorch 写法 +torch.nn.MSELoss(reduce=False) + +# Paddle 写法 +paddle.nn.MSELoss(reduction='none') +``` + +#### reduction + +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.MSELoss(reduction='none') + +# Paddle 写法 +paddle.nn.MSELoss(reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.MSELoss(reduction='mean') + +# Paddle 写法 +paddle.nn.MSELoss(reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.MSELoss(reduction='sum') + +# Paddle 写法 +paddle.nn.MSELoss(reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md new file mode 100644 index 00000000000..d555ec87f92 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MarginRankingLoss.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.nn.MarginRankingLoss + +### [torch.nn.MarginRankingLoss](https://pytorch.org/docs/stable/generated/torch.nn.MarginRankingLoss.html#marginrankingloss) + +```python +torch.nn.MarginRankingLoss(margin=0.0, + size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.MarginRankingLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MarginRankingLoss_cn.html#marginrankingloss) + +```python +paddle.nn.MarginRankingLoss(margin=0.0, + reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | -------------------------------------------- | +| margin | margin | 用于加和的 margin 值。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool1d.md new file mode 100644 index 00000000000..a544b55feae --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool1d.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.nn.MaxPool1d +### [torch.nn.MaxPool1d](https://pytorch.org/docs/stable/generated/torch.nn.MaxPool1d.html?highlight=maxpool1d#torch.nn.MaxPool1d) + +```python +torch.nn.MaxPool1d(kernel_size, + stride=None, + padding=0, + dilation=1, + return_indices=False, + ceil_mode=False) +``` + +### [paddle.nn.MaxPool1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxPool1D_cn.html#maxpool1d) + +```python +paddle.nn.MaxPool1D(kernel_size, + stride=None, + padding=0, + return_mask=False, + ceil_mode=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核大小。 | +| stride | stride | 表示池化核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | - | 设置空洞池化的大小,Paddle 无此参数,暂无转写方式。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool2d.md new file mode 100644 index 00000000000..377616b2a51 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool2d.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.nn.MaxPool2d +### [torch.nn.MaxPool2d](https://pytorch.org/docs/stable/generated/torch.nn.MaxPool2d.html?highlight=maxpool2d#torch.nn.MaxPool2d) + +```python +torch.nn.MaxPool2d(kernel_size, + stride=None, + padding=0, + dilation=1, + return_indices=False, + ceil_mode=False) +``` + +### [paddle.nn.MaxPool2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxPool2D_cn.html#maxpool2d) + +```python +paddle.nn.MaxPool2D(kernel_size, + stride=None, + padding=0, + return_mask=False, + ceil_mode=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核大小。 | +| stride | stride | 表示池化核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | - | 设置空洞池化的大小,Paddle 无此参数,暂无转写方式。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool3d.md new file mode 100644 index 00000000000..1c5d552a9d1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxPool3d.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.nn.MaxPool3d +### [torch.nn.MaxPool3d](https://pytorch.org/docs/stable/generated/torch.nn.MaxPool3d.html?highlight=maxpool3d#torch.nn.MaxPool3d) + +```python +torch.nn.MaxPool3d(kernel_size, + stride=None, + padding=0, + dilation=1, + return_indices=False, + ceil_mode=False) +``` + +### [paddle.nn.MaxPool3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxPool3D_cn.html#maxpool3d) + +```python +paddle.nn.MaxPool3D(kernel_size, + stride=None, + padding=0, + ceil_mode=False, + return_mask=False, + data_format='NCDHW', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示池化核大小。 | +| stride | stride | 表示池化核步长。 | +| padding | padding | 表示填充大小。 | +| dilation | - | 设置空洞池化的大小,Paddle 无此参数,暂无转写方式。 | +| return_indices | return_mask | 是否返回最大值的索引,仅参数名不一致。 | +| ceil_mode | ceil_mode | 表示是否用 ceil 函数计算输出的 height 和 width 。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool1d.md new file mode 100644 index 00000000000..202430242ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool1d.md @@ -0,0 +1,30 @@ +## [仅 paddle 参数更多 ]torch.nn.MaxUnpool1d +### [torch.nn.MaxUnpool1d](https://pytorch.org/docs/stable/generated/torch.nn.MaxUnpool1d.html?highlight=maxunpool1d#torch.nn.MaxUnpool1d) + +```python +torch.nn.MaxUnpool1d(kernel_size, + stride=None, + padding=0) +``` + +### [paddle.nn.MaxUnPool1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxUnPool1D_cn.html) + +```python +paddle.nn.MaxUnPool1D(kernel_size, + stride=None, + padding=0, + data_format='NCL', + output_size=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示反池化核大小。 | +| stride | stride | 表示反池化核步长。 | +| padding | padding | 表示填充大小。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | output_size | 目标输出尺寸,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool2d.md new file mode 100644 index 00000000000..64aea998ad7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool2d.md @@ -0,0 +1,30 @@ +## [仅 paddle 参数更多 ]torch.nn.MaxUnpool2d +### [torch.nn.MaxUnpool2d](https://pytorch.org/docs/stable/generated/torch.nn.MaxUnpool2d.html?highlight=maxunpool2d#torch.nn.MaxUnpool2d) + +```python +torch.nn.MaxUnpool2d(kernel_size, + stride=None, + padding=0) +``` + +### [paddle.nn.MaxUnPool2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxUnPool2D_cn.html) + +```python +paddle.nn.MaxUnPool2D(kernel_size, + stride=None, + padding=0, + data_format='NCHW', + output_size=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示反池化核大小。 | +| stride | stride | 表示反池化核步长。 | +| padding | padding | 表示填充大小。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | output_size | 目标输出尺寸,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool3d.md new file mode 100644 index 00000000000..1f6f7f885bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MaxUnpool3d.md @@ -0,0 +1,30 @@ +## [仅 paddle 参数更多 ]torch.nn.MaxUnpool3d +### [torch.nn.MaxUnpool3d](https://pytorch.org/docs/stable/generated/torch.nn.MaxUnpool3d.html?highlight=maxunpool3d#torch.nn.MaxUnpool3d) + +```python +torch.nn.MaxUnpool3d(kernel_size, + stride=None, + padding=0) +``` + +### [paddle.nn.MaxUnPool3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MaxUnPool3D_cn.html) + +```python +paddle.nn.MaxUnPool3D(kernel_size, + stride=None, + padding=0, + data_format='NCDHW', + output_size=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_size | 表示反池化核大小。 | +| stride | stride | 表示反池化核步长。 | +| padding | padding | 表示填充大小。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | output_size | 目标输出尺寸,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Mish.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Mish.md new file mode 100644 index 00000000000..8b7e0e054cf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Mish.md @@ -0,0 +1,20 @@ +## [ torch 参数更多 ]torch.nn.Mish + +### [torch.nn.Mish](https://pytorch.org/docs/stable/generated/torch.nn.Mish.html?highlight=torch+nn+mish) + +```python +torch.nn.Mish(inplace=False) +``` + +### [paddle.nn.Mish](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Mish_cn.html) + +```python +paddle.nn.Mish(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,主要功能为节省显存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.add_module.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.add_module.md new file mode 100644 index 00000000000..862715c6c0d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.add_module.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.Module.add_module + +### [torch.nn.Module.add_module](https://pytorch.org/docs/stable/generated/torch.nn.Module.html?highlight=torch+nn+module+add_module#torch.nn.Module.add_module) + +```python +torch.nn.Module.add_module(name, module) +``` + +### [paddle.nn.Layer.add_sublayer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#add-sublayer-name-sublayer) + +```python +paddle.nn.Layer.add_sublayer(name, sublayer) +``` + +两者功能一致,仅参数名不一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----- | ----- | ------------------------------------------ | +| name | name | 表示子层名。 | +| module | sublayer | 表示要添加到模块中的子模块,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.apply.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.apply.md new file mode 100644 index 00000000000..41f5d621ceb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.apply.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.nn.Module.apply + +### [torch.nn.Module.apply](https://pytorch.org/docs/stable/generated/torch.nn.Module.html?highlight=torch+nn+module+apply#torch.nn.Module.apply) + +```python +torch.nn.Module.apply(fn) +``` + +### [paddle.nn.Layer.apply](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html) + +```python +paddle.nn.Layer.apply(fn) +``` + +两者功能一致,参数完全一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----- | ---------- | ------------------------ | +| fn | fn | 表示应用于每个模块的函数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.bfloat16.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.bfloat16.md new file mode 100644 index 00000000000..e3f64a03746 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.bfloat16.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.bfloat16 + +### [torch.nn.Module.bfloat16](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.bfloat16) + +```python +torch.nn.Module.bfloat16() +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(dtype=paddle.bfloat16) +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------- | +| - | dtype | 转换的数据类型,Paddle 为 paddle.bfloat16,需要转写。 | + +### 转写示例 + +#### dtype 参数:转换的数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.bfloat16() + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(dtype=paddle.bfloat16) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.buffers.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.buffers.md new file mode 100644 index 00000000000..d2be39058e6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.buffers.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.Module.buffers + +### [torch.nn.Module.buffers](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.buffers) + +```python +torch.nn.Module.buffers(recurse=True) +``` + +### [paddle.nn.Layer.buffers](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#buffers-include-sublayers-true) + +```python +paddle.nn.Layer.buffers(include_sublayers=True) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| recurse | include_sublayers | 表示是否返回子层的 buffers ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.children.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.children.md new file mode 100644 index 00000000000..7ae406dcfd3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.children.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.nn.Module.children + +### [torch.nn.Module.children](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.children) + +```python +torch.nn.Module.children() +``` + +### [paddle.nn.Layer.children](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#children) + +```python +paddle.nn.Layer.children() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cpu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cpu.md new file mode 100644 index 00000000000..c2faf88fa9f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cpu.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.cpu + +### [torch.nn.Module.cpu](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.cpu) + +```python +torch.nn.Module.cpu() +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to("cpu") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------- | +| - | device | Paddle 设置为 cpu,需要转写。 | + +### 转写示例 + +#### device 参数:设备 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.cpu() + +# Paddle 写法: +module = paddle.nn.Layer() +module.to("cpu") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cuda.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cuda.md new file mode 100644 index 00000000000..bc1377f48a9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.cuda.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.cuda + +### [torch.nn.Module.cuda](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.cuda) + +```python +torch.nn.Module.cuda(device=None) +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(device="gpu") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------- | +| device | device | PyTorch 为设备编号,Paddle 为 gpu:设备编号,需要转写。 | + +### 转写示例 + +#### device 参数:设备 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.cuda(0) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to("gpu:0") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.double.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.double.md new file mode 100644 index 00000000000..d76efadfd7e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.double.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.double + +### [torch.nn.Module.double](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.double) + +```python +torch.nn.Module.double() +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(dtype="float64") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------- | +| - | dtype | 转换的数据类型,Paddle 为 float64,需要转写。 | + +### 转写示例 + +#### dtype 参数:转换的数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.double() + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(dtype="float64") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.eval.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.eval.md new file mode 100644 index 00000000000..ee353d06b07 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.eval.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.nn.Module.eval + +### [torch.nn.Module.eval](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.eval) + +```python +torch.nn.Module.eval() +``` + +### [paddle.nn.Layer.eval](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#eval) + +```python +paddle.nn.Layer.eval() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.float.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.float.md new file mode 100644 index 00000000000..67e7ef383c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.float.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.float + +### [torch.nn.Module.float](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.float) + +```python +torch.nn.Module.float() +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(dtype="float32") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------- | +| - | dtype | 转换的数据类型,Paddle 为 float32,需要转写。 | + +### 转写示例 + +#### dtype 参数:转换的数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.float() + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(dtype="float32") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_buffer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_buffer.md new file mode 100644 index 00000000000..2e2a2103f7a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_buffer.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.nn.Module.get_buffer + +### [torch.nn.Module.get_buffer](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_buffer) + +```python +torch.nn.Module.get_buffer(target) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +module.get_buffer("target") + +# Paddle 写法 +getattr(module, "target") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_parameter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_parameter.md new file mode 100644 index 00000000000..78c8f528a2e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_parameter.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.nn.Module.get_parameter + +### [torch.nn.Module.get_parameter](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_parameter) + +```python +torch.nn.Module.get_parameter(target) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +module.get_parameter("target") + +# Paddle 写法 +getattr(module, "target") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_submodule.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_submodule.md new file mode 100644 index 00000000000..c36a6a183b0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.get_submodule.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.nn.Module.get_submodule + +### [torch.nn.Module.get_submodule](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.get_submodule) + +```python +torch.nn.Module.get_submodule(target) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +module.get_submodule("target") + +# Paddle 写法 +getattr(module, "target") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.half.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.half.md new file mode 100644 index 00000000000..be32473cf25 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.half.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.half + +### [torch.nn.Module.half](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.half) + +```python +torch.nn.Module.half() +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(dtype="float16") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------- | +| - | dtype | 转换的数据类型,Paddle 为 float16,需要转写。 | + +### 转写示例 + +#### dtype 参数:转换的数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.half() + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(dtype="float16") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.load_state_dict.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.load_state_dict.md new file mode 100644 index 00000000000..1680dd085c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.load_state_dict.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.nn.Module.load_state_dict +### [torch.nn.Module.load_state_dict](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.load_state_dict) + +```python +torch.nn.Module.load_state_dict(state_dict, strict=True) +``` + +### [paddle.nn.Layer.set_state_dict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#set-state-dict-state-dict-use-structured-name-true) + +```python +paddle.nn.Layer.set_state_dict(state_dict, use_structured_name=True) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| state_dict | state_dict | 包含所有参数和可持久性 buffers 的 dict。 | +| strict | use_structured_name | 设置所加载参数字典的 key 是否能够严格匹配,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.md new file mode 100644 index 00000000000..5ce0920d4e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ] torch.nn.Module + +### [torch.nn.Module](https://pytorch.org/docs/stable/generated/torch.nn.Module.html?highlight=torch+nn+module#torch.nn.Module) + +```python +torch.nn.Module(*args, **kwargs) +``` + +### [paddle.nn.Layer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html) + +```python +paddle.nn.Layer(name_scope=None, dtype='float32') +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----- | ---------- | ------------------------------------ | +| - | name_scope | PyTorch 无此参数,Paddle 保持默认即可。 | +| - | dtype | PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_buffers.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_buffers.md new file mode 100644 index 00000000000..fe2147cbeeb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_buffers.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.Module.named_buffers + +### [torch.nn.Module.named_buffers](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.named_buffers) + +```python +torch.nn.Module.named_buffers(prefix='', recurse=True, remove_duplicate=True) +``` + +### [paddle.nn.Layer.named_buffers](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#named-buffers-prefix-include-sublayers-true) + +```python +paddle.nn.Layer.named_buffers(prefix='', include_sublayers=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| prefix | prefix | 在所有参数名称前加的前缀。 | +| recurse | include_self | 生成该模块和所有子模块的缓冲区,仅参数名不一致。 | +| remove_duplicate | - | 是否删除结果中重复的模块实例。Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_children.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_children.md new file mode 100644 index 00000000000..cdac50af2a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_children.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.nn.Module.named_children + +### [torch.nn.Module.named_children](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.named_children) + +```python +torch.nn.Module.named_children() +``` + +### [paddle.nn.Layer.named_children](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#named-children) + +```python +paddle.nn.Layer.named_children() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_modules.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_modules.md new file mode 100644 index 00000000000..e8e7dfd26ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_modules.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.nn.Module.named_modules + +### [torch.nn.Module.named_modules](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.named_modules) + +```python +torch.nn.Module.named_modules(memo=None, prefix='', remove_duplicate=True) +``` + +### [paddle.nn.Layer.named_sublayers](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#named-sublayers-prefix-include-self-false-layers-set-none) + +```python +paddle.nn.Layer.named_sublayers(prefix='', include_self=False, layers_set=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| memo | - | 是否用备忘录对结果进行存储。Paddle 无此参数,暂无转写方式。 | +| prefix | prefix | 在所有参数名称前加的前缀。 | +| remove_duplicate | - | 是否删除结果中重复的模块实例, Paddle 无此参数,暂无转写方式。 | +| - | include_self | 是否包含该层自身,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | layers_set | 记录重复子层的集合,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_parameters.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_parameters.md new file mode 100644 index 00000000000..17672bd3645 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.named_parameters.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.Module.named_parameters + +### [torch.nn.Module.named_parameters](https://pytorch.org/docs/stable/generated/torch.nn.Module.html?highlight=torch+nn+module+named_parameters#torch.nn.Module.named_parameters) + +```python +torch.nn.Module.named_parameters(prefix='', recurse=True, remove_duplicate=True) +``` + +### [paddle.nn.Layer.named_parameters](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#named-parameters-prefix-include-sublayers-true) + +```python +paddle.nn.Layer.named_parameters(prefix='', include_sublayers=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| prefix | prefix | 在所有参数名称前加的前缀。 | +| recurse | include_sublayers | 生成该模块和所有子模块的参数, 仅参数名不一致。 | +| remove_duplicate | - | 是否删除结果中的重复参数, Paddle 无此参数, 暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.parameters.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.parameters.md new file mode 100644 index 00000000000..9bffda490b6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.parameters.md @@ -0,0 +1,18 @@ +## [ 仅参数名不一致 ]torch.nn.Module.parameters +### [torch.nn.Module.parameters](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.parameters) + +```python +torch.nn.Module.parameters(recurse=True) +``` + +### [paddle.nn.Layer.parameters](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#parameters-include-sublayers-true) + +```python +paddle.nn.Layer.parameters(include_sublayers=True) +``` +两者功能一致,仅参数名不一致,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| recurse | include_sublayers | 是否返回子层的参数,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_buffer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_buffer.md new file mode 100644 index 00000000000..fd2f9ef6fe4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_buffer.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.Module.register_buffer +### [torch.nn.Module.register_buffer](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_buffer) + +```python +torch.nn.Module.register_buffer(name, tensor, persistent=True) +``` + +### [paddle.nn.Layer.register_buffer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#register-buffer-name-tensor-persistable-true) + +```python +paddle.nn.Layer.register_buffer(name, tensor, persistable=True) +``` +两者功能一致,仅参数名不一致,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| name | name | 注册 buffer 的名字。可以通过此名字来访问已注册的 buffer。 | +| tensor | tensor | 将被注册为 buffer 的变量。 | +| persistent | persistable | 注册的 buffer 是否需要可持久性地保存到 state_dict 中。仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_hook.md new file mode 100644 index 00000000000..ee46d514a3b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_hook.md @@ -0,0 +1,20 @@ +## [ torch 参数更多 ]torch.nn.Module.register_forward_hook +### [torch.nn.Module.register_forward_hook](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_forward_hook) + +```python +torch.nn.Module.register_forward_hook(hook, *, prepend=False, with_kwargs=False) +``` + +### [paddle.nn.Layer.register_forward_post_hook](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#register-forward-post-hook-hook) + +```python +paddle.nn.Layer.register_forward_post_hook(hook) +``` +PyTorch 参数更多,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| hook | hook | 被注册的 hook。 | +| prepend | - | 是否在其他 hook 执行前执行,Paddle 无此参数, 暂无转写方式。 | +| with_kwargs | - | 是否传入 forward 函数的参数,paddle 无此参数, 暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_pre_hook.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_pre_hook.md new file mode 100644 index 00000000000..a46b0efa57f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_forward_pre_hook.md @@ -0,0 +1,20 @@ +## [ torch 参数更多 ]torch.nn.Module.register_forward_pre_hook +### [torch.nn.Module.register_forward_pre_hook](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_forward_pre_hook) + +```python +torch.nn.Module.register_forward_pre_hook(hook, *, prepend=False, with_kwargs=False) +``` + +### [paddle.nn.Layer.register_forward_pre_hook](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#register-forward-pre-hook-hook) + +```python +paddle.nn.Layer.register_forward_pre_hook(hook) +``` +PyTorch 参数更多,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| hook | hook | 被注册的 hook。 | +| prepend | - | 是否在其他 hook 执行前执行,Paddle 无此参数,暂无转写方式。 | +| with_kwargs| - | 是否传入 forward 函数的参数,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_module.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_module.md new file mode 100644 index 00000000000..c2ac4b9f0bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_module.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.nn.Module.register_module +### [torch.nn.Module.register_module](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_module) + +```python +torch.nn.Module.register_module(name, module) +``` + +### [paddle.nn.Layer.add_sublayer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#add-sublayer-name-sublayer) + +```python +paddle.nn.Layer.add_sublayer(name, sublayer) +``` +两者功能一致,仅参数名不一致,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| name | name | 注册 buffer 的名字。可以通过此名字来访问已注册的 buffer。 | +| module | sublayer | 将被注册为 buffer 的模块。仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_parameter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_parameter.md new file mode 100644 index 00000000000..3b4bee98567 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.register_parameter.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.nn.Module.register_parameter + +### [torch.nn.Module.register_parameter](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.register_parameter) + +```python +torch.nn.Module.register_parameter(name, param) +``` + +### [paddle.nn.Layer.add_parameter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#add-parameter-name-parameter) + +```python +paddle.nn.Layer.add_parameter(name, parameter) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------- | +| name | name | 参数名。 | +| param | parameter | Parameter 实例,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.state_dict.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.state_dict.md new file mode 100644 index 00000000000..932e6370b83 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.state_dict.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ] torch.nn.Module.state_dict +### [torch.nn.Module.state_dict](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.state_dict) + +```python +torch.nn.Module.state_dict(*, destination, prefix, keep_vars) +``` + +### [paddle.nn.Layer.state_dict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#state-dict-destination-none-include-sublayers-true-use-hook-true) + +```python +paddle.nn.Layer.state_dict(destination=None, include_sublayers=True, use_hook=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| destination | destination | 所有参数和可持久性 buffers 都将存放在 destination 中 。 | +| prefix | - | 添加到参数和缓冲区名称的前缀,Paddle 无此参数,暂无转写方式。 | +| keep_vars | - | 状态字典中返回的 Tensor 是否与 autograd 分离,Paddle 无此参数,暂无转写方式 | +| - | include_sublayers | 包括子层的参数和 buffers, PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_hook | 将_state_dict_hooks 中注册的函数应用于 destination, PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.to.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.to.md new file mode 100644 index 00000000000..37b7ce3ada4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.to.md @@ -0,0 +1,122 @@ +## [参数不一致]torch.nn.Module.to + +### [torch.nn.Module.to](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.to) + +```python +torch.nn.Module.to(device=None, dtype=None, non_blocking=False) +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(device=None, dtype=None, blocking=None) +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -------------------------------------------------------------------------------------------------------- | +| device | device | Tensor 设备类型,PyTorch 为 torch.device,Paddle 为字符串 cpu,gpu:x,xpu:x 或 Place 对象,需要转写。 | +| dtype | dtype | Tensor 数据类型,PyTorch 为字符串或 PyTorch 数据类型,Paddle 为 字符串或 Paddle 数据类型,需要转写。 | +| non_blocking | blocking | 是否同步或异步拷贝,PyTorch 和 Paddle 取值相反,需要转写。 | + +### 转写示例 + +#### device 参数:Tensor 设备类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.to(device=torch.device("cuda:0")) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(device="gpu:0") +``` + +#### dtype 参数:Tensor 数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.to(dtype=torch.float32) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(dtype=paddle.float32) +``` + +#### non_blocking 参数:是否同步或异步拷贝 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.to(non_blocking = False) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(blocking=True) +``` + +--- + +### [torch.nn.Module.to](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.to) + +```python +torch.nn.Module.to(tensor, non_blocking=False) +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(device=None, dtype=None, blocking=None) +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | -------------------------------------------------------------- | +| tensor | - | 获取设备和数据类型的 Tensor,Paddle 无此参数,需要转写。 | +| - | device | Tensor 设备类型,PyTorch 无此参数,需要转写。 | +| - | dtype | Tensor 数据类型,PyTorch 无此参数,需要转写。 | +| non_blocking | blocking | 是否同步或异步拷贝,PyTorch 和 Paddle 取值相反,需要转写。 | + +### 转写示例 + +#### tensor 参数:获取设备和数据类型的 Tensor + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.to(x) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(device=x.place, dtype=x.dtype) +``` + +#### non_blocking 参数:是否同步或异步拷贝 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.to(x, non_blocking = False) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to(device=x.place, dtype=x.dtype, blocking=True) +``` + +--- + +### [torch.nn.Module.to](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.to) + +```python +torch.nn.Module.to(memory_format=torch.channels_last) +``` + +memory_format 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.train.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.train.md new file mode 100644 index 00000000000..ef6d1e43cb3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.train.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.nn.Module.train + +### [torch.nn.Module.train](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.train) + +```python +torch.nn.Module.train() +``` + +### [paddle.nn.Layer.train](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#train) + +```python +paddle.nn.Layer.train() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.type.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.type.md new file mode 100644 index 00000000000..b235335a6e7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.type.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.type + +### [torch.nn.Module.type](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.type) + +```python +torch.nn.Module.type(dst_type) +``` + +### [paddle.nn.Layer.astype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#astype-dtype-none) + +```python +paddle.nn.Layer.astype(dtype=None) +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------- | +| dst_type | dtype | PyTorch 为字符串或 PyTorch 数据类型,Paddle 为 字符串或 Paddle 数据类型,需要转写。 | + +### 转写示例 + +#### dst_type 参数:数据类型 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.type(dst_type=torch.float32) + +# Paddle 写法: +module = paddle.nn.Layer() +module.astype(dtype=paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.xpu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.xpu.md new file mode 100644 index 00000000000..e241768da1d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.xpu.md @@ -0,0 +1,35 @@ +## [参数不一致]torch.nn.Module.xpu + +### [torch.nn.Module.xpu](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.xpu) + +```python +torch.nn.Module.xpu(device=None) +``` + +### [paddle.nn.Layer.to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#to-device-none-dtype-none-blocking-none) + +```python +paddle.nn.Layer.to(device="xpu") +``` + +两者参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------- | +| device | device | PyTorch 为设备编号,Paddle 为 xpu:设备编号,需要转写。 | + +### 转写示例 + +#### device 参数:设备 + +```python +# PyTorch 写法: +module = torch.nn.Module() +module.xpu(0) + +# Paddle 写法: +module = paddle.nn.Layer() +module.to("xpu:0") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.zero_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.zero_grad.md new file mode 100644 index 00000000000..0d3e7ac1676 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Module.zero_grad.md @@ -0,0 +1,31 @@ +## [参数不一致]torch.nn.Module.zero_grad + +### [torch.nn.Module.zero_grad](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.zero_grad) + +```python +torch.nn.Module.zero_grad(set_to_none=True) +``` + +### [paddle.nn.Layer.clear_gradients](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Layer_cn.html#clear-gradients) + +```python +paddle.nn.Layer.clear_gradients(set_to_zero=True) +``` + +PyTorch 的 `Module.zero_grad` 参数与 Paddle 的 `Layer.clear_gradients` 参数用法刚好相反,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ------------------------------------------------ | +| set_to_none | set_to_zero | 设置如何清空梯度,PyTorch 默认 set_to_none 为 True,Paddle 默认 set_to_zero 为 True,两者功能刚好相反,Paddle 需设置为 False。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.Module.zero_grad(set_to_none=True) + +# Paddle 写法 +paddle.nn.Layer.clear_gradients(set_to_zero=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleDict.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleDict.md new file mode 100644 index 00000000000..5bb01a20047 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleDict.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.ModuleDict + +### [torch.nn.ModuleDict](https://pytorch.org/docs/stable/generated/torch.nn.ModuleDict.html?highlight=torch+nn+moduledict#torch.nn.ModuleDict) + +```python +torch.nn.ModuleDict(modules=None) +``` + +### [paddle.nn.LayerDict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LayerDict_cn.html) + +```python +paddle.nn.LayerDict(sublayers=None) +``` + +两者功能一致,参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----- | ---------- | ---------------------------------------------------------- | +| modules | sublayers | 键值对的可迭代对象,值的类型为 paddle.nn.Layer ,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleList.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleList.md new file mode 100644 index 00000000000..1a047247188 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ModuleList.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.nn.ModuleList + +### [torch.nn.ModuleList](https://pytorch.org/docs/stable/generated/torch.nn.ModuleList.html?highlight=torch+nn+modulelist#torch.nn.ModuleList) + +```python +torch.nn.ModuleList(modules=None) +``` + +### [paddle.nn.LayerList](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/LayerList_cn.html) + +```python +paddle.nn.LayerList(sublayers=None) +``` + +两者功能一致,参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----- | ---------- | -------------------------- | +| modules | sublayers | 要保存的子层,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelMarginLoss.md new file mode 100644 index 00000000000..4565dd09208 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelMarginLoss.md @@ -0,0 +1,44 @@ +## [仅 paddle 参数更多]torch.nn.MultiLabelMarginLoss + +### [torch.nn.MultiLabelMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.MultiLabelMarginLoss) + +```python +torch.nn.MultiLabelMarginLoss(size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.MultiLabelSoftMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MultiLabelSoftMarginLoss_cn.html) + +```python +paddle.nn.MultiLabelSoftMarginLoss(weight: Optional = None, reduction: str = 'mean', name: str = None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ---------------------------------------------------------------------------------- | +| - | weight | 权重值,默认为 None,PyTorch 无此参数,Paddle 保持默认即可。 | +| size_average | - | 已废弃(可用 `reduction` 代替)。表示是否采用 batch 中各样本 loss 平均值作为最终的 loss。如果置 False,则采用加和作为 loss。默认为 True,paddle 需要转写。 | +| reduce | - | 已废弃(可用 `reduction` 代替)。表示是否采用输出单个值作为 loss。如果置 False,则每个元素输出一个 loss 并忽略 `size_average`。默认为 True,paddle 需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' + +# 如果 PyTorch 存在 reduction 参数,则直接覆盖 +if 'reduction' not in kwargs: + kwargs['reduction'] = reduction +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelSoftMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelSoftMarginLoss.md new file mode 100644 index 00000000000..833cefa8530 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiLabelSoftMarginLoss.md @@ -0,0 +1,41 @@ +## [torch 参数更多]torch.nn.MultiLabelSoftMarginLoss + +### [torch.nn.MultiLabelSoftMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.MultiLabelSoftMarginLoss.html#torch.nn.MultiLabelSoftMarginLoss) + +```python +torch.nn.MultiLabelSoftMarginLoss(weight=None, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.MultiLabelSoftMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MultiLabelSoftMarginLoss_cn.html) + +```python +paddle.nn.MultiLabelSoftMarginLoss(weight=None, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ---------------------------------------------- | +| weight | weight | 手动设定权重。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiMarginLoss.md new file mode 100644 index 00000000000..aab3cc34fc0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiMarginLoss.md @@ -0,0 +1,46 @@ +## [torch 参数更多]torch.nn.MultiMarginLoss + +### [torch.nn.MultiMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.MultiMarginLoss) + +```python +torch.nn.MultiMarginLoss(p=1, margin=1.0, weight=None, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.MultiMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MultiMarginLoss_cn.html) + +```python +paddle.nn.MultiMarginLoss(p: int = 1, margin: float = 1.0, weight=None, reduction: str = 'mean', name: str = None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ---------------------------------------------------------------------------------- | +| p | p | 手动指定幂次方指数大小,默认为 1。 | +| margin | margin | 手动指定间距,默认为 1。 | +| weight | weight | 权重值,默认为 None。 如果给定权重则形状为 `[C,]` | +| size_average | - | 已废弃(可用 `reduction` 代替)。表示是否采用 batch 中各样本 loss 平均值作为最终的 loss。如果置 False,则采用加和作为 loss。默认为 True,paddle 需要转写。 | +| reduce | - | 已废弃(可用 `reduction` 代替)。表示是否采用输出单个值作为 loss。如果置 False,则每个元素输出一个 loss 并忽略 `size_average`。默认为 True,paddle 需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' + +# 如果 PyTorch 存在 reduction 参数,则直接覆盖 +if 'reduction' not in kwargs: + kwargs['reduction'] = reduction +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiheadAttention.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiheadAttention.md new file mode 100644 index 00000000000..52feb62cae1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.MultiheadAttention.md @@ -0,0 +1,33 @@ +## [torch 参数更多]torch.nn.MultiheadAttention + +### [torch.nn.MultiheadAttention](https://pytorch.org/docs/stable/generated/torch.nn.MultiheadAttention.html#torch.nn.MultiheadAttention) + +```python +torch.nn.MultiheadAttention(embed_dim, num_heads, dropout=0.0, bias=True, add_bias_kv=False, add_zero_attn=False, kdim=None, vdim=None, batch_first=False, device=None, dtype=None) +``` + +### [paddle.nn.MultiHeadAttention](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/MultiHeadAttention_cn.html) + +```python +paddle.nn.MultiHeadAttention(embed_dim, num_heads, dropout=0.0, kdim=None, vdim=None, need_weights=False, weight_attr=None, bias_attr=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------------------- | +| embed_dim | embed_dim | 输入输出的维度。 | +| num_heads | num_heads | 多头注意力机制的 Head 数量。 | +| dropout | dropout | 注意力目标的随机失活率。 | +| bias | bias_attr | 指定偏置参数属性的对象,Paddle 支持更多功能,同时支持 bool 用法。 | +| add_bias_kv | - | 在 dim=0 增加 bias,Paddle 无此参数,暂无转写方式。 | +| add_zero_attn | - | 在 dim=1 增加批量 0 值,Paddle 无此参数,暂无转写方式。 | +| kdim | kdim | 键值对中 key 的维度。 | +| vdim | vdim | 键值对中 value 的维度。 | +| batch_first | - | 表示输入数据的第 0 维是否代表 batch_size,Paddle 无此参数,暂无转写方式。 | +| device | - | Tensor 的设备,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | Tensor 的数据类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | need_weights | 表明是否返回注意力权重,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md new file mode 100644 index 00000000000..a47d772c848 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.NLLLoss.md @@ -0,0 +1,118 @@ +## [torch 参数更多]torch.nn.NLLLoss + +### [torch.nn.NLLLoss](https://pytorch.org/docs/stable/generated/torch.nn.NLLLoss.html?highlight=nllloss#torch.nn.NLLLoss) + +```python +torch.nn.NLLLoss(weight=None, + size_average=None, + ignore_index=- 100, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.NLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/NLLLoss_cn.html#nllloss) + +```python +paddle.nn.NLLLoss(weight=None, + ignore_index=- 100, + reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | ------------ | -------------------------------------------- | +| weight | weight | 表示每个类别的权重。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| ignore_index | ignore_index | 表示忽略的一个标签值。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 +#### size_average +```python +# Paddle 写法 +torch.nn.NLLLoss(size_average=True) + +# Paddle 写法 +paddle.nn.NLLLoss(reduction='mean') +``` + +#### size_average + +size_average 为 True + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, size_average=True) + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='mean') +``` + +size_average 为 False + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, size_average=False) + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='sum') +``` + +#### reduce + +reduce 为 True + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, reduce=True) + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='mean') +``` + +reduce 为 False + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, reduce=False) + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='none') +``` + +#### reduction + +reduction 为'none' + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, reduction='none') + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='none') +``` + +reduction 为'mean' + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, reduction='mean') + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='mean') +``` + +reduction 为'sum' + +```python +# PyTorch 写法 +torch.nn.NLLLoss(weight=w, reduction='sum') + +# Paddle 写法 +paddle.nn.NLLLoss(weight=w, reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PReLU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PReLU.md new file mode 100644 index 00000000000..9ac477b425f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PReLU.md @@ -0,0 +1,31 @@ +## [ 参数不一致 ]torch.nn.PReLU +### [torch.nn.PReLU](https://pytorch.org/docs/stable/generated/torch.nn.PReLU.html?highlight=prelu#torch.nn.PReLU) + +```python +torch.nn.PReLU(num_parameters=1, + init=0.25, + device=None, + dtype=None) +``` + +### [paddle.nn.PReLU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PReLU_cn.html#prelu) + +```python +paddle.nn.PReLU(num_parameters=1, + init=0.25, + weight_attr=None, + data_format='NCHW', + name=None) +``` + +其中 PyTorch 与 Paddle 均支持更多其它参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_parameters | num_parameters | 表示可训练 `weight` 的数量。 | +| init | init | 表示 `weight` 的初始值。 | +| device | - | 指定设备,PaddlePaddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 指定数据类型,PaddlePaddle 无此功能。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 指定输入的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PairwiseDistance.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PairwiseDistance.md new file mode 100644 index 00000000000..37a341b7d4e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PairwiseDistance.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.nn.PairwiseDistance +### [torch.nn.PairwiseDistance](https://pytorch.org/docs/stable/generated/torch.nn.PairwiseDistance.html?highlight=nn+pairwisedistance#torch.nn.PairwiseDistance) + +```python +torch.nn.PairwiseDistance(p=2.0, + eps=1e-06, + keepdim=False) +``` + +### [paddle.nn.PairwiseDistance](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PairwiseDistance_cn.html#pairwisedistance) + +```python +paddle.nn.PairwiseDistance(p=2., + epsilon=1e-6, + keepdim=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| p | p | 指定 p 阶的范数。 | +| eps | epsilon | 添加到分母的一个很小值,避免发生除零错误,仅参数名不一致。 | +| keepdim | keepdim | 表示是否在输出 Tensor 中保留减小的维度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Parameter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Parameter.md new file mode 100644 index 00000000000..f691bb3909e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Parameter.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.nn.Parameter + +### [torch.nn.Parameter](https://pytorch.org/docs/stable/generated/torch.nn.parameter.Parameter.html?highlight=torch+nn+parameter#torch.nn.parameter.Parameter) + +```python +torch.nn.Parameter(data=None, requires_grad=True) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 +```python +# PyTorch 写法 +y = torch.nn.Parameter(data=x, requires_grad=requires_grad) + +# Paddle 写法 +y = paddle.create_parameter(shape=x.shape, + dtype=x.dtype, + default_initializer=paddle.nn.initializer.Assign(x)) +y.stop_gradient = not requires_grad +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ParameterList.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ParameterList.md new file mode 100644 index 00000000000..175f86f4634 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ParameterList.md @@ -0,0 +1,18 @@ +## [ 仅参数名不一致 ]torch.nn.ParameterList +### [torch.nn.ParameterList](https://pytorch.org/docs/stable/generated/torch.nn.ParameterList.html?highlight=nn+parameterlist#torch.nn.ParameterList) + +```python +torch.nn.ParameterList(values=None) +``` + +### [paddle.nn.ParameterList](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ParameterList_cn.html#parameterlist) + +```python +paddle.nn.ParameterList(parameters=None) +``` +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| values | parameters | 可迭代的 Parameters,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelShuffle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelShuffle.md new file mode 100644 index 00000000000..fea4614aeb7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelShuffle.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.PixelShuffle +### [torch.nn.PixelShuffle](https://pytorch.org/docs/stable/generated/torch.nn.PixelShuffle.html?highlight=pixel#torch.nn.PixelShuffle) + +```python +torch.nn.PixelShuffle(upscale_factor) +``` + +### [paddle.nn.PixelShuffle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PixelShuffle_cn.html) + +```python +paddle.nn.PixelShuffle(upscale_factor, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| upscale_factor | upscale_factor | 表示增大空间分辨率的增大因子。 | +| - | data_format | 指定输入的 format , PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelUnshuffle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelUnshuffle.md new file mode 100644 index 00000000000..4ca18c43d81 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PixelUnshuffle.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.PixelUnshuffle +### [torch.nn.PixelUnshuffle](https://pytorch.org/docs/stable/generated/torch.nn.PixelUnshuffle.html?highlight=pixel#torch.nn.PixelUnshuffle) + +```python +torch.nn.PixelUnshuffle(downscale_factor) +``` + +### [paddle.nn.PixelUnshuffle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PixelUnshuffle_cn.html) + +```python +paddle.nn.PixelUnshuffle(downscale_factor, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| downscale_factor | downscale_factor | 表示减小空间分辨率的减小因子。 | +| - | data_format | 指定输入的 format , PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PoissonNLLLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PoissonNLLLoss.md new file mode 100644 index 00000000000..a6cf52fc9d4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.PoissonNLLLoss.md @@ -0,0 +1,46 @@ +## [torch 参数更多]torch.nn.PoissonNLLLoss + +### [torch.nn.PoissonNLLLoss](https://pytorch.org/docs/stable/generated/torch.nn.PoissonNLLLoss) + +```python +torch.nn.PoissonNLLLoss(log_input=True, full=False, size_average=None, eps=1e-08, reduce=None, reduction='mean') +``` + +### [paddle.nn.PoissonNLLLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/PoissonNLLLoss_cn.html) + +```python +paddle.nn.PoissonNLLLoss(log_input=True, full=False, epsilon=1e-8, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ---------------------------------------------------------------------------------- | +| log_input | log_input | 输入是否为对数函数映射后结果。 | +| full | full | 是否在损失计算中包括 Stirling 近似项。 | +| size_average | - | 已废弃(可用 `reduction` 代替)。表示是否采用 batch 中各样本 loss 平均值作为最终的 loss。如果置 False,则采用加和作为 loss。默认为 True,paddle 需要转写。 | +| eps | epsilon | 在 `log_input` 为 True 时使用的常数小量。默认值为 1e-8,仅参数名不一致。 | +| reduce | - | 已废弃(可用 `reduction` 代替)。表示是否采用输出单个值作为 loss。如果置 False,则每个元素输出一个 loss 并忽略 `size_average`。默认为 True,paddle 需要转写。 | +| reduction | reduction | 指定应用于输出结果的计算方式,可选值有 `none`、`mean` 和 `sum`。默认为 `mean`,计算 mini-batch loss 均值。设置为 `sum` 时,计算 mini-batch loss 的总和。设置为 `none` 时,则返回 loss Tensor。默认值下为 `mean`。两者完全一致。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' + +# 如果 PyTorch 存在 reduction 参数,则直接覆盖 +if 'reduction' not in kwargs: + kwargs['reduction'] = reduction +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md new file mode 100644 index 00000000000..a2e96f47c23 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNN.md @@ -0,0 +1,76 @@ +## [ 参数不一致 ]torch.nn.RNN +### [torch.nn.RNN](https://pytorch.org/docs/stable/generated/torch.nn.RNN.html#torch.nn.RNN) +```python +torch.nn.RNN(input_size, + hidden_size, + num_layers=1, + nonlinearity='tanh', + bias=True, + batch_first=False, + dropout=0, + bidirectional=False) +``` + +### [paddle.nn.SimpleRNN](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SimpleRNN_cn.html#simplernn) +```python +paddle.nn.SimpleRNN(input_size, hidden_size, num_layers=1, activation='tanh', direction='forward', dropout=0., time_major=False, weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| num_layers | num_layers | 表示循环网络的层数。 | +| nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | +| dropout | dropout | 表示 dropout 概率。 | +| bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | + + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.RNN(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.SimpleRNN(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.RNN(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.SimpleRNN(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` + +#### batch_first:batch size 是否为第一维 +```python +# PyTorch 写法 +torch.nn.RNN(16, 32, batch_first=True) + +# Paddle 写法 +paddle.nn.SimpleRNN(16, 32, time_major=False) +``` + +#### bidirectional:是否进行双向 +```python +# PyTorch 写法 +torch.nn.RNN(16, 32, bidirectional=True) + +# Paddle 写法 +paddle.nn.RNN(16, 32, direction='bidirectional') +``` +```python +# PyTorch 写法 +torch.nn.RNN(16, 32, bidirectional=False) + +# Paddle 写法 +paddle.nn.RNN(16, 32, direction='forward') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md new file mode 100644 index 00000000000..51687f3e2f0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNBase.md @@ -0,0 +1,102 @@ +## [torch 参数更多] torch.nn.RNNBase +### [torch.nn.RNNBase](https://pytorch.org/docs/stable/generated/torch.nn.RNNBase.html#torch.nn.RNNBase) +```python +torch.nn.RNNBase(mode: str, input_size: int, hidden_size: int, + num_layers: int = 1, bias: bool = True, batch_first: bool = False, + dropout: float = 0., bidirectional: bool = False, proj_size: int = 0, + device=None, dtype=None) +``` + +### [paddle.nn.layer.rnn.RNNBase](https://github.com/PaddlePaddle/Paddle/blob/e25e86f4f6d1bbd043b621a75e93d0070719c3d8/python/paddle/nn/layer/rnn.py#L1300) +```python +paddle.nn.layer.rnn.RNNBase(mode, input_size, hidden_size, + num_layers=1, direction="forward", time_major=False, + dropout=0.0, weight_ih_attr=None, weight_hh_attr=None, + bias_ih_attr=None, bias_hh_attr=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| mode | mode | 表示 `RNN` 模型的类型,torch 取值为 `'LSTM', 'GRU', 'RNN_TANH', 'RNN_RELU`,paddle 取值为 `'LSTM', 'GRU'`,需要转写。| +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| num_layers | num_layers | 表示循环网络的层数。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| batch_first | time_major | PyTorch 表示 batch size 是否为第一维,PaddlePaddle 表示 time steps 是否为第一维,它们的意义相反。需要转写。 | +| dropout | dropout | 表示 dropout 概率。 | +| bidirectional | direction | PyTorch 表示是否进行双向 RNN,Paddle 使用字符串表示是双向 RNN(`bidirectional`)还是单向 RNN(`forward`)。 | +| proj_size | - | PyTorch 表示投影层大小,默认为 0,表示不使用投影。Paddle 无此参数,一般对网络训练结果影响不大,现阶段直接删除。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数,Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### mode:RNN 模型类别 +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32) +``` + +```python +# PyTorch 写法 +torch.nn.RNNBase('GRU', 16, 32) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('GRU', 16, 32) +``` + +```python +# PyTorch 写法 +torch.nn.RNNBase('RNN_TANH', 16, 32) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('SimpleRNN', 16, 32) +``` + +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32, bias=True) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32) +``` + +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32, bias=False) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` + +#### batch_first:batch size 是否为第一维 +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32, batch_first=True) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32, time_major=False) +``` + +#### bidirectional:是否进行双向 +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32, bidirectional=True) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32, direction='bidirectional') +``` +```python +# PyTorch 写法 +torch.nn.RNNBase('LSTM', 16, 32, bidirectional=False) + +# Paddle 写法 +paddle.nn.layer.rnn.RNNBase('LSTM', 16, 32, direction='forward') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md new file mode 100644 index 00000000000..3c6534a4ec7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RNNCell.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.nn.RNNCell +### [torch.nn.RNNCell](https://pytorch.org/docs/stable/generated/torch.nn.RNNCell.html#torch.nn.RNNCell) +```python +torch.nn.RNNCell(input_size, hidden_size, bias=True, nonlinearity='tanh', device=None, dtype=None) +``` + +### [paddle.nn.SimpleRNNCell](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SimpleRNNCell_cn.html#simplernncell) +```python +paddle.nn.SimpleRNNCell(input_size, hidden_size, activation='tanh', weight_ih_attr=None, weight_hh_attr=None, bias_ih_attr=None, bias_hh_attr=None, name=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input_size | input_size | 表示输入 x 的大小。 | +| hidden_size | hidden_size | 表示隐藏状态 h 大小。 | +| bias | bias_ih_attr, bias_hh_attr | 是否使用偏置, Paddle 支持自定义偏置属性, torch 不支持,需要转写。 | +| nonlinearity | activation | 表示激活函数类型,仅参数名不一致。 | +| - |weight_ih_attr| weight_ih 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | +| - |weight_hh_attr| weight_hh 的参数, PyTorch 无此参数, Paddle 保持默认即可。 | + +### 转写示例 +#### bias:是否使用偏置 +```python +# PyTorch 写法 +torch.nn.RNNCell(16, 32, bias=True) + +# Paddle 写法 +paddle.nn.SimpleRNNCell(16, 32) +``` +```python +# PyTorch 写法 +torch.nn.RNNCell(16, 32, bias=False) + +# Paddle 写法 +paddle.nn.SimpleRNNCell(16, 32, bias_ih_attr=False, bias_hh_attr=False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RReLU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RReLU.md new file mode 100644 index 00000000000..0b09a4a4bf5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.RReLU.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.RReLU + +### [torch.nn.RReLU](https://pytorch.org/docs/stable/generated/torch.nn.RReLU.html#torch.nn.RReLU) + +```python +torch.nn.RReLU(lower=0.125, upper=0.3333333333333333, inplace=False) +``` + +### [paddle.nn.RReLU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/RReLU_cn.html) + +```python +paddle.nn.RReLU(lower=1. / 8., upper=1. / 3., name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| lower | lower | 负值斜率的随机值范围下限。 | +| upper | upper | 负值斜率的随机值范围上限。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU.md new file mode 100644 index 00000000000..e5269402202 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU.md @@ -0,0 +1,19 @@ +## [torch 参数更多 ]torch.nn.ReLU +### [torch.nn.ReLU](https://pytorch.org/docs/stable/generated/torch.nn.ReLU.html?highlight=relu#torch.nn.ReLU) + +```python +torch.nn.ReLU(inplace=False) +``` + +### [paddle.nn.ReLU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ReLU_cn.html#relu) + +```python +paddle.nn.ReLU(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| inplace | - | 在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU6.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU6.md new file mode 100644 index 00000000000..08d0664e273 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReLU6.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.nn.ReLU6 + +### [torch.nn.ReLU6](https://pytorch.org/docs/stable/generated/torch.nn.ReLU6.html#torch.nn.ReLU6) + +```python +torch.nn.ReLU6(inplace=False) +``` + +### [paddle.nn.ReLU6](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ReLU6_cn.html) + +```python +paddle.nn.ReLU6(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad1d.md new file mode 100644 index 00000000000..a016d7bbd8d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad1d.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.nn.ReflectionPad1d +### [torch.nn.ReflectionPad1d](https://pytorch.org/docs/stable/generated/torch.nn.ReflectionPad1d.html?highlight=pad#torch.nn.ReflectionPad1d) + +```python +torch.nn.ReflectionPad1d(padding) +``` + +### [paddle.nn.Pad1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad1D_cn.html#pad1d) + +```python +paddle.nn.Pad1D(padding, + mode='constant', + value=0.0, + data_format='NCL', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list),需要转写。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`reflect`。 | +| - | value | 表示填充值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReflectionPad1d((3, 1)) +m(input) + +# Paddle 写法 +m = nn.Pad1D([3, 1], mode='reflect') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad2d.md new file mode 100644 index 00000000000..0fbd97e31f8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad2d.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.nn.ReflectionPad2d +### [torch.nn.ReflectionPad2d](https://pytorch.org/docs/stable/generated/torch.nn.ReflectionPad2d.html?highlight=pad#torch.nn.ReflectionPad2d) + +```python +torch.nn.ReflectionPad2d(padding) +``` + +### [paddle.nn.Pad2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad2D_cn.html#pad2d) + +```python +paddle.nn.Pad2D(padding, + mode='constant', + value=0.0, + data_format='NCHW', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`reflect`。 | +| - | value | 表示填充值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReflectionPad2d((1, 0, 1, 2)) +m(input) + +# Paddle 写法 +m = nn.Pad2D([1, 0, 1, 2], mode='reflect') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad3d.md new file mode 100644 index 00000000000..f6e50177ebd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReflectionPad3d.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.nn.ReflectionPad3d +### [torch.nn.ReflectionPad3d](https://pytorch.org/docs/stable/generated/torch.nn.ReflectionPad3d.html?highlight=pad#torch.nn.ReflectionPad3d) + +```python +torch.nn.ReflectionPad3d(padding) +``` + +### [paddle.nn.Pad3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad3D_cn.html#pad3d) + +```python +paddle.nn.Pad3D(padding, + mode='constant', + value=0.0, + data_format='NCDHW', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`reflect`。 | +| - | value | 表示填充值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReflectionPad3d((1, 0, 1, 2, 0, 0)) +m(input) + +# Paddle 写法 +m = nn.Pad3D([1, 0, 1, 2, 0, 0], mode='reflect') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad1d.md new file mode 100644 index 00000000000..b880d53d177 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad1d.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.nn.ReplicationPad1d +### [torch.nn.ReplicationPad1d](https://pytorch.org/docs/stable/generated/torch.nn.ReplicationPad1d.html?highlight=pad#torch.nn.ReplicationPad1d) + +```python +torch.nn.ReplicationPad1d(padding) +``` + +### [paddle.nn.Pad1D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad1D_cn.html#pad1d) + +```python +paddle.nn.Pad1D(padding, + mode='constant', + value=0.0, + data_format='NCL', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list)。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`replicate`。 | +| - | value | 表示填充值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReplicationPad1d((3, 1)) +m(input) + +# Paddle 写法 +pad = paddle.to_tensor((3, 1)) +m = nn.Pad1D(pad, mode='replicate') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad2d.md new file mode 100644 index 00000000000..92d7febf3ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad2d.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ]torch.nn.ReplicationPad2d +### [torch.nn.ReplicationPad2d](https://pytorch.org/docs/stable/generated/torch.nn.ReplicationPad2d.html?highlight=pad#torch.nn.ReplicationPad2d) + +```python +torch.nn.ReplicationPad2d(padding) +``` + +### [paddle.nn.Pad2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad2D_cn.html#pad2d) + +```python +paddle.nn.Pad2D(padding, + mode='constant', + value=0.0, + data_format='NCHW', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list) ,需要转写。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`replicate`。 | +| - | value | 表示填充值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReplicationPad2d((3, 1)) +m(input) + +# Paddle 写法 +pad = paddle.to_tensor((3, 1)) +m = nn.Pad2D(pad, mode='replicate') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad3d.md new file mode 100644 index 00000000000..d5e5eed0bbc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ReplicationPad3d.md @@ -0,0 +1,38 @@ +## [ 参数不一致 ]torch.nn.ReplicationPad3d +### [torch.nn.ReplicationPad3d](https://pytorch.org/docs/stable/generated/torch.nn.ReplicationPad3d.html?highlight=pad#torch.nn.ReplicationPad3d) + +```python +torch.nn.ReplicationPad3d(padding) +``` + +### [paddle.nn.Pad3D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Pad3D_cn.html#pad3d) + +```python +paddle.nn.Pad3D(padding, + mode='constant', + value=0.0, + data_format='NCDHW', + name=None) +``` + +其中 Paddle 与 PyTorch 的 padding 所支持的参数类型不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 填充大小,PyTorch 和 Paddle 的 padding 参数的类型分别为 (int/tuple) 和 (int/Tensor/list) ,需要转写。 | +| - | mode | padding 的四种模式,PyTorch 无此参数,Paddle 需设置为`replicate`。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### padding:填充大小 +```python +# PyTorch 写法 +m = nn.ReplicationPad3d((3, 1)) +m(input) + +# Paddle 写法 +pad = paddle.to_tensor((3, 1)) +m = nn.Pad3D(pad, mode='replicate') +m(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SELU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SELU.md new file mode 100644 index 00000000000..eb7112d8754 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SELU.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.SELU + +### [torch.nn.SELU](https://pytorch.org/docs/stable/generated/torch.nn.SELU.html#torch.nn.SELU) + +```python +torch.nn.SELU(inplace=False) +``` + +### [paddle.nn.SELU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SELU_cn.html) + +```python +paddle.nn.SELU(scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | scale | selu 激活计算公式中的 scale 值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | alpha | selu 激活计算公式中的 alpha 值,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sequential.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sequential.md new file mode 100644 index 00000000000..e85dc5d5d72 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sequential.md @@ -0,0 +1,21 @@ +## [参数用法不一致]torch.nn.Sequential + +### [torch.nn.Sequential](https://pytorch.org/docs/stable/generated/torch.nn.Sequential.html#torch.nn.Sequential) + +```python +torch.nn.Sequential(arg: OrderedDict[str, Module]) +``` + +### [paddle.nn.Sequential](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Sequential_cn.html) + +```python +paddle.nn.Sequential(*layers) +``` + +其中功能一致, 参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| arg | layers | Paddle 支持 Layers 或可迭代的 name Layer 对,PyTorch 支持类型更多,包含 OrderedDict 类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SiLU.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SiLU.md new file mode 100644 index 00000000000..d4764f585c7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SiLU.md @@ -0,0 +1,21 @@ +## [torch 参数更多]torch.nn.SiLU + +### [torch.nn.SiLU](https://pytorch.org/docs/stable/generated/torch.nn.SiLU.html#torch.nn.SiLU) + +```python +torch.nn.SiLU(inplace=False) +``` + +### [paddle.nn.Silu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Silu_cn.html) + +```python +paddle.nn.Silu(name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sigmoid.md new file mode 100644 index 00000000000..77797d8079d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Sigmoid.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.nn.Sigmoid + +### [torch.nn.Sigmoid](https://pytorch.org/docs/stable/generated/torch.nn.Sigmoid.html) + +```python +torch.nn.Sigmoid(*args, **kwargs) +``` + +### [paddle.nn.Sigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Sigmoid_cn.html#sigmoid) + +```python +paddle.nn.Sigmoid(name=None) +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md new file mode 100644 index 00000000000..6dab2d8da77 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SmoothL1Loss.md @@ -0,0 +1,103 @@ +## [torch 参数更多 ]torch.nn.SmoothL1Loss +### [torch.nn.SmoothL1Loss](https://pytorch.org/docs/stable/generated/torch.nn.SmoothL1Loss.html?highlight=smoothl1loss#torch.nn.SmoothL1Loss) + +```python +torch.nn.SmoothL1Loss(size_average=None, + reduce=None, + reduction='mean', + beta=1.0) +``` + +### [paddle.nn.SmoothL1Loss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SmoothL1Loss_cn.html#smoothl1loss) + +```python +paddle.nn.SmoothL1Loss(reduction='mean', + delta=1.0, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | +| beta | delta | SmoothL1Loss 损失的阈值参数,beta 不为 1.0 时 Paddle 不支持,暂无转写方式。 | + +### 转写示例 +#### size_average +```python +# Paddle 写法 +torch.nn.SmoothL1Loss(size_average=True) + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='mean') +``` + +#### size_average +size_average 为 True +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(size_average=True) + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='mean') +``` + +size_average 为 False +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(size_average=False) + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='sum') +``` + +#### reduce +reduce 为 True +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(reduce=True) + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='mean') +``` + +reduce 为 False +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(reduce=False) + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='none') +``` + +#### reduction +reduction 为'none' +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(reduction='none') + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='none') +``` + +reduction 为'mean' +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(reduction='mean') + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='mean') +``` + +reduction 为'sum' +```python +# PyTorch 写法 +torch.nn.SmoothL1Loss(reduction='sum') + +# Paddle 写法 +paddle.nn.SmoothL1Loss(reduction='sum') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md new file mode 100644 index 00000000000..e75aefee643 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SoftMarginLoss.md @@ -0,0 +1,45 @@ +## [torch 参数更多]torch.nn.SoftMarginLoss + +### [torch.nn.SoftMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.SoftMarginLoss.html#torch.nn.SoftMarginLoss) + +```python +torch.nn.SoftMarginLoss(size_average=None, + reduce=None, + reduction='mean') +``` + +### [paddle.nn.SoftMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SoftMarginLoss_cn.html#softmarginloss) + +```python +paddle.nn.SoftMarginLoss(reduction='mean', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------ | --------- | -------------------------------------------- | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduction | reduction | 表示应用于输出结果的计算方式。 | + +### 转写示例 + +#### size_average + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax.md new file mode 100644 index 00000000000..c2f1e199169 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.Softmax +### [torch.nn.Softmax](https://pytorch.org/docs/stable/generated/torch.nn.Softmax.html?highlight=nn+softmax#torch.nn.Softmax) + +```python +torch.nn.Softmax(dim=None) +``` + +### [paddle.nn.Softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Softmax_cn.html#softmax) + +```python +paddle.nn.Softmax(axis=- 1, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md new file mode 100644 index 00000000000..ef2be99fdab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softmax2d.md @@ -0,0 +1,33 @@ +## [仅 paddle 参数更多]torch.nn.Softmax2d + +### [torch.nn.Softmax2d](https://pytorch.org/docs/stable/generated/torch.nn.Softmax2d.html?highlight=softmax2d#torch.nn.Softmax2d) + +```python +torch.nn.Softmax2d() +``` + +### [paddle.nn.Softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Softmax_cn.html#softmax) + +```python +paddle.nn.Softmax(axis=-1) +``` + +其中 Paddle 并没有 torch.nn.Softmax2d 此 api ,可通过 paddle.nn.Softmax 设置参数 axis 为 -3 实现同样的效果: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------ | +| - | axis | 指定对输入 Tensor 进行运算的轴。 | + +### 转写示例 + +```python +# PyTorch 写法 +cri = torch.nn.Softmax2d() +cri(input) + +# Paddle 写法 +cri = paddle.nn.Softmax(axis=-3) +cri(input) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softplus.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softplus.md new file mode 100644 index 00000000000..487d63b3567 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softplus.md @@ -0,0 +1,15 @@ +## [ 参数完全一致 ] torch.nn.Softplus + +### [torch.nn.Softplus](https://pytorch.org/docs/stable/generated/torch.nn.Softplus.html) + +```python +torch.nn.Softplus(beta=1, threshold=20) +``` + +### [paddle.nn.Softplus](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Softplus_cn.html) + +```python +paddle.nn.Softplus(beta=1, threshold=20, name=None) +``` + +两者功能一致,参数完全一致。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softshrink.md new file mode 100644 index 00000000000..28bf71cd5ee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softshrink.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.Softshrink +### [torch.nn.Softshrink](https://pytorch.org/docs/stable/generated/torch.nn.Softshrink.html?highlight=nn+softshrink#torch.nn.Softshrink) + +```python +torch.nn.Softshrink(lambd=0.5) +``` + +### [paddle.nn.Softshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Softshrink_cn.html#softshrink) + +```python +paddle.nn.Softshrink(threshold=0.5, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| lambd | threshold | Softshrink 激活计算公式中的阈值,必须大于等于零,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softsign.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softsign.md new file mode 100644 index 00000000000..633fc2daaf2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Softsign.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.nn.Softsign + +### [torch.nn.Softsign](https://pytorch.org/docs/stable/generated/torch.nn.Softsign.html) + +```python +torch.nn.Softsign(*args, **kwargs) +``` + +### [paddle.nn.Softsign](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Softsign_cn.html) + +```python +paddle.nn.Softsign(name=None) +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.convert_sync_batchnorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.convert_sync_batchnorm.md new file mode 100644 index 00000000000..4a04a7da378 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.convert_sync_batchnorm.md @@ -0,0 +1,20 @@ +## [ torch 参数更多 ]torch.nn.SyncBatchNorm.convert_sync_batchnorm +### [torch.nn.SyncBatchNorm.convert_sync_batchnorm](https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html?highlight=convert_sync_batchnorm#torch.nn.SyncBatchNorm.convert_sync_batchnorm) + +```python +torch.nn.SyncBatchNorm.convert_sync_batchnorm(module, process_group=None) +``` + +### [paddle.nn.SyncBatchNorm.convert_sync_batchnorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SyncBatchNorm_cn.html#convert-sync-batchnorm-layer) + +```python +paddle.nn.SyncBatchNorm.convert_sync_batchnorm(layer) +``` + +PyTorch 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| module | layer | 需要转换的模型层, 仅参数名不一致。 | +| process_group | - | 统计信息的同步分别在每个进程组内发生, Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.md new file mode 100644 index 00000000000..ea6db0200ca --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.SyncBatchNorm.md @@ -0,0 +1,58 @@ +## [ 参数不一致 ]torch.nn.SyncBatchNorm +### [torch.nn.SyncBatchNorm](https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html#torch.nn.SyncBatchNorm) + +```python +torch.nn.SyncBatchNorm(num_features, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True, process_group=None, device=None, dtype=None) +``` + +### [paddle.nn.SyncBatchNorm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/SyncBatchNorm_cn.html#syncbatchnorm) + +```python +paddle.nn.SyncBatchNorm(num_features, epsilon=1e-5, momentum=0.9, weight_attr=None, bias_attr=None, data_format='NCHW', name=None) +``` + +两者功能一致但参数不一致,部分参数名不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| num_features | num_features | 表示输入 Tensor 通道数。 | +| eps | epsilon | 为了数值稳定加在分母上的值。 | +| momentum | momentum | 表示归一化函数中的超参数, PyTorch 和 Paddle 公式实现细节不一致,两者正好是相反的,需要转写。 | +| - | weight_attr | 指定权重参数属性的对象。如果为 False, 则表示每个通道的伸缩固定为 1,不可改变。默认值为 None,表示使用默认的权重参数属性。 | +| - | bias_attr | 指定偏置参数属性的对象。如果为 False, 则表示每一个通道的偏移固定为 0,不可改变。默认值为 None,表示使用默认的偏置参数属性。 | +| - | data_format | 指定输入数据格式, PyTorch 无此参数,Paddle 保持默认即可。 | +| affine | - | 是否进行反射变换, Paddle 无此参数,需要转写。 | +| track_running_stats | use_global_stats | 表示是否已加载的全局均值和方差。 | +| process_group | - | 统计信息的同步分别在每个进程组内发生, Paddle 无此参数,暂无转写方式。 | +| device | - | 设备类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 参数类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 +#### affine:是否进行反射变换 +```python +affine=False 时,表示不更新: + +# PyTorch 写法 +m = torch.nn.SyncBatchNorm(24, affine=False) + +# Paddle 写法 +m = paddle.nn.SyncBatchNorm(24, weight_attr=False, bias_attr=False) + +affine=True 时,表示更新: + +# PyTorch 写法 +m = torch.nn.SyncBatchNorm(24) + +# Paddle 写法 +m = paddle.nn.SyncBatchNorm(24) +``` + +#### momentum: +```python +# PyTorch 写法 +m = torch.nn.SyncBatchNorm(24, momentum=0.2) + +# Paddle 写法 +m = paddle.nn.SyncBatchNorm(24, momentum=0.8) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanh.md new file mode 100644 index 00000000000..656a1323a5a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanh.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.nn.Tanh + +### [torch.nn.Tanh](https://pytorch.org/docs/stable/generated/torch.nn.Tanh.html) + +```python +torch.nn.Tanh(*args, **kwargs) +``` + +### [paddle.nn.Tanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Tanh_cn.html) + +```python +paddle.nn.Tanh(name=None) +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanhshrink.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanhshrink.md new file mode 100644 index 00000000000..3bf82caac8e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Tanhshrink.md @@ -0,0 +1,15 @@ +## [ 无参数 ] torch.nn.Tanhshrink + +### [torch.nn.Tanhshrink](https://pytorch.org/docs/stable/generated/torch.nn.Tanhshrink.html) + +```python +torch.nn.Tanhshrink(*args, **kwargs) +``` + +### [paddle.nn.Tanhshrink](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Tanhshrink_cn.html) + +```python +paddle.nn.Tanhshrink(name=None) +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Threshold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Threshold.md new file mode 100644 index 00000000000..dcc0994be94 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Threshold.md @@ -0,0 +1,23 @@ +## [torch 参数更多]torch.nn.Threshold + +### [torch.nn.Threshold](https://pytorch.org/docs/stable/generated/torch.nn.Threshold.html#torch.nn.Threshold) + +```python +torch.nn.Threshold(threshold, value, inplace=False) +``` + +### [paddle.nn.ThresholdedReLU](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ThresholdedReLU_cn.html) + +```python +paddle.nn.ThresholdedReLU(threshold=1.0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| threshold | threshold | ThresholdedReLU 激活计算公式中的 threshold 值。 | +| value | - | 不在指定 threshold 范围时的值,Paddle 无此参数,暂无转写方式。 | +| inplace | - | 表示在不更改变量的内存地址的情况下,直接修改变量的值,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Transformer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Transformer.md new file mode 100644 index 00000000000..f6990ea928d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Transformer.md @@ -0,0 +1,64 @@ +## [torch 参数更多]torch.nn.Transformer + +### [torch.nn.Transformer](https://pytorch.org/docs/stable/generated/torch.nn.Transformer.html#torch.nn.Transformer) + +```python +torch.nn.Transformer(d_model=512, nhead=8, num_encoder_layers=6, num_decoder_layers=6, dim_feedforward=2048, dropout=0.1, activation=, custom_encoder=None, custom_decoder=None, layer_norm_eps=1e-05, batch_first=False, norm_first=False, device=None, dtype=None) +``` + +### [paddle.nn.Transformer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Transformer_cn.html) + +```python +paddle.nn.Transformer(d_model=512, nhead=8, num_encoder_layers=6, num_decoder_layers=6, dim_feedforward=2048, dropout=0.1, activation='relu', attn_dropout=None, act_dropout=None, normalize_before=False, weight_attr=None, bias_attr=None, custom_encoder=None, custom_decoder=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ----------------------------------------------------------------------------------- | +| d_model | d_model | 编码器和解码器的输入输出的维度。 | +| nhead | nhead | 多头注意力机制的 Head 数量。 | +| num_encoder_layers | num_encoder_layers | 编码器中 TransformerEncoderLayer 的层数。 | +| num_decoder_layers | num_decoder_layers | 解码器中 TransformerDecoderLayer 的层数。 | +| dim_feedforward | dim_feedforward | 前馈神经网络中隐藏层的大小。 | +| dropout | dropout | 对编码器和解码器中每个子层的输出进行处理的 dropout 值。 | +| activation | activation | 前馈神经网络的激活函数。 | +| custom_encoder | custom_encoder | 若提供该参数,则将 custom_encoder 作为编码器。 | +| custom_decoder | custom_decoder | 若提供该参数,则将 custom_decoder 作为解码器。 | +| layer_norm_eps | - | 层 normalization 组件的 eps 值,Paddle 无此参数,暂无转写方式。 | +| batch_first | - | 表示输入数据的第 0 维是否代表 batch_size,Paddle 无此参数,暂无转写方式。 | +| norm_first | normalize_before | 是否 LayerNorms 操作在 attention 和 feedforward 前,仅参数名不一致。 | +| device | - | Tensor 的设备,Paddle 无此参数,需要转写。 | +| dtype | - | Tensor 的数据类型,Paddle 无此参数,需要转写。 | +| - | attn_dropout | 多头自注意力机制中对注意力目标的随机失活率,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | act_dropout | 前馈神经网络的激活函数后的 dropout,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### device:Tensor 的设备 + +```python +# PyTorch 写法 +m = torch.nn.Transformer(device=torch.device('cpu')) +y = m(x) + +# Paddle 写法 +m = paddle.nn.Transformer() +y = m(x).cpu() +``` + +#### dtype:Tensor 的数据类型 + +```python +# PyTorch 写法 +m = torch.nn.Transformer(dtype=torch.float32) +y = m(x) + +# Paddle 写法 +m = paddle.nn.Transformer() +y = m(x).astype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoder.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoder.md new file mode 100644 index 00000000000..1c255b44149 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoder.md @@ -0,0 +1,23 @@ +## [参数完全一致]torch.nn.TransformerDecoder + +### [torch.nn.TransformerDecoder](https://pytorch.org/docs/stable/generated/torch.nn.TransformerDecoder.html#transformerdecoder) + +```python +torch.nn.TransformerDecoder(decoder_layer, num_layers, norm=None) +``` + +### [paddle.nn.TransformerDecoder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/TransformerDecoder_cn.html) + +```python +paddle.nn.TransformerDecoder(decoder_layer, num_layers, norm=None) +``` + +其中功能一致, 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------------- | ------------- | ------------------------------------------ | +| decoder_layer | decoder_layer | TransformerDecoderLayer 的一个实例。 | +| num_layers | num_layers | TransformerDecoderLayer 层的叠加数量。 | +| norm | norm | 层标准化(Layer Normalization)。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoderLayer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoderLayer.md new file mode 100644 index 00000000000..01a879d962d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerDecoderLayer.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.nn.TransformerDecoderLayer +### [torch.nn.TransformerDecoderLayer](https://pytorch.org/docs/stable/generated/torch.nn.TransformerDecoderLayer.html?highlight=transformerdecoderlayer#torch.nn.TransformerDecoderLayer) + +```python +torch.nn.TransformerDecoderLayer(d_model, + nhead, + dim_feedforward=2048, + dropout=0.1, + activation="relu', + layer_norm_eps=1e-05, + batch_first=False, + norm_first=False, + device=None, + dtype=None) +``` +### [paddle.nn.TransformerDecoderLayer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/TransformerDecoderLayer_cn.html#transformerdecoderlayer) + +```python +paddle.nn.TransformerDecoderLayer(d_model, + nhead, + dim_feedforward=2048, + dropout=0.1, + activation="relu', + attn_dropout=None, + act_dropout=None, + normalize_before=False, + weight_attr=None, + bias_attr=None, + layer_norm_eps=1e-05) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| d_model | d_model | 表示输入的维度。 | +| nhead | nhead | 表示多头注意力机制的 head 数量。 | +| dim_feedforward | dim_feedforward | 前馈神经网络中隐藏层的大小。 | +| dropout | dropout | dropout 值。 | +| activation | activation | 前馈神经网络的激活函数。 | +| layer_norm_eps | layer_norm_eps | layer normalization 层的 eps 值。 | +| batch_first | - | 输入和输出 tensor 的 shape,Paddle 无此参数,暂无转写方式 | +| norm_first | normalize_before | 设置对每个子层的输入输出的处理。如果为 True,则对每个子层的输入进行层标准化(Layer Normalization),对每个子层的输出进行 dropout 和残差连接(residual connection)。否则(即为 False),则对每个子层的输入不进行处理,只对每个子层的输出进行 dropout、残差连接(residual connection)和层标准化(Layer Normalization)。默认值:False。 仅参数名不一致| +| device | - | 设备类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 参数类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数的属性,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数的属性, PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoder.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoder.md new file mode 100644 index 00000000000..c937cce039a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoder.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.nn.TransformerEncoder + +### [torch.nn.TransformerEncoder](https://pytorch.org/docs/stable/generated/torch.nn.TransformerEncoder.html#torch.nn.TransformerEncoder) + +```python +torch.nn.TransformerEncoder(encoder_layer, num_layers, norm=None, enable_nested_tensor=True, mask_check=True) +``` + +### [paddle.nn.TransformerEncoder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/TransformerEncoder_cn.html) + +```python +paddle.nn.TransformerEncoder(encoder_layer, num_layers, norm=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------------- | ------------- | ------------------------------------------ | +| encoder_layer | encoder_layer | TransformerEncoderLayer 的一个实例。 | +| num_layers | num_layers | TransformerEncoderLayer 层的叠加数量。 | +| norm | norm | 层标准化(Layer Normalization)。 | +| enable_nested_tensor | - | 是否转为嵌套 Tensor,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| mask_check | - | mask_check 参数,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoderLayer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoderLayer.md new file mode 100644 index 00000000000..3aa7056e51b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TransformerEncoderLayer.md @@ -0,0 +1,60 @@ +## [torch 参数更多]torch.nn.TransformerEncoderLayer + +### [torch.nn.TransformerEncoderLayer](https://pytorch.org/docs/stable/generated/torch.nn.TransformerEncoderLayer.html#torch.nn.TransformerEncoderLayer) + +```python +torch.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward=2048, dropout=0.1, activation=, layer_norm_eps=1e-05, batch_first=False, norm_first=False, device=None, dtype=None) +``` + +### [paddle.nn.TransformerEncoderLayer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/TransformerEncoderLayer_cn.html) + +```python +paddle.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward, dropout=0.1, activation='relu', attn_dropout=None, act_dropout=None, normalize_before=False, weight_attr=None, bias_attr=None, layer_norm_eps=1e-05) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------------- | ---------------- | ----------------------------------------------------------------------------------- | +| d_model | d_model | 输入输出的维度。 | +| nhead | nhead | 多头注意力机制的 Head 数量。 | +| dim_feedforward | dim_feedforward | 前馈神经网络中隐藏层的大小。 | +| dropout | dropout | 对两个子层的输出进行处理的 dropout 值。 | +| activation | activation | 前馈神经网络的激活函数。 | +| layer_norm_eps | layer_norm_eps | 层 normalization 组件的 eps 值。 | +| batch_first | - | 表示输入数据的第 0 维是否代表 batch_size,Paddle 无此参数,暂无转写方式。 | +| norm_first | normalize_before | 是否 LayerNorms 操作在 attention 和 feedforward 前,仅参数名不一致。 | +| device | - | Tensor 的设备,Paddle 无此参数,需要转写。 | +| dtype | - | Tensor 的数据类型,Paddle 无此参数,需要转写。 | +| - | attn_dropout | 多头自注意力机制中对注意力目标的随机失活率,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | act_dropout | 前馈神经网络的激活函数后的 dropout,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### device:Tensor 的设备 + +```python +# PyTorch 写法 +m = torch.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward,device=torch.device('cpu')) +y = m(x) + +# Paddle 写法 +m = paddle.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward) +y = m(x).cpu() +``` + +#### dtype:Tensor 的数据类型 + +```python +# PyTorch 写法 +m = torch.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward,dtype=torch.float32) +y = m(x) + +# Paddle 写法 +m = paddle.nn.TransformerEncoderLayer(d_model, nhead, dim_feedforward) +y = m(x).astype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginLoss.md new file mode 100644 index 00000000000..0b91b6a6975 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginLoss.md @@ -0,0 +1,44 @@ +## [torch 参数更多]torch.nn.TripletMarginLoss + +### [torch.nn.TripletMarginLoss](https://pytorch.org/docs/stable/generated/torch.nn.TripletMarginLoss.html#torch.nn.TripletMarginLoss) + +```python +torch.nn.TripletMarginLoss(margin=1.0, p=2.0, eps=1e-06, swap=False, size_average=None, reduce=None, reduction='mean') +``` + +### [paddle.nn.TripletMarginLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/TripletMarginLoss_cn.html) + +```python +paddle.nn.TripletMarginLoss(margin=1.0, p=2., epsilon=1e-6, swap=False, reduction='mean', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ---------------------------------------------- | +| margin | margin | 手动指定间距。 | +| p | p | 手动指定范数。 | +| eps | epsilon | 防止除数为 0,仅参数名不一致。 | +| swap | swap | 默认为 False。 | +| size_average | - | 已废弃,和 reduce 组合决定损失计算方式。 | +| reduce | - | 已废弃,和 size_average 组合决定损失计算方式。 | +| reduction | reduction | 指定应用于输出结果的计算方式。 | + +### 转写示例 + +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginWithDistanceLoss.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginWithDistanceLoss.md new file mode 100644 index 00000000000..8ba47014935 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.TripletMarginWithDistanceLoss.md @@ -0,0 +1,15 @@ +## [ 参数完全一致 ] torch.nn.TripletMarginWithDistanceLoss + +### [torch.nn.TripletMarginWithDistanceLoss](https://pytorch.org/docs/stable/generated/torch.nn.TripletMarginWithDistanceLoss.html) + +```python +torch.nn.TripletMarginWithDistanceLoss(*, distance_function=None, margin=1.0, swap=False, reduction='mean') +``` + +### [paddle.nn.TripletMarginWithDistanceLoss](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/TripletMarginWithDistanceLoss_cn.html#tripletmarginwithdistanceloss) + +```python +paddle.nn.TripletMarginWithDistanceLoss(distance_function=None, margin: float = 1.0, swap: bool = False, reduction: str = 'mean', name: str = None) +``` + +两者功能一致,参数完全一致。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unflatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unflatten.md new file mode 100644 index 00000000000..9ae6319af6a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unflatten.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.Unflatten +### [torch.nn.Unflatten](https://pytorch.org/docs/stable/generated/torch.nn.Unflatten.html?highlight=torch+nn+unflatten#torch.nn.Unflatten) + +```python +torch.nn.Unflatten(dim, unflattened_size) +``` + +### [paddle.nn.Unflatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Unflatten_cn.html#unflatten) + +```python +paddle.nn.Unflatten(axis, shape, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| unflattened_size | shape | 需要展开的形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unfold.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unfold.md new file mode 100644 index 00000000000..5fbd073cf23 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Unfold.md @@ -0,0 +1,37 @@ +## [ 参数不一致 ]torch.nn.Unfold +### [torch.nn.Unfold](https://pytorch.org/docs/stable/generated/torch.nn.Unfold.html?highlight=nn+unfold#torch.nn.Unfold) + +```python +torch.nn.Unfold(kernel_size, + dilation=1, + padding=0, + stride=1) +``` + +### [paddle.nn.Unfold](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Unfold_cn.html#unfold) + +```python +paddle.nn.Unfold(kernel_size=[3, 3], + strides=1, + paddings=1, + dilation=1, + name=None) +``` +其中 Paddle 与 PyTorch 前四个参数所支持的参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| kernel_size | kernel_sizes | 卷积核大小, PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 | +| dilation | dilations | 卷积膨胀,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 | +| padding | paddings | 每个维度的扩展,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。 | +| stride | strides | 步长大小,PyTorch 参数类型为 int、tuple(int) 或者 list(int), Paddle 参数类型为 int 或者 list(int)。| + +### 转写示例 +``` python +# PyTorch 写法: +unfold = nn.Unfold(kernel_size=(2, 3)) + +# Paddle 写法 +unfold = nn.Unfold(kernel_size=[2, 3]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Upsample.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Upsample.md new file mode 100644 index 00000000000..caf64dd6666 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.Upsample.md @@ -0,0 +1,33 @@ +## [ 仅 paddle 参数更多 ]torch.nn.Upsample +### [torch.nn.Upsample](https://pytorch.org/docs/stable/generated/torch.nn.Upsample.html?highlight=upsample#torch.nn.Upsample) + +```python +torch.nn.Upsample(size=None, + scale_factor=None, + mode='nearest', + align_corners=False) +``` + +### [paddle.nn.Upsample](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/Upsample_cn.html#upsample) + +```python +paddle.nn.Upsample(size=None, + scale_factor=None, + mode='nearest', + align_corners=False, + align_mode=0, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | size | 表示输出 Tensor 的大小。 | +| scale_factor | scale_factor | 输入的高度或宽度的乘数因子。 | +| mode | mode | 表示插值方法。 | +| align_corners | align_corners | 表示是否将输入和输出张量的 4 个角落像素的中心对齐,并保留角点像素的值。 | +| - | align_mode | 双线性插值的可选项,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | Tensor 的所需数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingBilinear2D.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingBilinear2D.md new file mode 100644 index 00000000000..f2101d7e030 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingBilinear2D.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.UpsamplingBilinear2d + +### [torch.nn.UpsamplingBilinear2d](https://pytorch.org/docs/stable/generated/torch.nn.UpsamplingBilinear2d.html?highlight=upsamplingbilinear2d#torch.nn.UpsamplingBilinear2d) + +```python +torch.nn.UpsamplingBilinear2d(size=None, scale_factor=None) +``` + +### [paddle.nn.UpsamplingBilinear2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/UpsamplingBilinear2D_cn.html) + +```python +paddle.nn.UpsamplingBilinear2D(size=None,scale_factor=None, data_format='NCHW',name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | size | 表示输出 Tensor 的 size 。 | +| scale_factor | scale_factor | 表示输入 Tensor 的高度或宽度的乘数因子。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingNearest2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingNearest2d.md new file mode 100644 index 00000000000..0d888f78631 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.UpsamplingNearest2d.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.UpsamplingNearest2d + +### [torch.nn.UpsamplingNearest2d](https://pytorch.org/docs/stable/generated/torch.nn.UpsamplingNearest2d.html?highlight=upsampl#torch.nn.UpsamplingNearest2d) + +```python +torch.nn.UpsamplingNearest2d(size=None, scale_factor=None) +``` + +### [paddle.nn.UpsamplingNearest2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/UpsamplingNearest2D_cn.html) + +```python +paddle.nn.UpsamplingNearest2D(size=None, scale_factor=None, data_format='NCHW',name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| size | size | 表示输出 Tensor 的 size 。 | +| scale_factor | scale_factor | 表示输入 Tensor 的高度或宽度的乘数因子。 | +| - | data_format | 表示输入 Tensor 的数据格式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ZeroPad2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ZeroPad2d.md new file mode 100644 index 00000000000..e3a99280fc7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.ZeroPad2d.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.nn.ZeroPad2d +### [torch.nn.ZeroPad2d](https://pytorch.org/docs/stable/generated/torch.nn.ZeroPad2d.html?highlight=zeropad#torch.nn.ZeroPad2d) + +```python +torch.nn.ZeroPad2d(padding) +``` + +### [paddle.nn.ZeroPad2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/ZeroPad2D_cn.html) + +```python +paddle.nn.ZeroPad2D(padding, + data_format='NCHW', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| padding | padding | 表示填充大小。 | +| - | data_format | 指定输入的 format, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.functional.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.functional.softmax.md new file mode 100644 index 00000000000..26b26f5cb1a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.functional.softmax.md @@ -0,0 +1,24 @@ +## [ torch 参数更多 ]torch.nn.functional.softmax + +### [torch.nn.functional.softmax](https://pytorch.org/docs/stable/generated/torch.nn.functional.softmax.html#torch.nn.functional.softmax) + +```python +torch.nn.functional.softmax(input, dim=None, _stacklevel=3, dtype=None) +``` + +### [paddle.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softmax_cn.html#softmax) + +```python +paddle.nn.functional.softmax(x, axis=-1, dtype=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | -------------- | ----------------------------------------------------- | +| input | x | 表示输入张量,仅参数名不一致。 | +| dim | axis | 表示对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| dtype | dtype | 表示返回张量所需的数据类型。 | +| _stacklevel | - | Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._ntuple.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._ntuple.md new file mode 100644 index 00000000000..112df6f386c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._ntuple.md @@ -0,0 +1,28 @@ +## [ 组合替代实现 ]torch.nn.modules.utils._ntuple + +### [torch.nn.modules.utils._ntuple](https://github.com/pytorch/pytorch/blob/1f4d4d3b7836d38d936a21665e6b2ab0b39d7092/torch/nn/modules/utils.py#L8) + +```python +torch.nn.modules.utils._ntuple(n, name="parse") +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.modules.utils._ntuple(2, name="parse") + +# Paddle 写法 +def _ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + +_ntuple(2, name="parse") +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._pair.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._pair.md new file mode 100644 index 00000000000..439b5b1afcb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.modules.utils._pair.md @@ -0,0 +1,28 @@ +## [ 组合替代实现 ]torch.nn.modules.utils._pair + +### [torch.nn.modules.utils._pair](https://github.com/pytorch/pytorch/blob/1f4d4d3b7836d38d936a21665e6b2ab0b39d7092/torch/nn/modules/utils.py#L198) + +```python +torch.nn.modules.utils._pair(x) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.nn.modules.utils._pair(x) + +# Paddle 写法 +def _ntuple(n, name="parse"): + def parse(x): + if isinstance(x, collections.abc.Iterable): + return tuple(x) + return tuple(repeat(x, n)) + + parse.__name__ = name + return parse + +_ntuple(n=2, name="parse")(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.parallel.DistributedDataParallel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.parallel.DistributedDataParallel.md new file mode 100644 index 00000000000..9b5580ea02d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.parallel.DistributedDataParallel.md @@ -0,0 +1,33 @@ +## [torch 参数更多]torch.nn.parallel.DistributedDataParallel + +### [torch.nn.parallel.DistributedDataParallel](https://pytorch.org/docs/stable/generated/torch.nn.parallel.DistributedDataParallel.html#torch.nn.parallel.DistributedDataParallel) + +```python +torch.nn.parallel.DistributedDataParallel(module, device_ids=None, output_device=None, dim=0, broadcast_buffers=True, process_group=None, bucket_cap_mb=25, find_unused_parameters=False, check_reduction=False, gradient_as_bucket_view=False, static_graph=False) +``` + +### [paddle.DataParallel](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/DataParallel_cn.html) + +```python +paddle.DataParallel(layers, strategy=None, comm_buffer_size=25, last_comm_buffer_size=1, find_unused_parameters=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------- | ---------------------- | ---------------------------------------------------------------------------------------- | +| module | layers | 需要通过数据并行方式执行的模型,仅参数名不一致。 | +| device_ids | - | 设置输入设备,Paddle 无此参数,暂无转写方式。 | +| output_device | - | 设置输出设备,Paddle 无此参数,暂无转写方式。 | +| dim | - | 进行运算的轴,Paddle 无此参数,暂无转写方式。 | +| broadcast_buffers | - | forward 开始时是否同步缓存,Paddle 无此参数,暂无转写方式。 | +| process_group | - | 进程组,Paddle 无此参数,暂无转写方式。 | +| bucket_cap_mb | comm_buffer_size | 它是通信调用(如 NCCLAllReduce)时,参数梯度聚合为一组的内存大小(MB),仅参数名不一致。 | +| find_unused_parameters | find_unused_parameters | 是否在模型 forward 函数的返回值的所有张量中,遍历整个向后图。 | +| check_reduction | - | 已废弃,Paddle 无此参数,暂无转写方式。 | +| gradient_as_bucket_view | - | 是否在 allreduce 通讯中配置梯度,Paddle 无此参数,暂无转写方式。 | +| static_graph | - | 是否训练静态图,Paddle 无此参数,暂无转写方式。 | +| - | strategy | 已废弃,数据并行的策略,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | last_comm_buffer_size | 它限制通信调用中最后一个缓冲区的内存大小,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.parameters_to_vector.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.parameters_to_vector.md new file mode 100644 index 00000000000..7b0caf0defe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.parameters_to_vector.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.nn.utils.parameters_to_vector + +### [torch.nn.utils.parameters_to_vector](https://pytorch.org/docs/stable/generated/torch.nn.utils.parameters_to_vector.html#torch-nn-utils-parameters-to-vector) + +```python +torch.nn.utils.parameters_to_vector(parameters) +``` + +### [paddle.nn.utils.parameters_to_vector](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/parameters_to_vector_cn.html#parameters-to-vector) + +```python +paddle.nn.utils.parameters_to_vector(parameters, name=None) +``` + +两者功能一致,参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| parameters | parameters | 可迭代的多个 parameter。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.vector_to_parameters.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.vector_to_parameters.md new file mode 100644 index 00000000000..1cd33ec4f70 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/nn/torch.nn.utils.vector_to_parameters.md @@ -0,0 +1,22 @@ +## [ 参数完全一致 ]torch.nn.utils.vector_to_parameters + +### [torch.nn.utils.vector_to_parameters](https://pytorch.org/docs/stable/generated/torch.nn.utils.vector_to_parameters.html#torch-nn-utils-vector-to-parameters) + +```python +torch.nn.utils.vector_to_parameters(vec, parameters) +``` + +### [paddle.nn.utils.vector_to_parameters](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/vector_to_parameters_cn.html#vector-to-parameters) + +```python +paddle.nn.utils.vector_to_parameters(vec, parameters, name=None) +``` + +两者功能一致,参数用法一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| vec | vec | 一个 1-D Tensor,它将被切片并复制到输入参数(input parameters)中。 | +| parameters | parameters | 可迭代的多个 parameter。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Generator.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Generator.md new file mode 100644 index 00000000000..1d50e9f0bfd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Generator.md @@ -0,0 +1,28 @@ +## [组合替代实现]torch.Generator + +### [torch.Generator](https://pytorch.org/docs/stable/generated/torch.Generator.html#generator) + +```python +torch.Generator(device='cpu') +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.Generator() + +# Paddle 写法 +paddle.framework.core.default_cpu_generator() +``` + +```python +# PyTorch 写法 +torch.Generator(device="cuda") + +# Paddle 写法 +device = paddle.device.get_device() +paddle.framework.core.default_cuda_generator(int(device[-1])) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Size.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Size.md new file mode 100644 index 00000000000..8f428ee39d3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Size.md @@ -0,0 +1,27 @@ +## [组合替代实现]torch.Size + +### [torch.Size](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-pytorch-functions) + +```python +torch.Size(sizes) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.Size([1]) + +# Paddle 写法 +(1,) +``` + +```python +# PyTorch 写法 +torch.Size([2, 3]) + +# Paddle 写法 +(2, 3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Tensor__upper.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Tensor__upper.md new file mode 100644 index 00000000000..ff946db584c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.Tensor__upper.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.Tensor + +### [torch.Tensor](https://pytorch.org/docs/stable/tensors.html) + +```python +torch.Tensor(data) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, dtype=None, place=None, stop_gradient=True) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------- | +| data | data | 要转换的数据。 | +| - | dtype | Tensor 的数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | place | Tensor 的设备,PyTorch 无此参数,Paddle 需设置为 'cpu' 。 | +| - | stop_gradient | 是否阻断 Autograd 的梯度传导。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs.md new file mode 100644 index 00000000000..00560828059 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs.md @@ -0,0 +1,37 @@ +## [torch 参数更多 ]torch.abs + +### [torch.abs](https://pytorch.org/docs/stable/generated/torch.abs.html?highlight=abs#torch.abs) + +```python +torch.abs(input, + *, + out=None) +``` + +### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/abs_cn.html#abs) + +```python +paddle.abs(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.abs([-3, -5], out=y) + +# Paddle 写法 +paddle.assign(paddle.abs([-3, -5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs_.md new file mode 100644 index 00000000000..78b072c0078 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.abs_.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.abs_ + +### [torch.abs_](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-tensor-methods) + +```python +torch.abs_(input) +``` + +### [paddle.abs_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/abs_cn.html) + +```python +paddle.abs_(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.absolute.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.absolute.md new file mode 100644 index 00000000000..942632fc3d7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.absolute.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.absolute + +### [torch.absolute](https://pytorch.org/docs/stable/generated/torch.absolute.html?highlight=absolute#torch.absolute) + +```python +torch.absolute(input, + *, + out=None) +``` + +### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/abs_cn.html#abs) + +```python +paddle.abs(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.absolute(torch.tensor([-3, -5]), out=y) + +# Paddle 写法 +paddle.assign(paddle.abs(paddle.to_tensor([-3, -5])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md new file mode 100644 index 00000000000..8f8b2e2ac2a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acos.md @@ -0,0 +1,37 @@ +## [torch 参数更多 ]torch.acos + +### [torch.acos](https://pytorch.org/docs/stable/generated/torch.acos.html?highlight=acos#torch.acos) + +```python +torch.acos(input, + *, + out=None) +``` + +### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/acos_cn.html#acos) + +```python +paddle.acos(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.acos(torch.tensor([0.3348, -0.5889]), out=y) + +# Paddle 写法 +paddle.assign(paddle.acos(paddle.to_tensor([0.3348, -0.5889])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acosh.md new file mode 100644 index 00000000000..23c1fb96dfa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.acosh.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.acosh + +### [torch.acosh](https://pytorch.org/docs/stable/generated/torch.acosh.html?highlight=acosh#torch.acosh) + +```python +torch.acosh(input, + *, + out=None) +``` + +### [paddle.acosh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/acosh_cn.html#acos) + +```python +paddle.acosh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.acosh(torch.tensor([1.3192, 1.9915]), out=y) + +# Paddle 写法 +paddle.assign(paddle.acosh(paddle.to_tensor([1.3192, 1.9915])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.add.md new file mode 100644 index 00000000000..4fa00e4092b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.add.md @@ -0,0 +1,53 @@ +## [torch 参数更多 ]torch.add + +### [torch.add](https://pytorch.org/docs/stable/generated/torch.add.html?highlight=add#torch.add) + +```python +torch.add(input, + other, + *, + alpha=1, + out=None) +``` + +### [paddle.add](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/add_cn.html#add) + +```python +paddle.add(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| alpha | - | 表示 other 的乘数,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### alpha:other 的乘数 + +```python +# PyTorch 写法 +torch.add(torch.tensor([3, 5]), torch.tensor([2, 3]), alpha=2) + +# Paddle 写法 +paddle.add(paddle.to_tensor([3, 5]), 2 * paddle.to_tensor( [2, 3])) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.add(torch.tensor([3, 5]), torch.tensor([2, 3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.add(paddle.to_tensor([3, 5]), paddle.to_tensor([2, 3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addbmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addbmm.md new file mode 100644 index 00000000000..7541fd91ae6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addbmm.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.addbmm + +### [torch.addbmm](https://pytorch.org/docs/stable/generated/torch.addbmm.html#torch.addbmm) + +```python +torch.addbmm(input, batch1, batch2, *, beta=1, alpha=1, out=None) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.addbmm(input, batch1, batch2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.sum(paddle.bmm(batch1, batch2), axis=0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcdiv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcdiv.md new file mode 100644 index 00000000000..fa134b7e018 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcdiv.md @@ -0,0 +1,22 @@ +## [ 组合替代实现 ]torch.addcdiv + +### [torch.addcdiv](https://pytorch.org/docs/stable/generated/torch.addcdiv.html#torch.addcdiv) +```python +torch.addcdiv(input, tensor1, tensor2, *, value=1, out=None) +``` + +用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相除,再加上输入 `input` ,公式为: + +$ out = input + value * (tensor1 / tensor2) $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.addcdiv(input, tensor1, tensor2, value=value) + +# Paddle 写法 +y = input + value * tensor1 / tensor2 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcmul.md new file mode 100644 index 00000000000..a14ba6e31c0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addcmul.md @@ -0,0 +1,22 @@ +## [ 组合替代实现 ]torch.addcmul + +### [torch.addcmul](https://pytorch.org/docs/stable/generated/torch.addcmul.html#torch.addcmul) +```python +torch.addcmul(input, tensor1, tensor2, *, value=1, out=None) +``` + +用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相乘,再加上输入 `input` ,公式为: + +$ out = input + value * tensor1 * tensor2 $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.addcmul(input, tensor1, tensor2, value=value) + +# Paddle 写法 +y = input + value * tensor1 * tensor2 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmm.md new file mode 100644 index 00000000000..da5dd88cc3a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmm.md @@ -0,0 +1,38 @@ +## [ torch 参数更多]torch.addmm + +### [torch.addmm](https://pytorch.org/docs/stable/generated/torch.addmm.html?highlight=addmm#torch.addmm) + +```python +torch.addmm(input,mat1,mat2,*,beta=1,alpha=1,out=None) +``` + +### [paddle.addmm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/addmm_cn.html) + +```python +paddle.addmm(input,x,y,alpha=1.0,beta=1.0,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| input | input | 表示输入的 Tensor 。 | +| mat1 | x | 表示输入的第一个 Tensor ,仅参数名不一致。 | +| mat2 | y | 表示输入的第二个 Tensor ,仅参数名不一致。 | +| beta | beta | 表示乘以 input 的标量。 | +| alpha | alpha | 表示乘以 mat1 * mat2 的标量。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.addmm(input,x,y,beta,alpha,out=output) + +# Paddle 写法 +paddle.assign(paddle.addmm(input,x,y,beta,alpha),output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmv.md new file mode 100644 index 00000000000..52122326596 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addmv.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.addmv + +### [torch.addmv](https://pytorch.org/docs/stable/generated/torch.addmv.html?highlight=addmv#torch.addmv) +```python +torch.addmv(input, mat, vec, beta=1, alpha=1, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.addmv(input, mat, vec, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.mm(mat, vec) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addr.md new file mode 100644 index 00000000000..defc99f3b43 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.addr.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.addr + +### [torch.addr](https://pytorch.org/docs/stable/generated/torch.addr.html?highlight=addr#torch.addr) + +```python +torch.addr(input, vec1, vec2, beta=1, alpha=1, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.addr(input, vec1, vec2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.outer(vec1, vec2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.adjoint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.adjoint.md new file mode 100644 index 00000000000..e39791cf2e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.adjoint.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.adjoint + +### [torch.adjoint](https://pytorch.org/docs/stable/generated/torch.adjoint.html#torch.adjoint) +```python +torch.adjoint(input) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.adjoint(input) + +# Paddle 写法 +y = paddle.conj(paddle.transpose(input, perm=[0, 2, 1])) + +# 注:假设 input 为 3D Tensor, paddle 需要对 input 的后两维转置。 +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.all.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.all.md new file mode 100644 index 00000000000..2a6eec47a01 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.all.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.all + +### [torch.all](https://pytorch.org/docs/stable/generated/torch.all.html?highlight=all#torch.all) + +```python +torch.all(input, dim=None, keepdim=False, *, out=None) +``` + +### [paddle.all](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/all_cn.html#all) + +```python +paddle.all(x, + axis=None, + keepdim=False, + name=None) +``` + +其中 Paddle 与 PyTorch 的 `input` 参数所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写。 | +| dim | axis | 表示运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +y = torch.all(x) + +# Paddle 写法 +y = paddle.all(x.astype('bool')) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.allclose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.allclose.md new file mode 100644 index 00000000000..6ece6ca3253 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.allclose.md @@ -0,0 +1,34 @@ +## [ 仅参数名不一致 ]torch.allclose + +### [torch.allclose](https://pytorch.org/docs/stable/generated/torch.allclose.html?highlight=allclose#torch.allclose) + +```python +torch.allclose(input, + other, + rtol=1e-05, + atol=1e-08, + equal_nan=False) +``` + +### [paddle.allclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/allclose_cn.html#allclose) + +```python +paddle.allclose(x, + y, + rtol=1e-05, + atol=1e-08, + equal_nan=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| rtol | rtol | 表示相对容忍误差。 | +| atol | atol | 表示绝对容忍误差。 | +| equal_nan | equal_nan | 表示是否将两个 NaN 数值视为相等 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.alpha_dropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.alpha_dropout.md new file mode 100644 index 00000000000..c47d03232d9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.alpha_dropout.md @@ -0,0 +1,23 @@ +## [ 仅参数默认值不一致 ]torch.alpha_dropout + +### [torch.alpha\_dropout](https://pytorch.org/docs/master/generated/torch.nn.functional.alpha_dropout.html) + +```python +torch.alpha_dropout(input, p=0.5, train=False) +``` + +### [paddle.nn.functional.alpha\_dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/alpha_dropout_cn.html#alpha-dropout) + +```python +paddle.nn.functional.alpha_dropout(x, p=0.5, training=True, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率,即丢弃概率。 | +| train | training | 标记是否为训练阶段。PyTorch 默认值为 False,Paddle 默认值为 True。Paddle 需设置为与 PyTorch 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amax.md new file mode 100644 index 00000000000..1b03c76efef --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amax.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.amax + +### [torch.amax](https://pytorch.org/docs/stable/generated/torch.amax.html) + +```python +torch.amax(input, dim, keepdim=False, *, out=None) +``` + +### [paddle.amax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amax_cn.html#amax) + +```python +paddle.amax(x, axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axis | 求最大值运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 指定输出 + +```python +# PyTorch 写法 +torch.amax(a, dim=0,out=y) + +# Paddle 写法 +paddle.assign(paddle.amax(a, dim=0), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amin.md new file mode 100644 index 00000000000..2a461b835bf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.amin.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.amin + +### [torch.amin](https://pytorch.org/docs/stable/generated/torch.amin.html) + +```python +torch.amin(input, dim, keepdim=False, *, out=None) +``` + +### [paddle.amin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amin_cn.html#amin) + +```python +paddle.amin(x, axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axis | 求最小值运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 指定输出 + +```python +# PyTorch 写法 +torch.amin(a, dim=0,out=y) + +# Paddle 写法 +paddle.assign(paddle.amin(a, dim=0), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.aminmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.aminmax.md new file mode 100644 index 00000000000..df79e3eaada --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.aminmax.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.aminmax + +### [torch.aminmax](https://pytorch.org/docs/stable/generated/torch.aminmax.html#torch.aminmax) + +```python +torch.aminmax(input, *, dim=None, keepdim=False, out=None) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.aminmax(input, dim=-1, keepdim=True) + +# Paddle 写法 +y = tuple([paddle.amin(input, axis=-1, keepdim=True), paddle.amax(input, axis=-1, keepdim=True)]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.angle.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.angle.md new file mode 100644 index 00000000000..914d48185f8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.angle.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.angle + +### [torch.angle](https://pytorch.org/docs/stable/generated/torch.angle.html) + +```python +torch.angle(input, *, out=None) +``` + +### [paddle.angle](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/angle_cn.html#angle) + +```python +paddle.angle(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| out | - | 输出 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 指定输出 + +```python +# PyTorch 写法 +torch.angle(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.angle(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.any.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.any.md new file mode 100644 index 00000000000..dae4cdad475 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.any.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.any + +### [torch.any](https://pytorch.org/docs/stable/generated/torch.any.html?highlight=any#torch.any) + +```python +torch.any(input, dim=None, keepdim=False, *, out=None) +``` + +### [paddle.any](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/any_cn.html#any) + +```python +paddle.any(x, + axis=None, + keepdim=False, + name=None) +``` + +其中 Paddle 与 PyTorch 的 `input` 参数所支持的类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,PyTorch 支持布尔和数值类型的输入,Paddle 仅支持布尔类型,需要转写。 | +| dim | axis | 表示运算的维度,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度,参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +y = torch.any(x) + +# Paddle 写法 +y = paddle.any(x.astype('bool')) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arange.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arange.md new file mode 100644 index 00000000000..b31c802dbec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arange.md @@ -0,0 +1,74 @@ +## [torch 参数更多]torch.arange + +### [torch.arange](https://pytorch.org/docs/stable/generated/torch.arange.html?highlight=arange#torch.arange) + +```python +torch.arange(start=0, + end, + step=1, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.arange](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/arange_cn.html) + +```python +paddle.arange(start=0, + end=None, + step=1, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| start | start | 表示区间起点(且区间包括此值)。 | +| end | end | 表示区间终点(且通常区间不包括此值)。 | +| step | step | 表示均匀分割的步长。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.arange(5, out=y) + +# Paddle 写法 +paddle.assign(paddle.arange(5), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.arange(5, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.arange(5) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.arange(5, requires_grad=True) + +# Paddle 写法 +y = paddle.arange(5) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccos.md new file mode 100644 index 00000000000..70b015de96c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccos.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.arccos + +### [torch.arccos](https://pytorch.org/docs/stable/generated/torch.arccos.html?highlight=arccos#torch.arccos) + +```python +torch.arccos(input, + *, + out=None) +``` + +### [paddle.acos](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/acos_cn.html#acos) + +```python +paddle.acos(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.arccos(torch.tensor([0.3348, -0.5889]), out=y) + +# Paddle 写法 +paddle.assign(paddle.acos(paddle.to_tensor([0.3348, -0.5889])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccosh.md new file mode 100644 index 00000000000..004f91b4fde --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arccosh.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.arccosh + +### [torch.arccosh](https://pytorch.org/docs/stable/generated/torch.arccosh.html?highlight=arccosh#torch.arccosh) + +```python +torch.arccosh(input, + *, + out=None) +``` + +### [paddle.acosh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/acosh_cn.html#acos) + +```python +paddle.acosh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.arccosh(torch.tensor([1.3192, 1.9915]), out=y) + +# Paddle 写法 +paddle.assign(paddle.acosh(paddle.to_tensor([1.3192, 1.9915])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsin.md new file mode 100644 index 00000000000..36506f54408 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsin.md @@ -0,0 +1,36 @@ +## [torch 参数更多 ]torch.arcsin + +### [torch.arcsin](https://pytorch.org/docs/stable/generated/torch.arcsin.html#torch.arcsin) + +```python +torch.arcsin(input, + *, + out=None) +``` + +### [paddle.asin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/asin_cn.html#asin) + +```python +paddle.asin(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.arcsin(torch.tensor([-0.5962, 0.4985]), out=y) + +# Paddle 写法 +paddle.assign(paddle.asin(paddle.to_tensor([-0.5962, 0.4985])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsinh.md new file mode 100644 index 00000000000..89cb680f4d8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arcsinh.md @@ -0,0 +1,36 @@ +## [torch 参数更多 ]torch.arcsinh + +### [torch.arcsinh](https://pytorch.org/docs/stable/generated/torch.arcsinh.html#torch.arcsinh) + +```python +torch.arcsinh(input, + *, + out=None) +``` + +### [paddle.asinh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/asinh_cn.html) + +```python +paddle.asinh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.arcsinh(torch.tensor([-0.5962, 0.4985]), out=y) + +# Paddle 写法 +paddle.assign(paddle.asinh(paddle.to_tensor([-0.5962, 0.4985])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan.md new file mode 100644 index 00000000000..1acba9baa44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan.md @@ -0,0 +1,36 @@ +## [torch 参数更多 ]torch.arctan + +### [torch.arctan](https://pytorch.org/docs/stable/generated/torch.arctan.html#torch.arctan) + +```python +torch.arctan(input, + *, + out=None) +``` + +### [paddle.atan](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atan_cn.html#atan) + +```python +paddle.atan(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.arctan(torch.tensor([0.2341, 0.2539]), out=y) + +# Paddle 写法 +paddle.assign(paddle.atan(paddle.to_tensor([0.2341, 0.2539])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan2.md new file mode 100644 index 00000000000..eb70c86d9f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctan2.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.arctan2 +### [torch.arctan2](https://pytorch.org/docs/stable/generated/torch.arctan2.html#torch.arctan2) + +```python +torch.arctan2(input, + other, + *, + out=None) +``` + +### [paddle.atan2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atan2_cn.html) + +```python +paddle.atan2(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.arctan2(input, other, out=y) + +# Paddle 写法 +paddle.assign(paddle.atan2(input, other), output=y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctanh.md new file mode 100644 index 00000000000..3a3cf84b44b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.arctanh.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.arctanh +### [torch.arctanh](https://pytorch.org/docs/stable/generated/torch.arctanh.html#torch.arctanh) + +```python +torch.arctanh(input, + *, + out=None) +``` + +### [paddle.atanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atanh_cn.html) + +```python +paddle.atanh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.arctanh(torch.tensor([ 0.2341, 0.2539]), out=y) + +# Paddle 写法 +paddle.assign(paddle.atanh(paddle.to_tensor([ 0.2341, 0.2539])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmax.md new file mode 100644 index 00000000000..2c22ef2a44c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmax.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.argmax +### [torch.argmax](https://pytorch.org/docs/stable/generated/torch.argmax.html?highlight=argmax#torch.argmax) + +```python +torch.argmax(input, + dim=None, + keepdim=False) +``` + +### [paddle.argmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/argmax_cn.html#argmax) + +```python +paddle.argmax(x, + axis=None, + keepdim=False, + dtype='int64', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,仅参数名不一致。 | +| dim | axis | 指定进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| - | dtype | 输出 Tensor 的数据类型, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmin.md new file mode 100644 index 00000000000..399fa110ab5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argmin.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.argmin +### [torch.argmin](https://pytorch.org/docs/stable/generated/torch.argmin.html?highlight=argmin#torch.argmin) + +```python +torch.argmin(input, + dim=None, + keepdim=False) +``` + +### [paddle.argmin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/argmin_cn.html#argmin) + +```python +paddle.argmin(x, + axis=None, + keepdim=False, + dtype='int64', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,仅参数名不一致。 | +| dim | axis | 指定进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| - | dtype | 输出 Tensor 的数据类型, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argsort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argsort.md new file mode 100644 index 00000000000..0936465c2ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argsort.md @@ -0,0 +1,23 @@ +## [ torch 参数更多 ]torch.argsort +### [torch.argsort](https://pytorch.org/docs/stable/generated/torch.argsort.html#torch.argsort) + +```python +torch.argsort(input, dim=- 1, descending=False, stable=False) +``` + +### [paddle.argsort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/argsort_cn.html#argsort) + +```python +paddle.argsort(x, axis=- 1, descending=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,仅参数名不一致。 | +| dim | axis | 指定进行运算的轴,仅参数名不一致。 | +| descending | descending | 是否使用降序排列。 | +| stable | - | 是否使用稳定排序。Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argwhere.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argwhere.md new file mode 100644 index 00000000000..f172fdd5685 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.argwhere.md @@ -0,0 +1,21 @@ +## [ 仅 paddle 参数更多 ]torch.argwhere +### [torch.argwhere](https://pytorch.org/docs/stable/generated/torch.argwhere.html#torch.argwhere) + +```python +torch.argwhere(input) +``` + +### [paddle.nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nonzero_cn.html#nonzero) + +```python +paddle.nonzero(x, as_tuple=False) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| - | as_tuple | 返回格式。是否以 1-D Tensor 构成的元组格式返回。 PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_strided.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_strided.md new file mode 100644 index 00000000000..83fa5a288b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_strided.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.as_strided +### [torch.as_strided](https://pytorch.org/docs/stable/generated/torch.as_strided.html?highlight=as_strided#torch.as_strided) + +```python +torch.as_strided(input, + size, + stride, + storage_offset=None) +``` + +### [paddle.as_strided](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/as_strided_cn.html#as-strided) + +```python +paddle.as_strided(x, + shape, + stride, + offset=0, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor, 仅参数名不一致。 | +| size | shape | 表示输出 Tensor 的维度, 仅参数名不一致。 | +| stride | stride | 表示输出 Tensor 的 stride。 | +| storage_offset | offset | 表示偏移量, 仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_tensor.md new file mode 100644 index 00000000000..e7697477f99 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.as_tensor.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.as_tensor +### [torch.as_tensor](https://pytorch.org/docs/stable/generated/torch.as_tensor.html#torch.as_tensor) + +```python +torch.as_tensor(data, + dtype=None, + device=None) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, + dtype=None, + place=None, + stop_gradient=True) +``` + +两者功能一致,性能某些用法下比 PyTorch 差(比如如果输入一个 Tensor , PyTorch 会直接返回, Paddle 会复制后返回)。此外, Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| data | data | 表示输入的 Tensor 。 | +| dtype | dtype | 表示 Tensor 的数据类型。 | +| device | place | 表示 Tensor 的存放位置,仅参数名不一致。 | +| - | stop_gradient | 表示是否阻断梯度传导, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asarray.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asarray.md new file mode 100644 index 00000000000..cad5938d7d1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asarray.md @@ -0,0 +1,37 @@ +## [torch 参数更多]torch.asarray + +### [torch.asarray](https://pytorch.org/docs/stable/generated/torch.asarray.html#torch.asarray) + +```python +torch.asarray(obj, *, dtype=None, device=None, copy=None, requires_grad=False) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html) + +```python +paddle.to_tensor(data, dtype=None, place=None, stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | ------------------------------------------------------------------------ | +| obj | data | 初始化 Tensor 的数据,仅参数名不一致。 | +| dtype | dtype | 创建 Tensor 的数据类型。 | +| device | place | 创建 Tensor 的设备位置。 | +| copy | - | 是否和原 Tensor 共享内存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| requires_grad | stop_gradient | 是否阻断 Autograd 的梯度传导,PyTorch 和 Paddle 取值相反,需要转写。 | + +### 转写示例 + +#### requires_grad 参数:是否阻断 Autograd 的梯度传导 + +```python +# PyTorch 写法: +torch.asarray(x, requires_grad=False) + +# Paddle 写法: +paddle.to_tensor(x, stop_gradient=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asin.md new file mode 100644 index 00000000000..c7134ea904e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asin.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.asin +### [torch.asin](https://pytorch.org/docs/stable/generated/torch.asin.html#torch.asin) + +```python +torch.asin(input, + *, + out=None) +``` + +### [paddle.asin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/asin_cn.html#asin) + +```python +paddle.asin(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.asin(torch.tensor([-0.5962, 0.4985]), out=y) + +# Paddle 写法 +paddle.assign(paddle.asin(paddle.to_tensor([-0.5962, 0.4985])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asinh.md new file mode 100644 index 00000000000..b0245921ffd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.asinh.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.asinh +### [torch.asinh](https://pytorch.org/docs/stable/generated/torch.asinh.html#torch.asinh) + +```python +torch.asinh(input, + *, + out=None) +``` + +### [paddle.asinh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/asinh_cn.html) + +```python +paddle.asinh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.asinh(torch.tensor([-0.5962, 0.4985]), out=y) + +# Paddle 写法 +paddle.assign(paddle.asinh(paddle.to_tensor([-0.5962, 0.4985])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan.md new file mode 100644 index 00000000000..973bf93c745 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.atan +### [torch.atan](https://pytorch.org/docs/stable/generated/torch.atan.html#torch.atan) + +```python +torch.atan(input, + *, + out=None) +``` + +### [paddle.atan](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atan_cn.html#atan) + +```python +paddle.atan(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.atan(torch.tensor([ 0.2341, 0.2539]), out=y) + +# Paddle 写法 +paddle.assign(paddle.atan(paddle.to_tensor([ 0.2341, 0.2539])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan2.md new file mode 100644 index 00000000000..f8abef48d5f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atan2.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.atan2 +### [torch.atan2](https://pytorch.org/docs/stable/generated/torch.atan2.html#torch.atan2) + +```python +torch.atan2(input, + other, + *, + out=None) +``` + +### [paddle.atan2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atan2_cn.html) + +```python +paddle.atan2(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.atan2(torch.tensor([0.2,0.3]),torch.tensor([0.4,0.5]),out=y) + +# Paddle 写法 +paddle.assign(paddle.atan2(paddle.to_tensor([0.2,0.3]),paddle.to_tensor([0.4,0.5])),y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atanh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atanh.md new file mode 100644 index 00000000000..d4db65457b1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atanh.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.atanh +### [torch.atanh](https://pytorch.org/docs/stable/generated/torch.atanh.html#torch.atanh) + +```python +torch.atanh(input, + *, + out=None) +``` + +### [paddle.atanh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atanh_cn.html) + +```python +paddle.atanh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.atanh(torch.tensor([ 0.2341, 0.2539]), out=y) + +# Paddle 写法 +paddle.assign(paddle.atanh(paddle.to_tensor([ 0.2341, 0.2539])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_1d.md new file mode 100644 index 00000000000..942d83985c7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_1d.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.atleast_1d + +### [torch.atleast_1d](https://pytorch.org/docs/stable/generated/torch.atleast_1d.html#torch-atleast-1d) + +```python +torch.atleast_1d(*tensors) +``` + +### [paddle.atleast_1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_1d_cn.html#atleast_1d) + +```python +paddle.atleast_1d(*inputs, name=None) +``` + +PyTorch 与 Paddle 参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | inputs | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | + +PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 + +### 转写示例 + +#### tensors: 输入为 tuple(Tensor)时 + +```python +# PyTorch 写法 +torch.atleast_1d((x, y)) + +# Paddle 写法 +paddle.atleast_1d(x, y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_2d.md new file mode 100644 index 00000000000..16699cf896a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_2d.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.atleast_2d + +### [torch.atleast_2d](https://pytorch.org/docs/stable/generated/torch.atleast_2d.html#torch-atleast-2d) + +```python +torch.atleast_2d(*tensors) +``` + +### [paddle.atleast_2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_2d_cn.html#atleast_2d) + +```python +paddle.atleast_2d(*inputs, name=None) +``` + +PyTorch 与 Paddle 参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | inputs | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | + +PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 + +### 转写示例 + +#### tensors: 输入为 tuple(Tensor)时 + +```python +# PyTorch 写法 +torch.atleast_2d((x, y)) + +# Paddle 写法 +paddle.atleast_2d(x, y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_3d.md new file mode 100644 index 00000000000..537dfddb743 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.atleast_3d.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ]torch.atleast_3d + +### [torch.atleast_3d](https://pytorch.org/docs/stable/generated/torch.atleast_3d.html#torch-atleast-3d) + +```python +torch.atleast_3d(*tensors) +``` + +### [paddle.atleast_3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/atleast_3d_cn.html#atleast_3d) + +```python +paddle.atleast_3d(*inputs, name=None) +``` + +PyTorch 与 Paddle 参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | inputs | 输入的 Tensor,仅当 torch 输入为 tuple(Tensor)时,两者处理方式不一致,需要转写。其他情形下均一致。 | + +PyTorch 与 Paddle 功能一致,但对于由多个 Tensor 组成 tuple|list 输入的处理方式略有不同,具体请看转写示例。 + +### 转写示例 + +#### tensors: 输入为 tuple(Tensor)时 + +```python +# PyTorch 写法 +torch.atleast_3d((x, y)) + +# Paddle 写法 +paddle.atleast_3d(x, y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.autograd.function.FunctionCtx.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.autograd.function.FunctionCtx.md new file mode 100644 index 00000000000..6d99d734f1b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.autograd.function.FunctionCtx.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.autograd.function.FunctionCtx + +### [torch.autograd.function.FunctionCtx]() + +```python +torch.autograd.function.FunctionCtx +``` + +### [paddle.autograd.PyLayerContext](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayerContext_cn.html#pylayercontext) + +```python +paddle.autograd.PyLayerContext +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.backends.cudnn.version.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.backends.cudnn.version.md new file mode 100644 index 00000000000..cec6db09f14 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.backends.cudnn.version.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.backends.cudnn.version + +### [torch.backends.cudnn.version](https://pytorch.org/docs/stable/generated/torch.backends.cudnn.version.html) + +```python +torch.backends.cudnn.version() +``` + +### [paddle.device.get\_cudnn\_version](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/get_cudnn_version_cn.html#get-cudnn-version) + +```python +paddle.device.get_cudnn_version() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.baddbmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.baddbmm.md new file mode 100644 index 00000000000..c52fb057979 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.baddbmm.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.baddbmm + +### [torch.baddbmm](https://pytorch.org/docs/stable/generated/torch.baddbmm.html?highlight=baddbmm#torch.baddbmm) + +```python +torch.baddbmm(input, batch1, batch2, beta=1, alpha=1, out=None) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.baddbmm(input, batch1, batch2, beta=beta, alpha=alpha) + +# Paddle 写法 +y = beta * input + alpha * paddle.bmm(batch1, batch2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bernoulli.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bernoulli.md new file mode 100644 index 00000000000..7c5e1ed4167 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bernoulli.md @@ -0,0 +1,39 @@ +## [ torch 参数更多 ]torch.bernoulli + +### [torch.bernoulli](https://pytorch.org/docs/stable/generated/torch.bernoulli.html#torch.bernoulli) + +```python +torch.bernoulli(input, + *, + generator=None, + out=None) +``` + +### [paddle.bernoulli](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bernoulli_cn.html) + +```python +paddle.bernoulli(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.bernoulli(torch.tensor([3, 5]), out=y) + +# Paddle 写法 +paddle.assign(paddle.bernoulli(paddle.to_tensor([3, 5])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bincount.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bincount.md new file mode 100644 index 00000000000..204dc11f1ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bincount.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.bincount + +### [torch.bincount](https://pytorch.org/docs/stable/generated/torch.bincount.html?highlight=bincount#torch.bincount) + +```python +torch.bincount(input, + weights=None, + minlength=0) +``` + +### [paddle.bincount](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bincount_cn.html#bincount) + +```python +paddle.bincount(x, + weights=None, + minlength=0, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input| x | 表示输入的 Tensor ,仅参数名不一致。 | +| weights | weights | 表示输入 Tensor 中每个元素的权重。 | +| minlength | minlength | 表示输出 Tensor 的最小长度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_and.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_and.md new file mode 100644 index 00000000000..0a08bf649b8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_and.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.bitwise_and + +### [torch.bitwise_and](https://pytorch.org/docs/stable/generated/torch.bitwise_and.html#torch.bitwise_and) + +```python +torch.bitwise_and(input, + other, + *, + out=None) +``` + +### [paddle.bitwise_and](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_and_cn.html#bitwise-and) + +```python +paddle.bitwise_and(x, + y, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_not.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_not.md new file mode 100644 index 00000000000..8f600d81f6b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_not.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ] torch.bitwise_not + +### [torch.bitwise_not](https://pytorch.org/docs/stable/generated/torch.bitwise_not.html?highlight=bitwise_not#torch.bitwise_not) + +```python +torch.bitwise_not(input, + *, + out=None) +``` + +### [paddle.bitwise_not](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_not_cn.html) + +```python +paddle.bitwise_not(x, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor,参数名一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_or.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_or.md new file mode 100644 index 00000000000..4321096b8b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_or.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.bitwise_or + +### [torch.bitwise_or](https://pytorch.org/docs/stable/generated/torch.bitwise_or.html#torch-bitwise-or) + +```python +torch.bitwise_or(input, + other, + *, + out=None) +``` + +### [paddle.bitwise_or](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_or_cn.html#bitwise-or) + +```python +paddle.bitwise_or(x, + y, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_xor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_xor.md new file mode 100644 index 00000000000..a025bf021c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bitwise_xor.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.bitwise_xor + +### [torch.bitwise_xor](https://pytorch.org/docs/stable/generated/torch.bitwise_xor.html) + +```python +torch.bitwise_xor(input, + other, + *, + out=None) +``` + +### [paddle.bitwise_xor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bitwise_xor_cn.html) + +```python +paddle.bitwise_xor(x, + y, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bmm.md new file mode 100644 index 00000000000..a4a8723ad0d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bmm.md @@ -0,0 +1,35 @@ +## [ torch 参数更多]torch.bmm + +### [torch.bmm](https://pytorch.org/docs/stable/generated/torch.bmm.html?highlight=bmm#torch.bmm) + +```python +torch.bmm(input,mat2,*,out=None) +``` + +### [paddle.bmm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bmm_cn.html) + +```python +paddle.bmm(x,y,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| input | x | 表示输入的第一个 Tensor ,仅参数名不一致。 | +| mat2 | y | 表示输入的第二个 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.bmm(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.bmm(x, y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_shapes.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_shapes.md new file mode 100644 index 00000000000..a0d1bb249a3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_shapes.md @@ -0,0 +1,33 @@ +## [参数不一致]torch.broadcast_shapes + +### [torch.broadcast_shapes](https://pytorch.org/docs/stable/generated/torch.broadcast_shapes.html#torch.broadcast_shapes) + +```python +torch.broadcast_shapes(*shapes) +``` + +### [paddle.broadcast_shape](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/broadcast_shape_cn.html) + +```python +paddle.broadcast_shape(x_shape, y_shape) +``` + +其中功能一致, 参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ---------------- | --------------------------------------------------------------------------------------------------------- | +| \*shapes | x_shape, y_shape | 输入 Tensor 的 shape,输入参数数量不一致,PyTorch 可以输入多项,Paddle 输入为两项,需要多次调用进行转写。 | + +### 转写示例 + +#### shapes 参数:输入 Tensor 的 shape + +```python +# PyTorch 写法: +torch.broadcast_shapes(x1, x2, x3) + +# Paddle 写法: +paddle.broadcast_shape(paddle.broadcast_shape(x1, x2), x3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_tensors.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_tensors.md new file mode 100644 index 00000000000..1ba96d447df --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_tensors.md @@ -0,0 +1,32 @@ +## [ 参数不一致 ]torch.broadcast_tensors + +### [torch.broadcast_tensors](https://pytorch.org/docs/stable/generated/torch.broadcast_tensors.html?highlight=broadcast_tensors#torch.broadcast_tensors) + +```python +torch.broadcast_tensors(*tensors) +``` + +### [paddle.broadcast_tensors](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/broadcast_tensors_cn.html#broadcast-tensors) + +```python +paddle.broadcast_tensors(inputs, + name=None) +``` + +两者功能一致但参数类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *tensors | inputs | 一组输入 Tensor , PyTorch 参数 tensors 为可变参, Paddle 参数 inputs 为 list(Tensor) 或 tuple(Tensor) 的形式。 | + + +### 转写示例 +#### *tensors: 一组输入 Tensor +```python +# PyTorch 写法 +torch.broadcast_tensors(x, y) + +# Paddle 写法 +paddle.broadcast_tensors([x, y]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_to.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_to.md new file mode 100644 index 00000000000..447dc65883f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.broadcast_to.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.broadcast_to + +### [torch.broadcast_to](https://pytorch.org/docs/stable/generated/torch.broadcast_to.html?highlight=broadcast_to#torch.broadcast_to) + +```python +torch.broadcast_to(input, + shape) +``` + +### [paddle.broadcast_to](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/broadcast_to_cn.html#broadcast-to) + +```python +paddle.broadcast_to(x, + shape, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input| x | 表示输入的 Tensor ,仅参数名不一致。 | +| shape | shape | 表示扩展后 Tensor 的 shape 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bucketize.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bucketize.md new file mode 100644 index 00000000000..b9d018fbce3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.bucketize.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ] torch.bucketize +### [torch.bucketize](https://pytorch.org/docs/stable/generated/torch.bucketize.html#torch.bucketize) + +```python +torch.bucketize(input, boundaries, *, out_int32=False, right=False, out=None) +``` + +### [paddle.bucketize](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/bucketize_cn.html#paddle-bucketize) + +```python +paddle.bucketize(x, sorted_sequence, out_int32=False, right=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input| x | 表示输入的 Tensor ,仅参数名不一致。 | +| boundaries| sorted_sequence | 数据的边界,仅参数名不一致。 | +| out_int32| out_int32 | 输出的数据类型是否为 int32。 | +| right| right | 根据给定输入在 sorted_sequence 查找对应的上边界或下边界。 | +| out | - | 表示输出的 Tensor, Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.bucketize(x, boundaries, out=y) + +# Paddle 写法 +paddle.assign(paddle.bucketize(x, boundaries), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cat.md new file mode 100644 index 00000000000..9ec55b7e3e9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cat.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.cat +### [torch.cat](https://pytorch.org/docs/stable/generated/torch.cat.html?highlight=cat#torch.cat) + +```python +torch.cat(input, + *, + out=None) +``` + +### [paddle.concat](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/concat_cn.html#concat) + +```python +paddle.concat(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input| x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cat([x, y], out=y) + +# Paddle 写法 +paddle.assign(paddle.concat([x, y]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cdist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cdist.md new file mode 100644 index 00000000000..b33e72c7099 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cdist.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.cdist + +### [torch.cdist](https://pytorch.org/docs/stable/generated/torch.cdist.html#torch.cdist) + +```python +torch.cdist(x1, x2, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary') +``` + +### [paddle.cdist](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cdist_cn.html#cdist) + +```python +paddle.cdist(x, y, p=2.0, compute_mode='use_mm_for_euclid_dist_if_necessary', name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| x1 | x | 表示第一个输入的 Tensor ,仅参数名不一致。 | +| x2 | y | 表示第二个输入的 Tensor ,仅参数名不一致。 | +| p | p | 计算每个向量对之间的 p 范数距离的值。默认值为 2.0 | +| compute_mode | compute_mode |表示计算模式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ceil.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ceil.md new file mode 100644 index 00000000000..012434f13e6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ceil.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.ceil + +### [torch.ceil](https://pytorch.org/docs/stable/generated/torch.ceil.html#torch.ceil) + +```python +torch.ceil(input, + *, + out=None) +``` + +### [paddle.ceil](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/ceil_cn.html) + +```python +paddle.ceil(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的结果 Tensor,Paddle 无此参数,需要转写。| + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.ceil(torch.tensor([-0.6341, -1.4208]), out=y) + +# Paddle 写法 +paddle.assign(paddle.ceil(paddle.to_tensor([-0.6341, -1.4208])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.celu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.celu.md new file mode 100644 index 00000000000..18569825838 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.celu.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.celu + +### [torch.celu](https://pytorch.org/docs/stable/generated/torch.nn.functional.celu.html#torch.nn.functional.celu) + +```python +torch.celu(input, alpha=1.0) +``` + +### [paddle.nn.functional.celu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/celu_cn.html#celu) + +```python +paddle.nn.functional.celu(x, alpha=1.0, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| alpha | alpha | CELU 的 alpha 值,默认值为 1.0。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chain_matmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chain_matmul.md new file mode 100644 index 00000000000..597a5d120bf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chain_matmul.md @@ -0,0 +1,17 @@ +## [ 组合替代实现 ]torch.chain_matmul + +### [torch.chain_matmul](https://pytorch.org/docs/stable/generated/torch.chain_matmul.html?highlight=chain_matmul#torch.chain_matmul) +```python +torch.chain_matmul(*matrices, out=None) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.chain_matmul(a, b, c) + +# Paddle 写法 +y = a @ b @ c +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky.md new file mode 100644 index 00000000000..d5ed69506f4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.cholesky + +### [torch.cholesky](https://pytorch.org/docs/stable/generated/torch.cholesky.html?highlight=cholesky#torch.cholesky) + +```python +torch.cholesky(input,upper=False,*,out=None) +``` + +### [paddle.linalg.cholesky](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cholesky_cn.html) + +```python +paddle.linalg.cholesky(x,upper=False,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| input | x | 表示输入参数为多维 Tensor ,它的维度应该为 [*, M, N],其中*为零或更大的批次尺寸,并且最里面的两个维度上的矩阵都应为对称的正定矩阵,仅参数名不一致。 | +| upper | upper | 表示是否返回上三角矩阵或下三角矩阵。 | +| out | - | 表示输出的 Tensor, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:输出的 Tensor + +```python +# PyTorch 写法 +torch.cholesky(x, upper=False, out=output) + + +# Paddle 写法 +paddle.assign(paddle.linalg.cholesky(x, upper=False), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_inverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_inverse.md new file mode 100644 index 00000000000..62abd7135cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_inverse.md @@ -0,0 +1,28 @@ +## [ 组合替代实现 ]torch.cholesky_inverse +### [torch.cholesky_inverse](https://pytorch.org/docs/stable/generated/torch.cholesky_inverse.html?highlight=cholesky_inverse#torch.cholesky_inverse) +```python +torch.cholesky_inverse(input, upper=False, out=None) +``` + +### 功能介绍 +用于计算对称正定矩阵的逆矩阵,公式为: +> 当`upper`为 False 时, +> $inv=(uu^T)^{-1}$ ; +> 当`upper`为 True 时, +> $inv=(u^Tu)^{-1}$ 。 + + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +```python +import paddle + +def cholesky_inverse(input, upper=False, out=None) : + u = paddle.cholesky(input, False) + ut = paddle.transpose(u, perm=[1, 0]) + if upper: + out = paddle.inverse(paddle.matmul(ut, u)) + else: + out = paddle.inverse(paddle.matmul(u, ut)) + return out +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_solve.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_solve.md new file mode 100644 index 00000000000..cf97679b907 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cholesky_solve.md @@ -0,0 +1,23 @@ +## [仅参数名不一致]torch.cholesky_solve + +### [torch.cholesky_solve](https://pytorch.org/docs/stable/generated/torch.cholesky_solve.html?highlight=cholesky#torch.cholesky_solve) + +```python +torch.cholesky_solve(input, input2, upper=False, *, out=None) +``` + +### [paddle.linalg.cholesky_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cholesky_solve_cn.html#cholesky-solve) + +```python +paddle.linalg.cholesky_solve(x, y, upper=False, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下:: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------------------------------------- | +| input | x | 表示线性方程中的 B 矩阵。仅参数名不一致 | +| input2 | y | 表示线性方程中 A 矩阵的 Cholesky 分解矩阵 u。仅参数名不一致 | +| upper | upper | 表示输入 x 是否是上三角矩阵,True 为上三角矩阵,False 为下三角矩阵。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chunk.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chunk.md new file mode 100644 index 00000000000..69ac5214d5b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.chunk.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.chunk +### [torch.chunk](https://pytorch.org/docs/stable/generated/torch.chunk.html?highlight=chunk#torch.chunk) + +```python +torch.chunk(input, + chunks, + dim=0) +``` + +### [paddle.chunk](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/chunk_cn.html#chunk) + +```python +paddle.chunk(x, + chunks, + axis=0, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| chunks | chunks | 表示将输入 Tensor 划分成多少个相同大小的子 Tensor。 | +| dim | axis |表示需要分割的维度 ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp.md new file mode 100644 index 00000000000..afedaf16dbe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ]torch.clamp +### [torch.clamp](https://pytorch.org/docs/stable/generated/torch.clamp.html#torch-clamp) + +```python +torch.clamp(input, + min=None, + max=None, + *, + out=None) +``` + +### [paddle.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/clip_cn.html#clip) + +```python +paddle.clip(x, + min=None, + max=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| min | min | 表示裁剪的最小值。 | +| max | max | 表示裁剪的最大值。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.clamp(torch.tensor([-1.7120, 0.1734]), min=-0.5, max=0.5, out=y) + +# Paddle 写法 +paddle.assign(paddle.clip(paddle.to_tensor([-1.7120, 0.1734]), min=-0.5, max=0.5), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_max.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_max.md new file mode 100644 index 00000000000..9fd7f9b07f9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_max.md @@ -0,0 +1,39 @@ +## [ torch 参数更多 ]torch.clamp_max +### [torch.clamp_max]() + +```python +torch.clamp_max(input, + max=None, + *, + out=None) +``` + +### [paddle.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/clip_cn.html#clip) + +```python +paddle.clip(x, + min=None, + max=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | min | 表示裁剪的最小值。PyTorch 无此参数, Paddle 保持默认即可。 | +| max | max | 表示裁剪的最大值。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.clamp_max(input, max=0.5, out=y) + +# Paddle 写法 +paddle.assign(paddle.clip(input, max=0.5), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_min.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_min.md new file mode 100644 index 00000000000..ec4594608b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clamp_min.md @@ -0,0 +1,39 @@ +## [ torch 参数更多 ]torch.clamp_min +### [torch.clamp_min]() + +```python +torch.clamp_min(input, + min=None, + *, + out=None) +``` + +### [paddle.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/clip_cn.html#clip) + +```python +paddle.clip(x, + min=None, + max=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| min | min | 表示裁剪的最小值。 | +| - | max | 表示裁剪的最大值。PyTorch 无此参数, Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.clamp_min(input, min=-0.5, out=y) + +# Paddle 写法 +paddle.assign(paddle.clip(input, min=-0.5), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clip.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clip.md new file mode 100644 index 00000000000..993ab3ed2e2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clip.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ]torch.clip +### [torch.clip](https://pytorch.org/docs/stable/generated/torch.clip.html#torch.clip) + +```python +torch.clip(input, + min=None, + max=None, + *, + out=None) +``` + +### [paddle.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/clip_cn.html#clip) + +```python +paddle.clip(x, + min=None, + max=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input| | x | 表示输入的 Tensor,仅参数名不一致。 | +| min | min | 表示裁剪的最小值。 | +| max | max | 表示裁剪的最大值。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.clip(torch.tensor([-1.7120, 0.1734]), min=-0.5, max=0.5, out=y) + +# Paddle 写法 +paddle.assign(paddle.clip(paddle.to_tensor([-1.7120, 0.1734]), min=-0.5, max=0.5), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clone.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clone.md new file mode 100644 index 00000000000..2001d177b65 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.clone.md @@ -0,0 +1,25 @@ +## [torch 参数更多 ]torch.clone + +### [torch.clone](https://pytorch.org/docs/stable/generated/torch.clone.html?highlight=clone#torch.clone) + +```python +torch.clone(input, + *, + memory_format=torch.preserve_format) +``` + +### [paddle.clone](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/clone_cn.html#clone) + +```python +paddle.clone(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| memory_format | - | 返回张量的所需内存格式,默认为 torch.preserve_format 。Paddle 无此参数,一般对训练结果影响不大,直接删除即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.column_stack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.column_stack.md new file mode 100644 index 00000000000..777c2f06c2d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.column_stack.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ]torch.column_stack + +### [torch.column_stack](https://pytorch.org/docs/stable/generated/torch.column_stack.html#torch.column_stack) + +```python +torch.column_stack(tensors, *, out=None) +``` + +### [paddle.column_stack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/column_stack_cn.html) + +```python +paddle.column_stack(x, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.combinations.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.combinations.md new file mode 100644 index 00000000000..ac28fe92a25 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.combinations.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.combinations + +### [torch.combinations](https://pytorch.org/docs/stable/generated/torch.combinations.html#torch.combinations) + +```python +torch.combinations(input, r=2, with_replacement=False) +``` + +### [paddle.combinations](https://github.com/PaddlePaddle/Paddle/blob/8932f1c5e26788ab1eed226e70fafb1ea67ce737/python/paddle/tensor/math.py#L7099) + +```python +paddle.combinations(x, r=2, with_replacement=False, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------------- | ---------------- | ----------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| r | r | 需要合并元素数量。 | +| with_replacement | with_replacement | 是否允许合并中替换。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.complex.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.complex.md new file mode 100644 index 00000000000..2e749ab152a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.complex.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.complex + + +### [torch.complex](https://pytorch.org/docs/stable/generated/torch.complex.html) + +```python +torch.complex(real, imag, *, out=None) +``` + +### [paddle.complex](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/complex_cn.html#complex) + +```python +paddle.complex(real, imag, name=None) +``` + +其中,PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| real | real | 实部,数据类型为:float32 或 float64。 | +| imag | imag | 虚部,数据类型和 real 相同。 | +| out | - | 输出 Tensor。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.complex(a, b, out=out) + +# Paddle 写法 +paddle.assign(paddle.complex(a, b), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.concat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.concat.md new file mode 100644 index 00000000000..a74ac9c5ed4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.concat.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.concat + +### [torch.concat](https://pytorch.org/docs/stable/generated/torch.concat.html#torch.concat) + +```python +torch.concat(tensors, dim=0, *, out=None) +``` + +### [paddle.concat](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/concat_cn.html) + +```python +paddle.concat(x, axis=0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------- | +| tensors | x | 待联结的 Tensor list 或者 Tensor tuple,仅参数名不一致。 | +| dim | axis | 指定对输入 x 进行运算的轴,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.concat(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.concat(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj.md new file mode 100644 index 00000000000..0a0b33ca757 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj.md @@ -0,0 +1,20 @@ +## [仅参数名不一致]torch.conj +### [torch.conj](https://pytorch.org/docs/stable/generated/torch.conj.html?highlight=conj#torch.conj) + +```python +torch.conj(input) +``` + +### [paddle.conj](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/conj_cn.html#conj) + +```python +paddle.conj(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj_physical.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj_physical.md new file mode 100644 index 00000000000..9f0f39ee680 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.conj_physical.md @@ -0,0 +1,30 @@ +## [ torch 参数更多]torch.conj_physical +### [torch.conj_physical](https://pytorch.org/docs/stable/generated/torch.conj_physical.html#torch.conj_physical) + +```python +torch.conj_physical(input, *, out=None) +``` + +### [paddle.conj](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/conj_cn.html#conj) + +```python +paddle.conj(x, + name=None) +``` + +PyTorch 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,paddle 无此参数, 需要转写。 | + +#### out:指定输出 +```python +# PyTorch 写法 +torch.conj_physical(input, out=out) + +# Paddle 写法 +paddle.assign(paddle.conj(input), output=out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.copysign.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.copysign.md new file mode 100644 index 00000000000..95b4805020d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.copysign.md @@ -0,0 +1,24 @@ +## [ 组合替代实现 ]torch.copysign + +### [torch.copysign](https://pytorch.org/docs/stable/generated/torch.copysign.html#torch.copysign) + +```python +torch.copysign(input, + other, + *, + out=None) +``` +创建一个新的浮点张量,其大小与` input `相同,正负符号与` other `相同 + +PaddlePaddle 目前无对应 API,可使用如下代码组合替代实现: + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.copysign(input, other, out=y) + +# Paddle 写法 +paddle.assign(paddle.abs(input) * paddle.sign(other), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.corrcoef.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.corrcoef.md new file mode 100644 index 00000000000..569c65d91bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.corrcoef.md @@ -0,0 +1,22 @@ +## [仅参数名不一致]torch.corrcoef +### [torch.corrcoef](https://pytorch.org/docs/stable/generated/torch.corrcoef.html?highlight=corrcoef#torch.corrcoef) + +```python +torch.corrcoef(input) +``` + +### [paddle.linalg.corrcoef](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/corrcoef_cn.html#corrcoef) + +```python +paddle.linalg.corrcoef(x, + rowvar=True, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 一个 N(N<=2) 维矩阵,包含多个变量。默认矩阵的每行是一个观测变量,由参数 rowvar 设置。 | +| - | rowvar | 以行或列作为一个观测变量, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cos.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cos.md new file mode 100644 index 00000000000..d8ab7b7caf3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cos.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.cos +### [torch.cos](https://pytorch.org/docs/stable/generated/torch.cos.html#torch-cos) + +```python +torch.cos(input, + *, + out=None) +``` + +### [paddle.cos](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cos_cn.html#cos) + +```python +paddle.cos(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cos(torch.tensor([1.4309, 1.2706]), out=y) + +# Paddle 写法 +paddle.assign(paddle.cos(paddle.to_tensor([1.4309, 1.2706])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosh.md new file mode 100644 index 00000000000..84cb7000349 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosh.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.cosh +### [torch.cosh](https://pytorch.org/docs/stable/generated/torch.cosh.html#torch.cosh) + +```python +torch.cosh(input, + *, + out=None) +``` + +### [paddle.cosh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cosh_cn.html#cosh) + +```python +paddle.cosh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cosh(torch.tensor([0.1632, 1.1835]), out=y) + +# Paddle 写法 +paddle.assign(paddle.cosh(paddle.to_tensor([0.1632, 1.1835])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosine_similarity.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosine_similarity.md new file mode 100644 index 00000000000..cf334122a72 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cosine_similarity.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.cosine_similarity +### [torch.cosine_similarity](https://pytorch.org/docs/stable/generated/torch.nn.functional.cosine_similarity.html?highlight=cosine_similarity#torch.nn.functional.cosine_similarity) + +```python +torch.cosine_similarity(x1, x2, dim=1, eps=1e-8) +``` + +### [paddle.nn.functional.cosine_similarity](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/cosine_similarity_cn.html#cosine-similarity) + +```python +paddle.nn.functional.cosine_similarity(x1, x2, axis=1, eps=1e-8) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| x1 | x1 | 表示第一个输入的 Tensor 。 | +| x2 | x2 | 表示第二个输入的 Tensor 。 | +| dim | axis | 表示计算的维度,仅参数名不一致。 | +| eps | eps | 表示加到分母上的超参数 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.count_nonzero.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.count_nonzero.md new file mode 100644 index 00000000000..c00b583ceb1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.count_nonzero.md @@ -0,0 +1,25 @@ +## [仅 paddle 参数更多]torch.count_nonzero +### [torch.count_nonzero](https://pytorch.org/docs/stable/generated/torch.count_nonzero.html?highlight=count_nonzero#torch.count_nonzero) + +```python +torch.count_nonzero(input, dim=None) +``` + +### [paddle.count_nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/count_nonzero_cn.html#count-nonzero) + +```python +paddle.count_nonzero(x, + axis=None, + keepdim=False, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| - | keepdim | 是否在输出 Tensor 中保留减小的维度, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cov.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cov.md new file mode 100644 index 00000000000..26ac533e75c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cov.md @@ -0,0 +1,31 @@ +## [ 仅 paddle 参数更多 ]torch.cov +### [torch.cov](https://pytorch.org/docs/stable/generated/torch.cov.html?highlight=cov#torch.cov) + +```python +torch.cov(input, + correction=1, + fweights=None, + aweights=None) +``` + +### [paddle.linalg.cov](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/cov_cn.html#cov) + +```python +paddle.linalg.cov(x, + rowvar=True, + ddof=True, + fweights=None, + aweights=None, + name=None) +``` + +仅 paddle 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor 。 | +| correction | ddof | 样本量和样本自由度之间的差异, 若为 True ,返回无偏估计结果;若为 False ,返回普通平均值计算结果。| +| fweights | fweights | 表示每一个观测向量的重复次数。 | +| aweights | aweights | 表示每一个观测向量的重要性。 | +| - | rowvar | 以行或列作为一个观测变量, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cross.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cross.md new file mode 100644 index 00000000000..d899de4fde6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cross.md @@ -0,0 +1,42 @@ +## [torch 参数更多 ]torch.cross + +### [torch.cross](https://pytorch.org/docs/stable/generated/torch.cross.html?highlight=cross#torch.cross) + +```python +torch.cross(input, + other, + dim=None, + *, + out=None) +``` + +### [paddle.cross](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cross_cn.html#cross) + +```python +paddle.cross(x, + y, + axis=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 沿着此维进行向量积操作,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cross(input, other, dim=1, out=y) + +# Paddle 写法 +paddle.assign(paddle.cross(input, other, axis=1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummax.md new file mode 100644 index 00000000000..eaec3b541ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummax.md @@ -0,0 +1,41 @@ +## [ torch 参数更多 ]torch.cummax + +### [torch.cummax](https://pytorch.org/docs/stable/generated/torch.cummax.html?highlight=cummax#torch.cummax) + +```python +torch.cummax(input, + dim, + *, + out=None) +``` + +### [paddle.cummax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cummax_cn.html#cummax) + +```python +paddle.cummax(x, + axis=None, + dtype='int64', + name=None) +``` + +两者功能一致,torch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| dim | axis | 用于指定 index 获取输入的维度,仅参数名不一致。 | +| - | dtype | 指定输出索引的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 + +```python +# PyTorch 写法 +torch.cummax(x,1, out=(values, indices)) + +# Paddle 写法 +paddle.assign(paddle.cummax(x,1), (values, indices)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummin.md new file mode 100644 index 00000000000..0542cb71299 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cummin.md @@ -0,0 +1,41 @@ +## [ torch 参数更多 ]torch.cummin + +### [torch.cummin](https://pytorch.org/docs/stable/generated/torch.cummin.html) + +```python +torch.cummin(input, + dim, + *, + out=None) +``` + +### [paddle.cummin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cummin_cn.html) + +```python +paddle.cummin(x, + axis=None, + dtype='int64', + name=None) +``` + +两者功能一致,torch 参数更多,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| dim | axis | 用于指定 index 获取输入的维度,仅参数名不一致。 | +| - | dtype | 指定输出索引的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 + +```python +# PyTorch 写法 +torch.cummin(x,1, out=(values, indices)) + +# Paddle 写法 +paddle.assign(paddle.cummin(x,1), (values, indices)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumprod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumprod.md new file mode 100644 index 00000000000..915e24c0649 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumprod.md @@ -0,0 +1,42 @@ +## [torch 参数更多 ]torch.cumprod + +### [torch.cumprod](https://pytorch.org/docs/stable/generated/torch.cumprod.html?highlight=cumprod#torch.cumprod) + +```python +torch.cumprod(input, + dim, + *, + dtype=None, + out=None) +``` + +### [paddle.cumprod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cumprod_cn.html#cumprod) + +```python +paddle.cumprod(x, + dim=None, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------| +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | dim | 指明需要累乘的维度,参数名相同。 | +| dtype | dtype | 输出 Tensor 的数据类型,如果指定了,那么在执行操作之前,输入的 Tensor 将被转换为 dtype 类型,这对防止数据类型溢出非常有用,默认为 None,参数名相同。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cumprod(input, dim=1, dtype='float64', out=y) + +# Paddle 写法 +paddle.assign(paddle.cumprod(input, dim=1, dtype='float64'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumsum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumsum.md new file mode 100644 index 00000000000..1f20d5cef23 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumsum.md @@ -0,0 +1,42 @@ +## [torch 参数更多 ]torch.cumsum + +### [torch.cumsum](https://pytorch.org/docs/stable/generated/torch.cumsum.html?highlight=cumsum#torch.cumsum) + +```python +torch.cumsum(input, + dim, + *, + dtype=None, + out=None) +``` + +### [paddle.cumsum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cumsum_cn.html#cumsum) + +```python +paddle.cumsum(x, + axis=None, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 指明需要累加的维度,仅参数名不一致。 | +| dtype | dtype | 输出 Tensor 的数据类型,默认为 None,参数名相同。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.cumsum(input, dim=-1, dtype='float64', out=y) + +# Paddle 写法 +paddle.assign(paddle.cumsum(input, dim=-1, dtype='float64'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumulative_trapezoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumulative_trapezoid.md new file mode 100644 index 00000000000..4c2010fe658 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.cumulative_trapezoid.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.cumulative_trapezoid + +### [torch.cumulative_trapezoid](https://pytorch.org/docs/stable/generated/torch.cumulative_trapezoid.html#torch.cumulative_trapezoid) + +```python +torch.cumulative_trapezoid(y, x=None, *, dx=None, dim=-1) +``` + +### [paddle.cumulative_trapezoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cumulative_trapezoid_cn.html) + +```python +paddle.cumulative_trapezoid(y, x=None, dx=None, axis=-1, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------- | +| y | y | 输入多维 Tensor。 | +| x | x | y 中数值对应的浮点数所组成的 Tensor。 | +| dx | dx | 相邻采样点之间的常数间隔。 | +| dim | axis | 计算 trapezoid rule 时 y 的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.deg2rad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.deg2rad.md new file mode 100644 index 00000000000..82a15bb8ff9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.deg2rad.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.deg2rad +### [torch.deg2rad](https://pytorch.org/docs/stable/generated/torch.deg2rad.html#torch-deg2rad) + +```python +torch.deg2rad(input, + *, + out=None) +``` + +### [paddle.deg2rad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/deg2rad_cn.html#paddle.deg2rad) + +```python +paddle.deg2rad(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +a = torch.tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]]) +torch.deg2rad(a, out=y) + +# Paddle 写法 +a = paddle.to_tensor([[180.0, -180.0], [360.0, -360.0], [90.0, -90.0]]) +paddle.assign(paddle.deg2rad(a), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.det.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.det.md new file mode 100644 index 00000000000..a9552a7db5b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.det.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.det +### [torch.det](https://pytorch.org/docs/stable/generated/torch.det.html?highlight=det#torch.det) + +```python +torch.det(input) +``` + +### [paddle.linalg.det](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/det_cn.html#det) + +```python +paddle.linalg.det(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.device.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.device.md new file mode 100644 index 00000000000..f84adb5e303 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.device.md @@ -0,0 +1,26 @@ +## [ 组合替代实现 ]torch.device + +### [torch.device](https://pytorch.org/docs/stable/tensor_attributes.html#torch-device) + +```python +torch.device(type, index) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.device('cuda', 0) + +# Paddle 写法 +'gpu:0' + + +# PyTorch 写法 +torch.device('cpu') + +# Paddle 写法 +'cpu' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diag.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diag.md new file mode 100644 index 00000000000..a46de2b69ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diag.md @@ -0,0 +1,39 @@ +## [torch 参数更多 ]torch.diag +### [torch.diag](https://pytorch.org/docs/stable/generated/torch.diag.html?highlight=diag#torch.diag) + +```python +torch.diag(input, + diagonal=0, + *, + out=None) +``` + +### [paddle.diag](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diag_cn.html) + +```python +paddle.diag(x, + offset=0, + padding_value=0, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| diagonal | offset | 对角线偏移量。正值表示上对角线,0 表示主对角线,负值表示下对角线。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| - | padding_value | 表示填充指定对角线以外的区域, PyTorch 无此参数, Paddle 保持默认即可 。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.diag(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.diag(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagflat.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagflat.md new file mode 100644 index 00000000000..8faa700bfa4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagflat.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.diagflat +### [torch.diagflat](https://pytorch.org/docs/stable/generated/torch.diagflat.html?highlight=diagflat#torch.diagflat) + +```python +torch.diagflat(input, + offset=0) +``` + +### [paddle.diagflat](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diagflat_cn.html#diagflat) + +```python +paddle.diagflat(x, + offset=0, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| offset | offset | 表示对角线偏移量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal.md new file mode 100644 index 00000000000..ce639ad1b07 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.diagonal +### [torch.diagonal](https://pytorch.org/docs/stable/generated/torch.diagonal.html?highlight=diagonal#torch.diagonal) + +```python +torch.diagonal(input, + offset=0, + dim1=0, + dim2=1)) +``` + +### [paddle.diagonal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diagonal_cn.html#diagonal) + +```python +paddle.diagonal(x, + offset=0, + axis1=0, + axis2=1, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| offset | offset | 表示对角线偏移量。 | +| dim1 | axis1 | 获取对角线的二维平面的第一维,仅参数名不一致。 | +| dim2 | axis2 | 获取对角线的二维平面的第二维,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal_scatter.md new file mode 100644 index 00000000000..f3c8a0d3879 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diagonal_scatter.md @@ -0,0 +1,33 @@ +## [ 仅参数名不一致 ] torch.diagonal_scatter + +### [torch.diagonal_scatter](https://pytorch.org/docs/stable/generated/torch.diagonal_scatter.html?highlight=diagonal_scatter#torch.diagonal_scatter) + +```python +torch.diagonal_scatter(input, + src, + offset=0, + dim1=0, + dim2=1) +``` + +### [paddle.diagonal_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diagonal_scatter_cn.html) + +```python +paddle.diagonal_scatter(x, + y, + offset=0, + axis1=0, + axis2=1) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| input | x | 输入张量,被嵌入的张量,仅参数名不一致。 | +| src | y | 用于嵌入的张量,仅参数名不一致。 | +| offset | offset | 从指定的二维平面嵌入对角线的位置,默认值为 0,即主对角线。 | +| dim1 | axis1 | 对角线的第一个维度,默认值为 0,仅参数名不一致。 | +| dim2 | axis2 | 对角线的第二个维度,默认值为 1,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diff.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diff.md new file mode 100644 index 00000000000..7fdbcfdbadf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.diff.md @@ -0,0 +1,33 @@ +## [ 参数不一致 ]torch.diff +### [torch.diff](https://pytorch.org/docs/stable/generated/torch.diff.html?highlight=diff#torch.diff) + +```python +torch.diff(input, + n=1, + dim=-1, + prepend=None, + append=None) +``` + +### [paddle.diff](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/diff_cn.html#diff) + +```python +paddle.diff(x, + n=1, + axis=-1, + prepend=None, + append=None, + name=None) +``` + +两者功能一致,但参数 `n` 的支持范围不同,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| n | n | 表示需要计算前向差值的次数。torch 支持 n 为任意值,paddle 仅支持 n=1,暂无转写方式。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| prepend | prepend | 表示在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的前面。 | +| append | append | 表示在计算前向差值之前,沿着指定维度 axis 附加到输入 x 的后面。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.digamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.digamma.md new file mode 100644 index 00000000000..bf00bb1fb61 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.digamma.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ]torch.digamma +### [torch.digamma](https://pytorch.org/docs/stable/generated/torch.digamma.html?highlight=torch+digamma#torch.digamma) +```python +torch.digamma(input, + *, + out=None) +``` + +### [paddle.digamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/digamma_cn.html) +```python +paddle.digamma(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.digamma(torch.tensor([[1, 1.5], [0, -2.2]]), out=y) + +# Paddle 写法 +paddle.assign(paddle.digamma(paddle.to_tensor([[1, 1.5], [0, -2.2]], dtype='float32')), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dist.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dist.md new file mode 100644 index 00000000000..885727efd85 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dist.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.dist +### [torch.dist](https://pytorch.org/docs/stable/generated/torch.dist.html?highlight=dist#torch.dist) + +```python +torch.dist(input, + other, + p=2) +``` + +### [paddle.dist](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/dist_cn.html#dist) + +```python +paddle.dist(x, + y, + p=2) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| p | p | 表示需要计算的范数 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MAX.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MAX.md new file mode 100644 index 00000000000..514964ddb35 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MAX.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.distributed.ReduceOp.MAX + +### [torch.distributed.ReduceOp.MAX](https://pytorch.org/docs/stable/distributed.html#torch.distributed.ReduceOp) + +```python +torch.distributed.ReduceOp.MAX +``` + +### [paddle.distributed.ReduceOp.MAX](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/ReduceOp_cn.html#reduceop) + +```python +paddle.distributed.ReduceOp.MAX +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MIN.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MIN.md new file mode 100644 index 00000000000..826a39a8d10 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.MIN.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.distributed.ReduceOp.MIN + +### [torch.distributed.ReduceOp.MIN](https://pytorch.org/docs/stable/distributed.html#torch.distributed.ReduceOp) + +```python +torch.distributed.ReduceOp.MIN +``` + +### [paddle.distributed.ReduceOp.MIN](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/ReduceOp_cn.html#reduceop) + +```python +paddle.distributed.ReduceOp.MIN +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.PRODUCT.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.PRODUCT.md new file mode 100644 index 00000000000..db9ec75ecf0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.PRODUCT.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.distributed.ReduceOp.PRODUCT + +### [torch.distributed.ReduceOp.PRODUCT](https://pytorch.org/docs/stable/distributed.html#torch.distributed.ReduceOp) + +```python +torch.distributed.ReduceOp.PRODUCT +``` + +### [paddle.distributed.ReduceOp.PROD](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/ReduceOp_cn.html#reduceop) + +```python +paddle.distributed.ReduceOp.PROD +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.SUM.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.SUM.md new file mode 100644 index 00000000000..8abdf62b256 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.distributed.ReduceOp.SUM.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.distributed.ReduceOp.SUM + +### [torch.distributed.ReduceOp.SUM](https://pytorch.org/docs/stable/distributed.html#torch.distributed.ReduceOp) + +```python +torch.distributed.ReduceOp.SUM +``` + +### [paddle.distributed.ReduceOp.SUM](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/ReduceOp_cn.html#reduceop) + +```python +paddle.distributed.ReduceOp.SUM +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.div.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.div.md new file mode 100644 index 00000000000..2b9088273a4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.div.md @@ -0,0 +1,62 @@ +## [ torch 参数更多 ]torch.div +### [torch.div](https://pytorch.org/docs/stable/generated/torch.div.html#torch.div) +```python +torch.div(input, + other, + *, + rounding_mode=None, + out=None) +``` + +### [paddle.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/divide_cn.html) +```python +paddle.divide(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| other | y | 表示输入的 Tensor,仅参数名不一致。 | +| rounding_mode | - | 表示舍入模式,Paddle 无此参数, 需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### rounding_mode: 舍入模式 +```python +# PyTorch 写法 (rounding_mode 参数设置为 None) +x = torch.div(torch.tensor([2, 3, 4]), torch.tensor([1, 5, 2])) + +# Paddle 写法 +a = paddle.to_tensor([2, 3, 4], dtype='float64') +b = paddle.to_tensor([1, 5, 2], dtype='float64') +x = paddle.divide(a, b) + +# PyTorch 写法 (rounding_mode 参数设置为"trunc") +x = torch.div(torch.tensor([-0.3711, -1.9353]), torch.tensor([0.8032, 0.2930]), rounding_mode='trunc') + +# Paddle 写法 +x = paddle.divide(paddle.to_tensor([-0.3711, -1.9353]), paddle.to_tensor([0.8032, 0.2930])) +x = paddle.trunc(x) + +# PyTorch 写法 (rounding_mode 参数设置为"floor") +x = torch.div(torch.tensor([-0.3711, -1.9353]), torch.tensor([0.8032, 0.2930]), rounding_mode='floor') + +# Paddle 写法 +x = paddle.divide(paddle.to_tensor([-0.3711, -1.9353]), paddle.to_tensor([0.8032, 0.2930])) +x = paddle.floor(x) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.div(torch.tensor([2, 3, 4]), torch.tensor([1, 5, 2]), out=y) + +# Paddle 写法 +paddle.assign(paddle.divide(paddle.to_tensor([2, 3, 4]), paddle.to_tensor([1, 5, 2])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.divide.md new file mode 100644 index 00000000000..9e7f4f08b55 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.divide.md @@ -0,0 +1,54 @@ +## [ torch 参数更多 ]torch.divide +### [torch.divide](https://pytorch.org/docs/stable/generated/torch.divide.html?highlight=torch+divide#torch.divide) +```python +torch.divide(input, + other, + *, + rounding_mode=None, + out=None) +``` + +### [paddle.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/divide_cn.html) +```python +paddle.divide(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rounding_mode | - | 表示舍入模式,Paddle 无此参数, 需要转写。Paddle 可通过组合 paddle.trunc 或 paddle.floor 实现。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### rounding_mode: 舍入模式 +```python +# PyTorch 写法 (rounding_mode 参数设置为"trunc") +x = torch.divide(torch.tensor([2, 3, 4]), torch.tensor([1, 5, 2]), rounding_mode='trunc') + +# Paddle 写法 +x = paddle.divide(paddle.to_tensor([2, 3, 4]), paddle.to_tensor([1, 5, 2])) +x = paddle.trunc(x) + +# PyTorch 写法 (rounding_mode 参数设置为"floor") +x = torch.divide(torch.tensor([2, 3, 4]), torch.tensor([1, 5, 2]), rounding_mode='floor') + +# Paddle 写法 +x = paddle.divide(paddle.to_tensor([2, 3, 4]), paddle.to_tensor([1, 5, 2])) +x = paddle.floor(x) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.divide(torch.tensor([2, 3, 4]), torch.tensor([1, 5, 2]), out=y) + +# Paddle 写法 +paddle.assign(paddle.divide(paddle.to_tensor([2, 3, 4]), paddle.to_tensor([1, 5, 2])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dot.md new file mode 100644 index 00000000000..33fdcf74d01 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dot.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.dot + +### [torch.dot](https://pytorch.org/docs/stable/generated/torch.dot.html?highlight=dot#torch.dot) + +```python +torch.dot(input, other, *, out=None) +``` + +### [paddle.dot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/dot_cn.html#dot) + +```python +paddle.dot(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.dot(torch.tensor([2, 3]), torch.tensor([2, 1]), out=y) + +# Paddle 写法 +paddle.assign(paddle.dot(paddle.to_tensor([2, 3]), paddle.to_tensor([2, 1])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dropout.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dropout.md new file mode 100644 index 00000000000..5d5eb3794bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dropout.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.dropout + +### [torch.dropout](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-pytorch-functions) + +```python +torch.dropout(input: Tensor, + p: float, + train: bool) +``` + +### [paddle.nn.functional.dropout](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/dropout_cn.html#dropout) + +```python +paddle.nn.functional.dropout(x, p=0.5, axis=None, training=True, mode='upscale_in_train', name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| p | p | 将输入节点置 0 的概率,即丢弃概率。默认值为 0.5。 | +| train | training | 标记是否为训练阶段。默认值为 True,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dsplit.md new file mode 100644 index 00000000000..63be788aca7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dsplit.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.dsplit +### [torch.dsplit](https://pytorch.org/docs/stable/generated/torch.dsplit.html#torch.dsplit) + +```python +torch.dsplit(input, + indices_or_sections) +``` + +### [paddle.dsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/dsplit_cn.html) + +```python +paddle.dsplit(x, + num_or_indices, + name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入多维 Tensor ,仅参数名不一致。 | +| indices_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dstack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dstack.md new file mode 100644 index 00000000000..928e78d1153 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.dstack.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.dstack + +### [torch.dstack](https://pytorch.org/docs/stable/generated/torch.dstack.html#torch.dstack) + +```python +torch.dstack(tensors, *, out=None) +``` + +### [paddle.dstack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/dstack_cn.html) + +```python +paddle.dstack(x, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.einsum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.einsum.md new file mode 100644 index 00000000000..480e89f5e8c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.einsum.md @@ -0,0 +1,22 @@ +## [参数完全一致]torch.einsum + +### [torch.einsum](https://pytorch.org/docs/stable/generated/torch.einsum.html#torch.einsum) + +```python +torch.einsum(equation, *operands) +``` + +### [paddle.einsum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/einsum_cn.html) + +```python +paddle.einsum(equation, *operands) +``` + +其中功能一致, 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | ---------- | +| equation | equation | 求和标记。 | +| operands | operands | 输入张量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty.md new file mode 100644 index 00000000000..c169482b70a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty.md @@ -0,0 +1,92 @@ +## [torch 参数更多]torch.empty + +### [torch.empty](https://pytorch.org/docs/stable/generated/torch.empty.html?highlight=empty#torch.empty) + +```python +torch.empty(*size, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False, + pin_memory=False, + memory_format=torch.contiguous_format) +``` + +### [paddle.empty](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/empty_cn.html) + +```python +paddle.empty(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| *size | shape | 表示输出形状大小, PyTorch 是可变参数用法, Paddle 是列表或元组,需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| pin_memory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### size:输出形状大小 + +```python +# PyTorch 写法 +torch.empty(3, 5) + +# Paddle 写法 +paddle.empty([3, 5]) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.empty((3, 5), out=y) + +# Paddle 写法 +paddle.assign(paddle.empty([3, 5]), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.empty((3, 5), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.empty([3, 5]) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.empty((3, 5), requires_grad=True) + +# Paddle 写法 +y = paddle.empty([3, 5]) +y.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +y = torch.empty((3, 5), pin_memory=True) + +# Paddle 写法 +y = paddle.empty([3, 5]).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty_like.md new file mode 100644 index 00000000000..37a0c1285d2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.empty_like.md @@ -0,0 +1,58 @@ +## [torch 参数更多]torch.empty_like + +### [torch.empty_like](https://pytorch.org/docs/stable/generated/torch.empty_like.html?highlight=empty_like#torch.empty_like) + +```python +torch.empty_like(input, + *, + dtype=None, + layout=None, + device=None, + requires_grad=False, + memory_format=torch.preserve_format) +``` + +### [paddle.empty_like](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/empty_like_cn.html) + +```python +paddle.empty_like(x, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.empty_like(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.empty_like(x) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.empty_like(x, requires_grad=True) + +# Paddle 写法 +y = paddle.empty_like(x) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.enable_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.enable_grad.md new file mode 100644 index 00000000000..14b280cd5f8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.enable_grad.md @@ -0,0 +1,12 @@ +## [ 无参数 ]torch.enable_grad +### [torch.enable_grad](https://pytorch.org/docs/stable/generated/torch.enable_grad.html?highlight=enable_grad#torch.enable_grad) + +```python +torch.enable_grad() +``` + +### [paddle.enable_grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/enable_grad.html#enable-grad) + +```python +paddle.enable_grad() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eq.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eq.md new file mode 100644 index 00000000000..e40ca557465 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eq.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.eq + +### [torch.eq](https://pytorch.org/docs/stable/generated/torch.eq.html) + +```python +torch.eq(input, other, *, out) +``` + +### [paddle.equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/equal_cn.html#equal) + +```python +paddle.equal(x, y) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| other | y | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:指定输出 +``` python +# PyTorch 写法: +torch.eq(x, y, out=out) + +# Paddle 写法: +paddle.assign(paddle.equal(x, y), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.equal.md new file mode 100644 index 00000000000..4f13355ce14 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.equal.md @@ -0,0 +1,37 @@ +## [ 返回参数类型不一致 ]torch.equal +### [torch.equal](https://pytorch.org/docs/stable/generated/torch.equal.html?highlight=equal#torch.equal) + +```python +torch.equal(input, + other) +``` + +### [paddle.equal_all](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/equal_all_cn.html#equal-all) + +```python +paddle.equal_all(x, + y, + name=None) +``` + +两者功能一致但返回参数类型不同,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | + +注:PyTorch 返回 bool 类型,Paddle 返回 0-D bool Tensor + + +### 转写示例 +#### 返回值 +``` python +# PyTorch 写法 +out = torch.equal(x, y) + +# Paddle 写法 +out = paddle.equal_all(x, y) +out = out.item() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erf.md new file mode 100644 index 00000000000..ad70fbc8d54 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erf.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.erf +### [torch.erf](https://pytorch.org/docs/stable/generated/torch.erf.html?highlight=torch+erf#torch.erf) + +```python +torch.erf(input, + *, + out=None) +``` + +### [paddle.erf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/erf_cn.html#erf) + +```python +paddle.erf(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.erf(torch.tensor([-0.4, -0.2, 0.1, 0.3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.erf(paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfc.md new file mode 100644 index 00000000000..4fe05a2d8c9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfc.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.erfc + +### [torch.erfc](https://pytorch.org/docs/stable/generated/torch.erfc.html#torch.erfc) + +```python +torch.erfc(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.erfc(a) + +# Paddle 写法 +y = 1 - paddle.erf(a) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfinv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfinv.md new file mode 100644 index 00000000000..3b08b08d763 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.erfinv.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.erfinv +### [torch.erfinv](https://pytorch.org/docs/stable/generated/torch.erfinv.html?highlight=torch+erfinv#torch.erfinv) + +```python +torch.erfinv(input, + *, + out=None) +``` + +### [paddle.erfinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/erfinv_cn.html) + +```python +paddle.erfinv(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.erfinv(torch.tensor([0, 0.5, -1.]), out=y) + +# Paddle 写法 +paddle.assign(paddle.erfinv(paddle.to_tensor([0, 0.5, -1.], dtype="float32")), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp.md new file mode 100644 index 00000000000..bf03c952356 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.exp +### [torch.exp](https://pytorch.org/docs/stable/generated/torch.exp.html?highlight=torch+exp#torch.exp) + +```python +torch.exp(input, + *, + out=None) +``` + +### [paddle.exp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/exp_cn.html#exp) + +```python +paddle.exp(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.exp(torch.tensor([-0.4, -0.2, 0.1, 0.3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.exp(paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp2.md new file mode 100644 index 00000000000..dea2c33e3a5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.exp2.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.exp2 + +### [torch.exp2](https://pytorch.org/docs/stable/generated/torch.exp2.html#torch.exp2) + +```python +torch.exp2(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.exp2(a) + +# Paddle 写法 +y = 2 ** a +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.expm1.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.expm1.md new file mode 100644 index 00000000000..4517617c929 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.expm1.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.expm1 +### [torch.expm1](https://pytorch.org/docs/stable/generated/torch.expm1.html?highlight=torch+expm1#torch.expm1) + +```python +torch.expm1(input, + *, + out=None) +``` + +### [paddle.expm1](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/expm1_cn.html) + +```python +paddle.expm1(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.expm1(torch.tensor([-0.4, -0.2, 0.1, 0.3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.expm1(paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eye.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eye.md new file mode 100644 index 00000000000..8941c2b9880 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.eye.md @@ -0,0 +1,71 @@ +## [torch 参数更多]torch.eye + +### [torch.eye](https://pytorch.org/docs/stable/generated/torch.eye.html?highlight=eye#torch.eye) + +```python +torch.eye(n, + m=None, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.eye](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/eye_cn.html) + +```python +paddle.eye(num_rows, + num_columns=None, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| n | num_rows | 表示生成 2-D Tensor 的行数,仅参数名不一致。 | +| m | num_columns | 表示生成 2-D Tensor 的列数, 仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.eye(3, out=y) + +# Paddle 写法 +paddle.assign(paddle.eye(3), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +torch.eye(3, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.eye(3) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.eye(3, requires_grad=True) + +# Paddle 写法 +y = paddle.eye(3) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.finfo.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.finfo.md new file mode 100644 index 00000000000..0eed4a3879c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.finfo.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.finfo + +### [torch.finfo](https://pytorch.org/docs/stable/type_info.html#torch-finfo) + +```python +torch.finfo(type) +``` + +### [paddle.finfo](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/finfo_cn.html) + +```python +paddle.finfo(dtype) +``` + +两者功能一致,参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------- | +| type | dtype | 输入的数据类型,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fix.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fix.md new file mode 100644 index 00000000000..fab95417560 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fix.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.fix +### [torch.fix](https://pytorch.org/docs/stable/generated/torch.fix.html?highlight=torch+fix#torch.fix) + +```python +torch.fix(input, + *, + out=None) +``` + +### [paddle.trunc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/trunc_cn.html) + +```python +paddle.trunc(input, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示输入的 Tensor。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fix(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.trunc(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flatten.md new file mode 100644 index 00000000000..74c04b30245 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flatten.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.flatten +### [torch.flatten](https://pytorch.org/docs/stable/generated/torch.flatten.html?highlight=flatten#torch.flatten) + +```python +torch.flatten(input, + start_dim=0, + end_dim=-1) +``` + +### [paddle.flatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/flatten_cn.html#flatten) + +```python +paddle.flatten(x, + start_axis=0, + stop_axis=-1, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| start_dim | start_axis | 表示 flatten 展开的起始维度,仅参数名不一致。 | +| end_dim | stop_axis | 表示 flatten 展开的结束维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flip.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flip.md new file mode 100644 index 00000000000..a64e69e7b6c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flip.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.flip +### [torch.flip](https://pytorch.org/docs/stable/generated/torch.flip.html?highlight=flip#torch.flip) + +```python +torch.flip(input, + dims) +``` + +### [paddle.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/flip_cn.html#flip) + +```python +paddle.flip(x, + axis, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fliplr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fliplr.md new file mode 100644 index 00000000000..a910b63a3ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fliplr.md @@ -0,0 +1,22 @@ +## [ 仅 paddle 参数更多 ]torch.fliplr +### [torch.fliplr](https://pytorch.org/docs/stable/generated/torch.fliplr.html?highlight=fliplr#torch.fliplr) + +```python +torch.fliplr(input) +``` + +### [paddle.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/flip_cn.html#flip) + +```python +paddle.flip(x, + axis, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | axis | 表示进行运算的轴,PyTorch 无此参数,Paddle 需设置为 1 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flipud.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flipud.md new file mode 100644 index 00000000000..79c8730303c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.flipud.md @@ -0,0 +1,29 @@ +## [ 参数不一致 ]torch.flipud +### [torch.flipud](https://pytorch.org/docs/stable/generated/torch.flipud.html?highlight=flipud#torch.flipud) + +```python +torch.flipud(input) +``` + +### [paddle.flip](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/flip_cn.html#flip) + +```python +paddle.flip(x, axis, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | axis | 表示对输入 Tensor 进行翻转的轴, PyTorch 无此参数, Paddle 需要将其设为 0。 | + +### 转写示例 +```python +# PyTorch 写法 +torch.flipud(x) + +# Paddle 写法 +paddle.flip(x, 0) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor.md new file mode 100644 index 00000000000..95e856ed929 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor.md @@ -0,0 +1,33 @@ +## [torch 参数更多]torch.floor +### [torch.floor](https://pytorch.org/docs/stable/generated/torch.floor.html?highlight=torch+floor#torch.floor) + +```python +torch.floor(input, + *, + out=None) +``` + +### [paddle.floor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/floor_cn.html#floor) + +```python +paddle.floor(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.floor(torch.tensor([-0.4, -0.2, 0.1, 0.3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.floor(paddle.to_tensor([-0.4, -0.2, 0.1, 0.3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor_divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor_divide.md new file mode 100644 index 00000000000..428a22a0df7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.floor_divide.md @@ -0,0 +1,46 @@ +## [参数不一致]torch.floor_divide +### [torch.floor_divide](https://pytorch.org/docs/stable/generated/torch.floor_divide.html?highlight=torch+floor_divide#torch.floor_divide) + +```python +torch.floor_divide(input, + other, + *, + out=None) +``` + +### [paddle.floor_divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/floor_divide_cn.html#floor-divide) + +```python +paddle.floor_divide(x, + y, + name=None) +``` + +其中 PyTorch 和 Paddle 的 `other` 参数支持类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的被除数 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的除数 Tensor ,torch 支持 Tensor 和 Python Number,paddle 仅支持 Tensor。当输入为 Python Number 时,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +torch.floor_divide(torch.tensor([2, 3, 8, 7]), other=2.) + +# Paddle 写法 +paddle.floor_divide(paddle.to_tensor([2, 3, 8, 7]), other=paddle.to_tensor(2.)) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.floor_divide(torch.tensor([2, 3, 8, 7]), torch.tensor([1, 5, 3, 3]), out=y) + +# Paddle 写法 +paddle.assign(paddle.floor_divide(paddle.to_tensor([2, 3, 8, 7]), paddle.to_tensor([1, 5, 3, 3])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmax.md new file mode 100644 index 00000000000..2e080159e43 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmax.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.fmax + +### [torch.fmax](https://pytorch.org/docs/stable/generated/torch.fmax.html#torch.fmax) + +```python +torch.fmax(input, other, *, out=None) +``` + +### [paddle.fmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fmax_cn.html) + +```python +paddle.fmax(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fmax(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.fmax(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmin.md new file mode 100644 index 00000000000..9cc6820ee98 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmin.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.fmin + +### [torch.fmin](https://pytorch.org/docs/stable/generated/torch.fmin.html#torch.fmin) + +```python +torch.fmin(input, other, *, out=None) +``` + +### [paddle.fmin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/fmin_cn.html) + +```python +paddle.fmin(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fmin(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.fmin(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmod.md new file mode 100644 index 00000000000..48d4e207d60 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.fmod.md @@ -0,0 +1,37 @@ +## [torch 参数更多 ]torch.fmod +### [torch.fmod](https://pytorch.org/docs/stable/generated/torch.fmod.html?highlight=fmod#torch.fmod) + +```python +torch.fmod(input, + other, + *, + out=None) +``` + +### [paddle.mod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/mod_cn.html#mod) + +```python +paddle.mod(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的被除数 ,仅参数名不一致。 | +| other | y | 表示输入的除数, PyTorch 可以为 Tensor 或 scalar,Paddle 只能为 Tensor 。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.fmod([3, 5], [1, 2], out=y) + +# Paddle 写法 +paddle.assign(paddle.mod([3, 5], [1, 2]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frac.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frac.md new file mode 100644 index 00000000000..db643675d3d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frac.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.frac +### [torch.frac](https://pytorch.org/docs/stable/generated/torch.frac.html?highlight=frac#torch.frac) + +```python +torch.frac(input, + *, + out=None) +``` + +### [paddle.frac](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/frac_cn.html#frac) + +```python +paddle.frac(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.frac(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.frac(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frexp.md new file mode 100644 index 00000000000..39589736647 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.frexp.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.frexp + +### [torch.frexp](https://pytorch.org/docs/stable/generated/torch.frexp.html?highlight=frexp#torch.frexp) + +```python +torch.frexp(input, + out=None) +``` + +### [paddle.frexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/frexp_cn.html#frexp) + +```python +paddle.frexp(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,可选项,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.frexp(x,out=y) + +# Paddle 写法 +paddle.assign(paddle.frexp(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_dlpack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_dlpack.md new file mode 100644 index 00000000000..a1c33d81db8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_dlpack.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.from_dlpack + +### [torch.from_dlpack](https://pytorch.org/docs/stable/generated/torch.from_dlpack.html?highlight=from_dlpack#torch.from_dlpack) + +```python +torch.from_dlpack(ext_tensor) +``` + +### [paddle.utils.dlpack.from_dlpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/dlpack/from_dlpack_cn.html) + +```python +paddle.utils.dlpack.from_dlpack(dlpack) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| ext_tensor | dlpack | 表示输入的带有 dltensor 的 PyCapsule 对象,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_numpy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_numpy.md new file mode 100644 index 00000000000..5599cc65a7d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.from_numpy.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.from_numpy +### [torch.from_numpy](https://pytorch.org/docs/stable/generated/torch.from_numpy.html?highlight=from_numpy#torch.from_numpy) + +```python +torch.from_numpy(ndarray) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, + dtype=None, + place=None, + stop_gradient=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| ndarray | data | 表示需要转换的数据, PyTorch 只能传入 numpy.ndarray , Paddle 可以传入 scalar 、 list 、 tuple 、 numpy.ndarray 、 paddle.Tensor 。 | +| - | dtype | 表示数据类型, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | place | 表示 Tensor 存放位置, PyTorch 无此参数, Paddle 需设置为 paddle.CPUPlace()。 | +| - | stop_gradient | 表示是否阻断梯度传导, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full.md new file mode 100644 index 00000000000..a6943235952 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full.md @@ -0,0 +1,71 @@ +## [torch 参数更多]torch.full + +### [torch.full](https://pytorch.org/docs/stable/generated/torch.full.html?highlight=ful#torch.full) + +```python +torch.full(size, + fill_value, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.full](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/full_cn.html) + +```python +paddle.full(shape, + fill_value, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| size | shape | 表示创建 Tensor 的形状,仅参数名不一致。 | +| fill_value | fill_value | 表示初始化输出 Tensor 的常量数据的值 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.full([3, 5], 1., out=y) + +# Paddle 写法 +paddle.assign(paddle.full([3, 5], 1.), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.full([3, 5], 1., device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.full([3, 5], 1.) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.full([3, 5], 1., requires_grad=True) + +# Paddle 写法 +y = paddle.full([3, 5], 1.) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full_like.md new file mode 100644 index 00000000000..47957302b30 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.full_like.md @@ -0,0 +1,57 @@ +## [torch 参数更多 ]torch.full_like +### [torch.full_like](https://pytorch.org/docs/stable/generated/torch.full_like.html?highlight=full_like#torch.full_like) + +```python +torch.full_like(input, + fill_value, + *, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False, + memory_format=torch.preserve_format) +``` + +### [paddle.full_like](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/full_like_cn.html#full-like) + +```python +paddle.full_like(x, + fill_value, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| fill_value | fill_value | 表示填充值。 | +| dtype | dtype | 表示数据类型。| +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| + + +### 转写示例 + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.full_like(x, 1., device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.full_like(x, 1.) +y.cpu() + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.full_like([3, 5], 1., requires_grad=True) + +# Paddle 写法 +x = paddle.full_like([3, 5], 1.) +x.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gather.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gather.md new file mode 100644 index 00000000000..5b176068bc1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gather.md @@ -0,0 +1,44 @@ +## [torch 参数更多 ]torch.gather +### [torch.gather](https://pytorch.org/docs/stable/generated/torch.gather.html?highlight=gather#torch.gather) + +```python +torch.gather(input, + dim, + index, + *, + sparse_grad=False, + out=None) +``` + +### [paddle.take_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/take_along_axis_cn.html#take-along-axis) + +```python +paddle.take_along_axis(arr, + indices, + axis, + broadcast=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor ,仅参数名不一致。 | +| dim | axis | 用于指定 index 获取输入的维度,仅参数名不一致。 | +| index | indices | 聚合元素的索引矩阵,维度和输入 (input) 的维度一致,仅参数名不一致。 | +| sparse_grad | - | 表示是否对梯度稀疏化,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示目标 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +``` python +# PyTorch 写法: +t = torch.tensor([[1, 2], [3, 4]]) +torch.gather(t, dim = 1, index = torch.tensor([[0, 0], [1, 0]]), out = y) + +# Paddle 写法: +t = paddle.to_tensor([[1, 2], [3, 4]]) +paddle.assign(paddle.take_along_axis(t, axis = 1, indices = [[0, 0], [1, 0]]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gcd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gcd.md new file mode 100644 index 00000000000..27c3759160e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gcd.md @@ -0,0 +1,35 @@ +## [ torch 参数更多]torch.gcd + +### [torch.gcd](https://pytorch.org/docs/stable/generated/torch.gcd.html#torch-gcd) + +```python +torch.gcd(input, other, *, out=None) +``` + +### [paddle.gcd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/gcd_cn.html#gcd) + +```python +paddle.gcd(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | x | 表示输入的第一个 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的第二个 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.gcd(x,y, out=output) + +# Paddle 写法 +paddle.assign(paddle.gcd(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ge.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ge.md new file mode 100644 index 00000000000..93d168e2fe5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ge.md @@ -0,0 +1,34 @@ +## [ 参数完全一致 ]torch.ge + +### [torch.ge](https://pytorch.org/docs/stable/generated/torch.ge.html) + +```python +torch.ge(input, other, *, out) +``` + +### [paddle.greater\_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/greater_equal_cn.html#greater-equal) + +```python +paddle.greater_equal(x, y) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| other | y | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:指定输出 +``` python +# PyTorch 写法: +torch.ge(x, y, out=out) + +# Paddle 写法: +paddle.assign(paddle.greater_equal(x, y), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ger.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ger.md new file mode 100644 index 00000000000..2a40331b2b2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ger.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.ger + +### [torch.ger](https://pytorch.org/docs/stable/generated/torch.ger.html?highlight=ger#torch.ger) + +```python +torch.ger(input, vec2, *, out=None) +``` + +### [paddle.outer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/outer_cn.html) + +```python +paddle.outer(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| vec2 | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.ger([1., 2., 3., 4.], [1., 2., 3.], out=y) + +# Paddle 写法 +paddle.assign(paddle.outer([1., 2., 3., 4.], [1., 2., 3.]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.get_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.get_rng_state.md new file mode 100644 index 00000000000..e0e150db6a1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.get_rng_state.md @@ -0,0 +1,33 @@ +## [参数不一致] torch.get_rng_state + +### [torch.get_rng_state](https://pytorch.org/docs/stable/generated/torch.get_rng_state.html#torch.get_rng_state) + +```python +torch.get_rng_state() +``` + +### [paddle.get_rng_state]() + +```python +paddle.get_rng_state() +``` + +其中 PyTorch 与 Paddle 的返回参数类型不一致 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| Tensor | GeneratorState | 返回类型不一致 | + + + +### 转写示例 +#### 返回参数类型不同 +```python +# PyTorch 写法 +x = torch.get_rng_state() + +# Paddle 写法 +x = paddle.get_rng_state() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.greater.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.greater.md new file mode 100644 index 00000000000..c4eecfc49a9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.greater.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.greater + +### [torch.greater](https://pytorch.org/docs/stable/generated/torch.greater.html?highlight=torch+greater#torch.greater) + +```python +torch.greater(input, other, *, out=None) +``` + +### [paddle.greater_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/greater_than_cn.html) + +```python +paddle.greater_than(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.greater(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.greater_than(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gt.md new file mode 100644 index 00000000000..2f1eee179a9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.gt.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.gt + +### [torch.gt](https://pytorch.org/docs/stable/generated/torch.gt.html) + +```python +torch.gt(input, other, *, out=None) +``` + +### [paddle.greater_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/greater_than_cn.html) + +```python +paddle.greater_than(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.gt(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.greater_than(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.heaviside.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.heaviside.md new file mode 100644 index 00000000000..733490e205c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.heaviside.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.heaviside +### [torch.heaviside](https://pytorch.org/docs/stable/generated/torch.heaviside.html#torch.heaviside) + +```python +torch.heaviside(input, values, *, out=None) +``` + +### [paddle.heaviside](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/heaviside_cn.html#heaviside) + +```python +paddle.heaviside(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| values | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.heaviside(x, y, out=z) + +# Paddle 写法 +z = paddle.heaviside(x, y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histc.md new file mode 100644 index 00000000000..d691fba5334 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histc.md @@ -0,0 +1,38 @@ +## [ 参数不一致 ]torch.histc + +### [torch.histc](https://pytorch.org/docs/stable/generated/torch.histc.html#torch-histc) + +```python +torch.histc(input, bins=100, min=0, max=0, *, out=None) +``` + +### [paddle.histogram](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/histogram_cn.html#histogram) + +```python +paddle.histogram(input, bins=100, min=0, max=0, name=None) +``` + +其中 PyTorch 与 Paddle 的返回值类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | input | 表示输入的 Tensor。 | +| bins | bins | 表示直方图直条的个数。 | +| min | min | 表示范围的下边界。 | +| max | max | 表示范围的上边界。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | 表示返回值,PyTorch 的返回值类型为 float32,Paddle 的返回值类型为 int64 , 需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.histc(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.histogram(x).astype('float32'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogram.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogram.md new file mode 100644 index 00000000000..6fd84918442 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogram.md @@ -0,0 +1,40 @@ +## [参数不一致]torch.histogram + +### [torch.histogram](https://pytorch.org/docs/stable/generated/torch.histogram.html#torch.histogram) + +```python +torch.histogram(input, bins, *, range=None, weight=None, density=False, out=None) +``` + +### [paddle.histogram](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/histogram_cn.html) + +```python +paddle.histogram(input, bins=100, min=0, max=0, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,返回参数 Tensor 数量不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------------------------------------------------------- | +| input | input | 输入 Tensor。 | +| bins | bins | 直方图 bins(直条)的个数。 | +| range | min, max | PyTorch 为 bins 的范围,类型为 float,Paddle 为 range 的下边界,上边界,类型为 int,需要转写。 | +| weight | - | 权重,Paddle 无此参数,暂无转写方式。 | +| density | - | 结果中每个 bin 是否包含权重数,Paddle 无此参数,暂无转写方式。 | +| 返回值 | 返回值 | PyTorch 返回 hist 和 bin_edges,Paddle 返回 hist,暂无转写方式。 | + +### 转写示例 + +#### range 参数:bins 的范围 + +```python +# PyTorch 写法: +x = torch.tensor([1., 2, 1]) +y = torch.histogram(x, bins=5, range=(0., 3.)) + +# Paddle 写法: +x = paddle.to_tensor([1, 2, 1]) +y = paddle.histogram(x, bins=5, min=0, max=3) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogramdd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogramdd.md new file mode 100644 index 00000000000..6ec155e5af4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.histogramdd.md @@ -0,0 +1,25 @@ +## [仅参数名不一致]torch.histogramdd + +### [torch.histogramdd](https://pytorch.org/docs/stable/generated/torch.histogramdd.html#torch-histogramdd) + +```python +torch.histogramdd(input, bins, *, range=None, weight=None, density=False) -> (Tensor, Tensor[]) +``` + +### [paddle.histogramdd](https://github.com/PaddlePaddle/Paddle/blob/a19227d9ee0e351363a4bb27b50b1becbec58a6c/python/paddle/tensor/linalg.py#L3875) + +```python +paddle.histogramdd(x, bins=10, ranges=None, density=False, weights=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| bins | bins | 直方图 bins(直条)的个数序列。 | +| range | ranges | bins 的范围,仅参数名不一致。 | +| weight | weights | 权重,仅参数名不一致。 | +| density | density | 结果中每个 bin 是否包含权重。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hsplit.md new file mode 100644 index 00000000000..0225fab4cd5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hsplit.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.hsplit +### [torch.hsplit](https://pytorch.org/docs/stable/generated/torch.hsplit.html#torch.hsplit) + +```python +torch.hsplit(input, + indices_or_sections) +``` + +### [paddle.hsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hsplit_cn.html) + +```python +paddle.hsplit(x, + num_or_indices, + name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入多维 Tensor ,仅参数名不一致。 | +| indices_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hstack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hstack.md new file mode 100644 index 00000000000..1526fe8b47d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hstack.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.hstack + +### [torch.hstack](https://pytorch.org/docs/stable/generated/torch.hstack.html#torch.hstack) + +```python +torch.hstack(tensors, *, out=None) +``` + +### [paddle.hstack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hstack_cn.html) + +```python +paddle.hstack(x, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hypot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hypot.md new file mode 100644 index 00000000000..952d7070c98 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.hypot.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.hypot + +### [torch.hypot](https://pytorch.org/docs/stable/generated/torch.hypot.html#torch.hypot) + +```python +torch.hypot(input, other, *, out=None) +``` + +### [paddle.hypot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/hypot_cn.html) + +```python +paddle.hypot(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| other | y | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.hypot(x, y, out=out) + +# Paddle 写法 +paddle.assign(paddle.hypot(x, y), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.i0.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.i0.md new file mode 100644 index 00000000000..34af7623110 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.i0.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.i0 + +### [torch.i0](https://pytorch.org/docs/stable/special.html#torch.special.i0) + +```python +torch.i0(input, + *, + out=None) +``` + +### [paddle.i0](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/i0_cn.html) + +```python +paddle.i0(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.i0(torch.tensor([1.0000, 1.2661, 2.2796]), out=y) + +# Paddle 写法 +paddle.assign(paddle.i0(paddle.to_tensor([1.0000, 1.2661, 2.2796])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.iinfo.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.iinfo.md new file mode 100644 index 00000000000..64dc415e48f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.iinfo.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.iinfo + +### [torch.iinfo](https://pytorch.org/docs/stable/type_info.html#torch-iinfo) + +```python +torch.iinfo(type) +``` + +### [paddle.iinfo](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/iinfo_cn.html) + +```python +paddle.iinfo(dtype) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------- | +| type | dtype | 输入的数据类型,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.imag.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.imag.md new file mode 100644 index 00000000000..d4783c1eda6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.imag.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.imag + +### [torch.imag](https://pytorch.org/docs/stable/generated/torch.imag.html?highlight=imag#torch.imag) + +```python +torch.imag(input) +``` + +### [paddle.imag](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/imag_cn.html#imag) + +```python +paddle.imag(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_add.md new file mode 100644 index 00000000000..6882dace103 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_add.md @@ -0,0 +1,44 @@ +## [ torch 参数更多 ]torch.index_add +### [torch.index_add](https://pytorch.org/docs/stable/generated/torch.index_add.html#torch.index_add) + +```python +torch.index_add(input, dim, index, source, *, alpha=1, out=None) +``` + +### [paddle.index_add](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/index_add_cn.html#index-add) + +```python +paddle.index_add(x, index, axis, value, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| source | value | 被加的 Tensor,仅参数名不一致。 | +| alpha | - | source 的 缩放倍数, Paddle 无此参数,需要转写。 Paddle 应将 alpha 和 source 的乘积作为 value。| +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### alpha:source 的缩放倍数 +```python +# PyTorch 写法 +torch.index_add(x, dim=1, index=index, source=source, alpha=alpha) + +# Paddle 写法 +paddle.index_add(x, index=index, axis=1, value=alpha*source) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.index_add(x, dim=1, index=index, source=source, alpha=alpha, out=y) + +# Paddle 写法 +paddle.assign(paddle.index_add(x, index=index, axis=1, value=alpha*source), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_copy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_copy.md new file mode 100644 index 00000000000..8d69dc352a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_copy.md @@ -0,0 +1,29 @@ +## [ 组合替代实现 ]torch.index_copy + +### [torch.index_copy](https://pytorch.org/docs/stable/generated/torch.index_copy.html#torch.index_copy) + +```python +torch.index_copy(input, dim, index, source, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法,dim=0 +y = torch.index_copy(input, 0, index, source) + +# Paddle 写法 +y = paddle.scatter(input, index, source) + +# PyTorch 写法,dim>0 +y = torch.index_copy(input, dim, index, source) + +# Paddle 写法 +times, temp_shape, temp_index = paddle.prod(paddle.to_tensor(input.shape[:dim])), input.shape, index +input, new_t = input.reshape([-1] + temp_shape[dim+1:]), source.reshape([-1] + temp_shape[dim+1:]) +for i in range(1, times): + temp_index= paddle.concat([temp_index, index+len(index)*i]) +y = paddle.scatter(input, temp_index, new_t).reshape(temp_shape) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_fill.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_fill.md new file mode 100644 index 00000000000..73a184f60bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_fill.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.index_fill + +### [torch.index_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.index_fill.html#torch.Tensor.index_fill) + +```python +torch.index_fill(input, dim, index, value) +``` + +### [paddle.index_fill](https://github.com/PaddlePaddle/Paddle/blob/1e3761d119643af19cb6f8a031a77f315d782409/python/paddle/tensor/manipulation.py#L5900) + +```python +paddle.index_fill(x, index, axis, value, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| index | index | 包含索引下标的 1-D Tensor。 | +| value | value | 填充的值。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_select.md new file mode 100644 index 00000000000..1e79c48e659 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.index_select.md @@ -0,0 +1,39 @@ +## [torch 参数更多 ]torch.index_select +### [torch.index_select](https://www.paddlepaddle.org.cn/documentation/docs/stable/develop/api/paddle/index_select_cn.html#index-select) + +```python +torch.index_select(input, + dim, + index, + *, + out=None) +``` + +### [paddle.index_select](https://www.paddlepaddle.org.cn/documentation/docs/stable/develop/api/paddle/index_select_cn.html#index-select) + +```python +paddle.index_select(x, + index, + axis=0, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.index_select(x, dim=1, index=index, out=y) + +# Paddle 写法 +paddle.assign(paddle.index_select(x, axis=1, index=index), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inference_mode.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inference_mode.md new file mode 100644 index 00000000000..73f7ef0bcfb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inference_mode.md @@ -0,0 +1,26 @@ +## [ 组合替代实现 ]torch.inference_mode + +### [torch.inference_mode](https://pytorch.org/docs/stable/generated/torch.inference_mode.html#torch.inference_mode) + +```python +torch.inference_mode(mode=True) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +@torch.inference_mode(False) + +# Paddle 写法 +# 当 mode 为 False 时,可以直接删去 + + +# PyTorch 写法 +@torch.inference_mode(True) + +# Paddle 写法 +@paddle.no_grad() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.initial_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.initial_seed.md new file mode 100644 index 00000000000..325259b0869 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.initial_seed.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.initial_seed + +### [torch.initial_seed](https://pytorch.org/docs/stable/generated/torch.initial_seed.html?highlight=initial_seed) +```python +torch.initial_seed() +``` + +获取当前随机数种子。返回一个用于播种 RNG 的 64 位数字。 + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +```python +# PyTorch 写法 +torch.initial_seed() + +# Paddle 写法 +paddle.get_rng_state()[0].current_seed() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inner.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inner.md new file mode 100644 index 00000000000..30e307fc0fc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inner.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.inner + +### [torch.inner](https://pytorch.org/docs/stable/generated/torch.inner.html?highlight=inner#torch.inner) + +```python +torch.inner(input, other, *, out=None) +``` + +### [paddle.inner](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/inner_cn.html) + +```python +paddle.inner(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.inner([[1., 2. , 3.], [4. ,5. ,6.]], [[1., 2. , 3.], [4. ,5. ,6.], [7., 8., 9.]], out=y) + +# Paddle 写法 +paddle.assign(paddle.inner([[1., 2. , 3.], [4. ,5. ,6.]], [[1., 2. , 3.], [4. ,5. ,6.], [7., 8., 9.]]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inverse.md new file mode 100644 index 00000000000..2d5bc7b5a17 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.inverse.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.inverse + +### [torch.inverse](https://pytorch.org/docs/stable/generated/torch.inverse.html?highlight=inverse#torch.inverse) + +```python +torch.inverse(input, *, out=None) +``` + +### [paddle.linalg.inv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/inv_cn.html) + +```python +paddle.linalg.inv(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.inverse(torch.tensor([[2., 0.], [0., 2.]]), out=y) + +# Paddle 写法 +paddle.assign(paddle.inverse(paddle.to_tensor([[2., 0], [0, 2.]])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_complex.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_complex.md new file mode 100644 index 00000000000..e25afeb8ea0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_complex.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.is_complex +### [torch.is_complex](https://pytorch.org/docs/stable/generated/torch.is_complex.html?highlight=is_complex#torch.is_complex) + +```python +torch.is_complex(input) +``` + +### [paddle.is_complex](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/is_complex_cn.html#is-complex) + +```python +paddle.is_complex(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_floating_point.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_floating_point.md new file mode 100644 index 00000000000..b02175f55d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_floating_point.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.is_floating_point + +### [torch.is_floating_point](https://pytorch.org/docs/stable/generated/torch.is_floating_point.html?highlight=is_floating_point#torch.is_floating_point) + +```python +torch.is_floating_point(input) +``` + +### [paddle.is_floating_point](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/is_floating_point_cn.html#is-floating-point) + +```python +paddle.is_floating_point(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_nonzero.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_nonzero.md new file mode 100644 index 00000000000..b0a7fc00f5a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_nonzero.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.is_nonzero + +### [torch.is_nonzero](https://pytorch.org/docs/stable/generated/torch.is_nonzero.html#torch.is_nonzero) + +```python +torch.is_nonzero(input) +``` + +用于判断单个元素是否为 `0` 或者 `False` ,当 `input` 的元素个数不为 1 时,抛出 `RuntimeError`; Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.is_nonzero(x) + +# Paddle 写法 +x.astype('bool').item() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_pinned.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_pinned.md new file mode 100644 index 00000000000..806517e7a16 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_pinned.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.Tensor.is_pinned + +### [torch.Tensor.is_pinned](https://pytorch.org/docs/stable/generated/torch.Tensor.is_pinned.html?highlight=is_pinned#torch.Tensor.is_pinned) + +```python +torch.Tensor.is_pinned() +``` + +返回张量是否在固定内存上; Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = a.is_pinned(b) + +# Paddle 写法 +y = 'pinned' in str(a.place) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_tensor.md new file mode 100644 index 00000000000..c9e54fa2f38 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.is_tensor.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.is_tensor + +### [torch.is_tensor](https://pytorch.org/docs/stable/generated/torch.is_tensor.html?highlight=is_tensor#torch.is_tensor) + +```python +torch.is_tensor(obj) +``` + +### [paddle.is_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/is_tensor_cn.html#is-tensor) + +```python +paddle.is_tensor(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| obj | x | 输⼊ Tensor ,被判断的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isclose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isclose.md new file mode 100644 index 00000000000..fd8c4a087cf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isclose.md @@ -0,0 +1,32 @@ +## [ 仅参数名不一致 ]torch.isclose +### [torch.isclose](https://pytorch.org/docs/stable/generated/torch.isclose.html?highlight=isclose#torch.isclose) + +```python +torch.isclose(input, + other, + rtol=1e-05, + atol=1e-08, + equal_nan=False) +``` + +### [paddle.isclose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/isclose_cn.html#isclose) + +```python +paddle.isclose(x, + y, + rtol=1e-05, + atol=1e-08, + equal_nan=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| rtol | rtol | 表示相对容忍误差。 | +| atol | atol | 表示绝对容忍误差。 | +| equal_nan | equal_nan | 表示是否将两个 NaN 数值视为相等。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isfinite.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isfinite.md new file mode 100644 index 00000000000..1cf4900ae42 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isfinite.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.isfinite +### [torch.isfinite](https://pytorch.org/docs/stable/generated/torch.isfinite.html?highlight=isfinite#torch.isfinite) + +```python +torch.isfinite(input) +``` + +### [paddle.isfinite](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/isfinite_cn.html#isfinite) + +```python +paddle.isfinite(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isinf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isinf.md new file mode 100644 index 00000000000..76af28b5b60 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isinf.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.isinf +### [torch.isinf](https://pytorch.org/docs/stable/generated/torch.isinf.html?highlight=isinf#torch.isinf) + +```python +torch.isinf(input) +``` + +### [paddle.isinf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/isinf_cn.html#isinf) + +```python +paddle.isinf(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isnan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isnan.md new file mode 100644 index 00000000000..0febaec1e1d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.isnan.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.isnan +### [torch.isnan](https://pytorch.org/docs/stable/generated/torch.isnan.html?highlight=isnan#torch.isnan) + +```python +torch.isnan(input) +``` + +### [paddle.isnan](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/isnan_cn.html#isnan) + +```python +paddle.isnan(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.istft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.istft.md new file mode 100644 index 00000000000..fed6c2e81b4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.istft.md @@ -0,0 +1,47 @@ +## [ 仅参数名不一致 ]torch.istft +### [torch.istft](https://pytorch.org/docs/stable/generated/torch.istft.html?highlight=istft#torch.istft) + +```python +torch.istft(input, + n_fft, + hop_length=None, + win_length=None, + window=None, + center=True, + normalized=False, + onesided=None, + length=None, + return_complex=False) +``` + +### [paddle.signal.istft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/signal/istft_cn.html#istft) + +```python +paddle.signal.istft(x, + n_fft, + hop_length=None, + win_length=None, + window=None, + center=True, + normalized=False, + onesided=True, + length=None, + return_complex=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| n_fft | n_fft | 表示离散傅里叶变换的样本点个数。 | +| hop_length | hop_length | 表示相邻两帧偏移的样本点个数。 | +| win_length | win_length | 表示信号窗的长度。 | +| window | window | 表示长度为 win_length 的 Tensor 。 | +| center | center | 表示是否将输入信号进行补长。 | +| normalized | normalized | 表示是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | +| onesided | onesided | 表示是否返回一个实信号。 | +| length | length | 表示输出信号的长度。 | +| return_complex | return_complex | 表示输出的重构信号是否为复信号。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kron.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kron.md new file mode 100644 index 00000000000..7bea3473a3f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kron.md @@ -0,0 +1,23 @@ +## [仅参数名不一致]torch.kron + +### [torch.kron](https://pytorch.org/docs/stable/generated/torch.kron.html#torch-kron) + +```python +torch.kron(input, other, *, out=None) +``` + +### [paddle.kron](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/kron_cn.html#kron) + +```python +paddle.kron(x, y, out=None, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | x | 表示 Kron OP 输入的第一个 Tensor ,仅参数名不一致。 | +| other | y | 表示 Kron OP 输入的第二个 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kthvalue.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kthvalue.md new file mode 100644 index 00000000000..14bbf388606 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.kthvalue.md @@ -0,0 +1,45 @@ +## [ 仅参数名不一致 ]torch.kthvalue +### [torch.kthvalue](https://pytorch.org/docs/stable/generated/torch.kthvalue.html?highlight=kthvalue#torch.kthvalue) + +```python +torch.kthvalue(input, + k, + dim=None, + keepdim=False, + *, + out=None) +``` + +### [paddle.kthvalue](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/kthvalue_cn.html) + +```python +paddle.kthvalue(x, + k, + axis=None, + keepdim=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| k | k | 表示需要沿轴查找的第 k 小值。 | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写 。 | + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.kthvalue(x, 2, 1, out=y) + +# Paddle 写法 +out0, out1 = paddle.kthvalue(x, 2, 1) +paddle.assign(out0, y[0]), paddle.assign(out1, y[1]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lcm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lcm.md new file mode 100644 index 00000000000..daf03afdf89 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lcm.md @@ -0,0 +1,35 @@ +## [ torch 参数更多]torch.lcm + +### [torch.lcm](https://pytorch.org/docs/stable/generated/torch.lcm.html#torch-lcm) + +```python +torch.lcm(input, other, *, out=None) +``` + +### [paddle.lcm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lcm_cn.html#lcm) + +```python +paddle.lcm(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | x | 表示输入的第一个 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的第二个 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.lcm(x,y, out=output) + +# Paddle 写法 +paddle.assign(paddle.lcm(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ldexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ldexp.md new file mode 100644 index 00000000000..a08dfcf4b1f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ldexp.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.ldexp + +### [torch.ldexp](https://pytorch.org/docs/stable/generated/torch.ldexp.html#torch.ldexp) + +```python +torch.ldexp(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.ldexp(a, b) + +# Paddle 写法 +y = a * (2 ** b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.le.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.le.md new file mode 100644 index 00000000000..082626e04bf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.le.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ]torch.le + +### [torch.le](https://pytorch.org/docs/stable/generated/torch.le.html) + +```python +torch.le(input, other, *, out=None) +``` + +### [paddle.less_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/less_equal_cn.html) + +```python +paddle.less_equal(x, y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Python Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Python Number 类型时,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +torch.le(x, 2) + +# Paddle 写法 +paddle.less_equal(x, paddle.to_tensor(2)) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.le(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.less_equal(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lerp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lerp.md new file mode 100644 index 00000000000..1075ccbfc7e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lerp.md @@ -0,0 +1,40 @@ +## [torch 参数更多 ]torch.lerp +### [torch.lerp](https://pytorch.org/docs/stable/generated/torch.lerp.html?highlight=lerp#torch.lerp) + +```python +torch.lerp(input, + end, + weight, + *, + out=None) +``` + +### [paddle.lerp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lerp_cn.html#lerp) + +```python +paddle.lerp(x, + y, + weight, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| end | y | 表示输入的 Tensor ,仅参数名不一致。 | +| weight | weight | 表示输入的 Tensor 。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.lerp(input1,input2,0.5, out=y) + +# Paddle 写法 +paddle.assign(paddle.lerp(input1,input2, 0.5), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less.md new file mode 100644 index 00000000000..e06938c4ec9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.less + +### [torch.less](https://pytorch.org/docs/stable/generated/torch.less.html#torch.less) + +```python +torch.less(input, other, *, out=None) +``` + +### [paddle.less_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/less_than_cn.html) + +```python +paddle.less_than(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.less(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.less_than(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less_equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less_equal.md new file mode 100644 index 00000000000..c85700cb285 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.less_equal.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ]torch.less_equal + +### [torch.less_equal](https://pytorch.org/docs/stable/generated/torch.less_equal.html#torch.less_equal) + +```python +torch.less_equal(input, other, *, out=None) +``` + +### [paddle.less_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/less_equal_cn.html) + +```python +paddle.less_equal(x, y, name=None) +``` + +其中 Paddle 和 PyTorch 的 `other` 参数所支持的数据类型不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,PyTorch 支持 Number 和 Tensor 类型, Paddle 仅支持 Tensor 类型。当输入为 Number 类型时,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +torch.less_equal(x, 2) + +# Paddle 写法 +paddle.less_equal(x, paddle.to_tensor(2)) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.less_equal(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.less_equal(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lgamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lgamma.md new file mode 100644 index 00000000000..aea058f51de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lgamma.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.lgamma +### [torch.lgamma](https://pytorch.org/docs/stable/generated/torch.lgamma.html?highlight=lgamma#torch.lgamma) + +```python +torch.lgamma(input, + *, + out=None) +``` + +### [paddle.lgamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lgamma_cn.html#lgamma) + +```python +paddle.lgamma(x + , name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.lgamma(input,out=y) + +# Paddle 写法 +paddle.assign(paddle.lgamma(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.linspace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.linspace.md new file mode 100644 index 00000000000..60e1d8aa822 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.linspace.md @@ -0,0 +1,74 @@ +## [torch 参数更多]torch.linspace + +### [torch.linspace](https://pytorch.org/docs/stable/generated/torch.linspace.html?highlight=linspace#torch.linspace) + +```python +torch.linspace(start, + end, + steps, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.linspace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linspace_cn.html) + +```python +paddle.linspace(start, + stop, + num, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| start | start | 表示区间开始的变量。 | +| end | stop | 表示区间结束的变量,仅参数名不一致。 | +| steps | num | 表示给定区间内需要划分的区间数,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.linspace(0, 10, 5, out=y) + +# Paddle 写法 +paddle.assign(paddle.linspace(0, 10, 5), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.linspace(0, 10, 5, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.linspace(0, 10, 5) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.linspace(0, 10, 5, requires_grad=True) + +# Paddle 写法 +y = paddle.linspace(0, 10, 5) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.load.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.load.md new file mode 100644 index 00000000000..0fe5cefe17b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.load.md @@ -0,0 +1,32 @@ +## [torch 参数更多 ]torch.load + +### [torch.load](https://pytorch.org/docs/stable/generated/torch.load.html?highlight=load#torch.load) + +```python +torch.load(f, + map_location=None, + pickle_module=pickle, + *, + weights_only=False, + **pickle_load_args) +``` + +### [paddle.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/load_cn.html#load) + +```python +paddle.load(path, + **configs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------------- | ------------ | ------------------------------------------------------------ | +| f | path | 载入目标对象实例的路径/内存对象, 仅参数名不一致。 | +| map_location | - | 表示如何重新映射存储位置,Paddle 无此参数,暂无转写方式。 | +| pickle_module | - | 表示用于 unpickling 元数据和对象的模块,Paddle 无此参数,暂无转写方式。 | +| weights_only | - | 指示 unpickler 是否应限制为仅加载张量、原始类型和字典,Paddle 无此参数,暂无转写方式。 | +| pickle_load_args | - | 传递给 pickle_module.load()和 pickle_mdule.Unpickler()的可选关键字参数,Paddle 无此参数,暂无转写方式。 | +| - | configs | 表示其他用于兼容的载入配置选项。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log.md new file mode 100644 index 00000000000..266db807ce1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.log +### [torch.log](https://pytorch.org/docs/stable/generated/torch.log.html?highlight=log#torch.log) + +```python +torch.log(input, + *, + out=None) +``` + +### [paddle.log](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/log_cn.html#log) + +```python +paddle.log(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.log(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.log(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log10.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log10.md new file mode 100644 index 00000000000..b6634e9f0d0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log10.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.log10 +### [torch.log10](https://pytorch.org/docs/stable/generated/torch.log10.html?highlight=log10#torch.log10) + +```python +torch.log10(input, + *, + out=None) +``` + +### [paddle.log10](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/log10_cn.html#log10) + +```python +paddle.log10(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.log10(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.log10(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log1p.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log1p.md new file mode 100644 index 00000000000..8b052cefbfd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log1p.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.log1p +### [torch.log1p](https://pytorch.org/docs/stable/generated/torch.log1p.html?highlight=log1p#torch.log1p) + +```python +torch.log1p(input, + *, + out=None) +``` + +### [paddle.log1p](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/log1p_cn.html#log1p) + +```python +paddle.log1p(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.log1p(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.log1p(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log2.md new file mode 100644 index 00000000000..a3073387fc9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.log2.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.log2 +### [torch.log2](https://pytorch.org/docs/stable/generated/torch.log2.html?highlight=log2#torch.log2) + +```python +torch.log2(input, + *, + out=None) +``` + +### [paddle.log2](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/log2_cn.html#log2) + +```python +paddle.log2(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.log2(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.log2(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp.md new file mode 100644 index 00000000000..281f0a97c2a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.logaddexp + +### [torch.logaddexp](https://pytorch.org/docs/stable/generated/torch.logaddexp.html#torch.logaddexp) + +```python +torch.logaddexp(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.logaddexp(a, b) + +# Paddle 写法 +y = paddle.log(paddle.exp(a) + paddle.exp(b)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp2.md new file mode 100644 index 00000000000..e02126936d3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logaddexp2.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.logaddexp2 + +### [torch.logaddexp2](https://pytorch.org/docs/stable/generated/torch.logaddexp2.html#torch.logaddexp2) + +```python +torch.logaddexp2(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.logaddexp2(a, b) + +# Paddle 写法 +y = paddle.log2(2 ** a + 2 ** b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logcumsumexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logcumsumexp.md new file mode 100644 index 00000000000..0c0fa41ffa6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logcumsumexp.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.logcumsumexp + +### [torch.logcumsumexp](https://pytorch.org/docs/stable/generated/torch.logcumsumexp.html#torch-logcumsumexp) + +```python +torch.logcumsumexp(input, dim, *, out=None) +``` + +### [paddle.logcumsumexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logcumsumexp_cn.html#logcumsumexp) + +```python +paddle.logcumsumexp(x, axis=None, dtype=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示需要计算的维度,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| - | dtype | 表示输出 Tensor 的数据类型,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.logcumsumexp(x,dim=0, out=output) + +# Paddle 写法 +paddle.assign(paddle.logcumsumexp(x,axis=0), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logdet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logdet.md new file mode 100644 index 00000000000..3cddb435338 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logdet.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.logdet + +### [torch.logdet](https://pytorch.org/docs/stable/generated/torch.logdet.html#torch.logdet) + +```python +torch.logdet(input) +``` +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.logdet(input) + +# Paddle 写法 +y = paddle.log(paddle.linalg.det(input)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_and.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_and.md new file mode 100644 index 00000000000..38e226bb9ad --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_and.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.logical_and +### [torch.logical_and](https://pytorch.org/docs/stable/generated/torch.logical_and.html?highlight=logical_and#torch.logical_and) + +```python +torch.logical_and(input, + other, + *, + out=None) +``` + +### [paddle.logical_and](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logical_and_cn.html#logical-and) + +```python +paddle.logical_and(x, + y, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 输出 Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_not.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_not.md new file mode 100644 index 00000000000..ce8acacfd46 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_not.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.logical_not +### [torch.logical_not](https://pytorch.org/docs/stable/generated/torch.logical_not.html?highlight=logical_not#torch.logical_not) + +```python +torch.logical_not(input, + *, + out=None) +``` + +### [paddle.logical_not](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logical_not_cn.html#logical-not) + +```python +paddle.logical_not(x, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_or.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_or.md new file mode 100644 index 00000000000..424f77110aa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_or.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.logical_or +### [torch.logical_or](https://pytorch.org/docs/stable/generated/torch.logical_or.html?highlight=logical_or#torch.logical_or) + +```python +torch.logical_or(input, + other, + *, + out=None) +``` + +### [paddle.logical_or](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logical_or_cn.html#logical-or) + +```python +paddle.logical_or(x, + y, + out=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_xor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_xor.md new file mode 100644 index 00000000000..56ad561e228 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logical_xor.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.logical_xor + +### [torch.logical_xor](https://pytorch.org/docs/stable/generated/torch.logical_xor.html?highlight=torch+logical_xor#torch.logical_xor) + +```python +torch.logical_xor(input, other, *, out=None) +``` + +### [paddle.logical_xor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logical_xor_cn.html) + +```python +paddle.logical_xor(x, y, out=None, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | out | 表示输出的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logit.md new file mode 100644 index 00000000000..761bb5c4dbf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logit.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.logit + +### [torch.logit](https://pytorch.org/docs/stable/generated/torch.logit.html?highlight=torch+logit#torch.logit) + +```python +torch.logit(input, eps=None, *, out=None) +``` + +### [paddle.logit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logit_cn.html) + +```python +paddle.logit(x, eps=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| eps | eps | 将输入向量的范围控制在 [eps,1−eps] | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.logit(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.logit(x),y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logspace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logspace.md new file mode 100644 index 00000000000..31aa48b252a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.logspace.md @@ -0,0 +1,77 @@ +## [torch 参数更多]torch.logspace + +### [torch.logspace](https://pytorch.org/docs/stable/generated/torch.logspace.html?highlight=logspace#torch.logspace) + +```python +torch.logspace(start, + end, + steps, + base=10.0, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.logspace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logspace_cn.html) + +```python +paddle.logspace(start, + stop, + num, + base=10.0, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| start | start | 表示区间开始值以 base 为底的指数。 | +| end | stop | 表示区间结束值以 base 为底的指数,仅参数名不一致。 | +| steps | num | 表示给定区间内需要划分的区间数,仅参数名不一致。 | +| base | base | 表示对数函数的底数。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.logspace(0, 10, 5, 2, out=y) + +# Paddle 写法 +paddle.assign(paddle.logspace(0, 10, 5, 2), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.logspace(0, 10, 5, 2, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.logspace(0, 10, 5, 2) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.logspace(0, 10, 5, 2, requires_grad=True) + +# Paddle 写法 +y = paddle.logspace(0, 10, 5, 2) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lt.md new file mode 100644 index 00000000000..b8454f8ea53 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lt.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.lt + +### [torch.lt](https://pytorch.org/docs/stable/generated/torch.lt.html#torch.lt) + +```python +torch.lt(input, other, *, out=None) +``` + +### [paddle.less_than](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/less_than_cn.html) + +```python +paddle.less_than(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.lt(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.less_than(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu.md new file mode 100644 index 00000000000..89c92f4dacb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.lu + +### [torch.lu](https://pytorch.org/docs/stable/generated/torch.lu.html?highlight=lu#torch.lu) + +```python +torch.lu(A, pivots=True, get_infos=False, *, out) +``` + +### [paddle.linalg.lu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lu_cn.html) + +```python +paddle.linalg.lu(x, pivot=True, get_infos=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 输入的 Tensor ,仅参数名不一致。 | +| pivots | pivot | 输入的 bool ,参数完全一致。 | +| get_infos | get_infos | 输入的 bool ,参数完全一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.lu(torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]), get_infos=True, out=(A_LU, pivots, info)) + +# Paddle 写法 +A_LU, pivots, info = paddle.linalg.lu(paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]), get_infos=True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu_unpack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu_unpack.md new file mode 100644 index 00000000000..f814e345476 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.lu_unpack.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.lu_unpack +### [torch.lu_unpack](https://pytorch.org/docs/stable/generated/torch.lu_unpack.html?highlight=lu_unpack#torch.lu_unpack) + +```python +torch.lu_unpack(LU_data, LU_pivots, unpack_data=True, unpack_pivots=True, *, out=None) +``` + +### [paddle.linalg.lu_unpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/lu_unpack_cn.html) + +```python +paddle.linalg.lu_unpack(x, y, unpack_ludata=True, unpack_pivots=True, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| LU_data | x | 输入的 Tensor ,仅参数名不一致。 | +| LU_pivots | y | 输入的 Tensor ,仅参数名不一致。 | +| unpack_data | unpack_ludata | 输入的 bool ,仅参数名不一致。 | +| unpack_pivots | unpack_pivots | 输入的 bool ,参数完全一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.lu_unpack(*torch.lu(torch.tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])), out=(P, L, U)) + +# Paddle 写法 +P,L,U = paddle.linalg.lu_unpack(*paddle.linalg.lu(paddle.to_tensor([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]))) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_fill.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_fill.md new file mode 100644 index 00000000000..198fec04de1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_fill.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ] torch.masked_fill + +### [torch.masked_fill](https://pytorch.org/docs/stable/generated/torch.Tensor.masked_fill.html#torch.Tensor.masked_fill) + +```python +torch.masked_fill(input, mask, value) +``` + +### [paddle.masked_fill](https://github.com/PaddlePaddle/Paddle/blob/1e3761d119643af19cb6f8a031a77f315d782409/python/paddle/tensor/manipulation.py#L5111) + +```python +paddle.masked_fill(x, mask, value, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| mask | mask | 布尔张量,表示要填充的位置 | +| value | value | 用于填充目标张量的值 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_select.md new file mode 100644 index 00000000000..987e09f5119 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.masked_select.md @@ -0,0 +1,37 @@ +## [torch 参数更多 ]torch.masked_select +### [torch.masked_select](https://pytorch.org/docs/stable/generated/torch.masked_select.html?highlight=masked_select#torch.masked_select) + +```python +torch.masked_select(input, + mask, + *, + out=None) +``` + +### [paddle.masked_select](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/masked_select_cn.html#masked-select) + +```python +paddle.masked_select(x, + mask, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| mask | mask | 表示用于索引的二进制掩码的 Tensor 。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.masked_select(x, mask, out=y) + +# Paddle 写法 +paddle.assign(paddle.masked_select(x, mask), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matmul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matmul.md new file mode 100644 index 00000000000..0d7b3c99805 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matmul.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.matmul +### [torch.matmul](https://pytorch.org/docs/stable/generated/torch.matmul.html?highlight=matmul#torch.matmul) +```python +torch.matmul(input, + other, + out=None) +``` + +### [paddle.matmul](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/matmul_cn.html) +```python +paddle.matmul(x, + y, + transpose_x=False, + transpose_y=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的第一个 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的第二个 Tensor ,仅参数名不一致。 | +| - | transpose_x | 表示相乘前是否转置 x,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | transpose_y | 表示相乘前是否转置 y,PyTorch 无此参数,Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.matmul(a, b, out=y) + +# Paddle 写法 +paddle.assign(paddle.matmul(a, b), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matrix_power.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matrix_power.md new file mode 100644 index 00000000000..c453f7f089e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.matrix_power.md @@ -0,0 +1,30 @@ +## [torch 参数更多 ]torch.matrix_power +### [torch.matrix_power](https://pytorch.org/docs/stable/generated/torch.matrix_power.html?highlight=matrix_power) +```python +torch.matrix_power(input, n, *, out=None) +``` + +### [paddle.linalg.matrix_power](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/matrix_power_cn.html) +```python +paddle.linalg.matrix_power(x, n, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| n | n | 输入的 int ,参数完全一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.matrix_power(torch.tensor([[1., 2., 3.],[1., 4., 9.],[1., 8., 27.]]), 2, out=y) + +# Paddle 写法 +paddle.assign(paddle.linalg.matrix_power(paddle.to_tensor([[1., 2., 3.],[1., 4., 9.],[1., 8., 27.]]), 2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max.md new file mode 100644 index 00000000000..aba99bdbabc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max.md @@ -0,0 +1,97 @@ +## [ 参数不一致 ]torch.max +输入一个 Tensor 对应 paddle.max,输入两个 Tensor 对应 paddle.maximum,因此有两组差异分析,分别如下: + +-------------------------------------------------------------------------------------------------- +### [torch.max](https://pytorch.org/docs/stable/generated/torch.max.html?highlight=max#torch.max) + +```python +torch.max(input, + dim=None, + keepdim=False, + *, + out=None) +``` + +### [paddle.max](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/max_cn.html#max) + +```python +paddle.max(x, + axis=None, + keepdim=False, + name=None) +``` + +其中 PyTorch 与 Paddle 指定 `dim` 后返回值不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 求最大值运算的维度, 仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | 表示返回结果,当指定 dim 后,PyTorch 会返回比较结果和元素索引, Paddle 不会返回元素索引,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# 对指定维度上的 Tensor 元素求最大值运算 + +# PyTorch 写法 +torch.max(a, out=y) +# torch 在输入 dim 时,返回 (values, indices),返回参数类型不一致 + +# Paddle 写法 +paddle.assign(paddle.max(a), y) +``` +#### 指定 dim 后的返回值 +```python +# PyTorch 写法 +result = torch.max(a, dim=1) + +# Paddle 写法 +result = torch.max(a, dim=1), torch.argmax(a, dim=1) +``` + +-------------------------------------------------------------------------------------------------- + +### [torch.max](https://pytorch.org/docs/stable/generated/torch.max.html?highlight=max#torch.max) + +```python +torch.max(input, + other, + *, + out=None) +``` + +### [paddle.maximum](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/minimum_cn.html#minimum) + +```python +paddle.maximum(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor , 仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# 逐元素对比输入的两个 Tensor + +# PyTorch 写法 +torch.max(a, b, out=y) +# 在输入 other 时,比较 input 和 other 返回较大值 + +# Paddle 写法 +paddle.assign(paddle.maximum(a, b), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool1d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool1d.md new file mode 100644 index 00000000000..f7cfb3b6c86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool1d.md @@ -0,0 +1,27 @@ +## [ torch 参数更多 ]torch.max_pool1d + +### [torch.max\_pool1d](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-pytorch-functions) + +```python +torch.max_pool1d(input, kernel_size, stride=[], padding=[0], dilation=[1], ceil_mode=False) +``` + +### [paddle.nn.functional.max_pool1d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool1d_cn.html) + +```python +paddle.nn.functional.max_pool1d(x, kernel_size, stride=None, padding=0, return_mask=False, ceil_mode=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------ | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| - | return_mask | 是否返回最大值的索引,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool2d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool2d.md new file mode 100644 index 00000000000..a8688c5ec0a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool2d.md @@ -0,0 +1,28 @@ +## [ torch 参数更多 ]torch.max_pool2d + +### [torch.max\_pool2d](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-pytorch-functions) + +```python +torch.max_pool2d(input, kernel_size, stride=[], padding=[0, 0], dilation=[1, 1], ceil_mode=False) +``` + +### [paddle.nn.functional.max_pool2d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool2d_cn.html) + +```python +paddle.nn.functional.max_pool2d(x, kernel_size, stride=None, padding=0, ceil_mode=False, return_mask=False, data_format='NCHW', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| - | return_mask | 是否返回最大值的索引,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool3d.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool3d.md new file mode 100644 index 00000000000..0b89c960240 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.max_pool3d.md @@ -0,0 +1,28 @@ +## [ 仅参数名不一致 ]torch.max_pool3d + +### [torch.max\_pool3d](https://pytorch.org/docs/stable/jit_builtin_functions.html#supported-pytorch-functions) + +```python +torch.max_pool3d(input, kernel_size, stride=[], padding=[0, 0, 0], dilation=[1, 1, 1], ceil_mode=False) +``` + +### [paddle.nn.functional.max_pool3d](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/max_pool3d_cn.html) + +```python +paddle.nn.functional.max_pool3d(x, kernel_size, stride=None, padding=0, ceil_mode=False, return_mask=False, data_format="NCDHW", name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| kernel_size | kernel_size | 池化核的尺寸大小。 | +| stride | stride | 池化操作步长。 | +| padding | padding | 池化补零的方式。 | +| dilation | - | 带有滑动窗口元素间的 stride,Paddle 无此参数,暂无转写方式。 | +| ceil_mode | ceil_mode | 是否用 ceil 函数计算输出的 height 和 width。 | +| - | return_mask | 是否返回最大值的索引,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 输入和输出的数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.maximum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.maximum.md new file mode 100644 index 00000000000..f6b55f6e95d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.maximum.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.maximum + +### [torch.maximum](https://pytorch.org/docs/stable/generated/torch.maximum.html#torch.maximum) + +```python +torch.maximum(input, other, *, out=None) +``` + +### [paddle.maximum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/maximum_cn.html) + +```python +paddle.maximum(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.maximum(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.maximum(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mean.md new file mode 100644 index 00000000000..b9e660c6ac0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mean.md @@ -0,0 +1,47 @@ +## [ torch 参数更多 ]torch.mean + +### [torch.mean](https://pytorch.org/docs/stable/generated/torch.mean.html) + +```python +torch.mean(input, dim, keepdim=False, *, dtype=None, out=None) +``` + +### [paddle.mean](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/mean_cn.html#mean) + +```python +paddle.mean(x, axis=None, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| dtype | - | 输出 Tensor 的类型,Paddle 无此参数, 需要转写。 | +| out | - | 输出 Tensor,Paddle 无此参数, 需要转写。 | + +### 转写示例 + +#### dtype:输出数据类型 + +```python +# PyTorch 写法 +torch.mean(x, dtype=torch.float32) + +# Paddle 写法 +paddle.mean(x).astype(paddle.float32) +``` + +#### out:输出 Tensor + +```python +# PyTorch 写法 +torch.mean(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.mean(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.median.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.median.md new file mode 100644 index 00000000000..47f7eeb12e2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.median.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ]torch.median +### [torch.median](https://pytorch.org/docs/stable/generated/torch.median.html?highlight=median#torch.median) + +```python +torch.median(input, + dim=-1, + keepdim=False, + *, + out=None) +``` + +### [paddle.median](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/median_cn.html#median) + +```python +paddle.median(x, axis=None, keepdim=False, mode='avg', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| - | mode | 当 x 在所需要计算的轴上有偶数个非 NaN 元素时,选择使用平均值或最小值确定非 NaN 中位数的值, PyTorch 无此参数,Paddle 需设置为 'min'。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.median([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.median([3, 5], mode='min'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.meshgrid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.meshgrid.md new file mode 100644 index 00000000000..3ce99046925 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.meshgrid.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.meshgrid +### [torch.meshgrid](https://pytorch.org/docs/stable/generated/torch.meshgrid.html?highlight=meshgrid#torch.meshgrid) + +```python +torch.meshgrid(*tensors, indexing=None) +``` + +### [paddle.meshgrid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/meshgrid_cn.html#meshgrid) + +```python +paddle.meshgrid(*args, **kargs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | args | 输入的 Tensor 列表,仅参数名不一致。 | +| indexing | - | tensor 的组合模式。Paddle 无此参数,需要转写。 | + +### 转写示例 +#### indexing:tensor 的组合模式 +```python +# PyTorch 写法 (indexing 为‘ij’时) +torch.meshgrid(x, y, indexing='ij') + +# Paddle 写法 +paddle.meshgrid(x, y) + +# PyTorch 写法 (indexing 为‘xy’时) +torch.meshgrid(x, y, indexing='xy') + +# Paddle 写法 +list([i.T for i in paddle.meshgrid(x, y)]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.min.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.min.md new file mode 100644 index 00000000000..76d0b0cf9aa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.min.md @@ -0,0 +1,96 @@ +## [ 参数不一致 ]torch.min +输入一个 Tensor 对应 paddle.min,输入两个 Tensor 对应 paddle.minimum,因此有两组差异分析,分别如下: + +-------------------------------------------------------------------------------------------------- +### [torch.min](https://pytorch.org/docs/stable/generated/torch.min.html?highlight=min#torch.min) + +```python +torch.min(input, + dim=None, + keepdim=False, + *, + out=None) +``` + +### [paddle.min](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/min_cn.html#min) + +```python +paddle.min(x, + axis=None, + keepdim=False, + name=None) +``` + +其中 PyTorch 与 Paddle 指定 `dim` 后返回值不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 求最小值运算的维度, 仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | 表示返回结果,当指定 dim 后,PyTorch 会返回比较结果和元素索引, Paddle 不会返回元素索引,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# 对指定维度上的 Tensor 元素求最大值运算 + +# PyTorch 写法 +torch.min(a, out=y) +# torch 在输入 dim 时,返回 (values, indices),返回参数类型不一致 + +# Paddle 写法 +paddle.assign(paddle.min(a), y) +``` +#### 指定 dim 后的返回值 +```python +# PyTorch 写法 +result = torch.min(a, dim=1) + +# Paddle 写法 +result = torch.min(a, dim=1), torch.argmin(a, dim=1) +``` + +-------------------------------------------------------------------------------------------------- + +### [torch.min](https://pytorch.org/docs/stable/generated/torch.min.html?highlight=min#torch.min) + +```python +torch.min(input, + other, + *, + out=None) +``` + +### [paddle.minimum](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/minimum_cn.html#minimum) + +```python +paddle.minimum(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor。 | +| other | y | 输入的 Tensor。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# 逐元素对比输入的两个 Tensor + +# PyTorch 写法 +torch.min(a, b, out=y) +# 在输入 other 时,比较 input 和 other 返回较大值 + +# Paddle 写法 +paddle.assign(paddle.minimum(a, b), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.minimum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.minimum.md new file mode 100644 index 00000000000..e7bd305b8f2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.minimum.md @@ -0,0 +1,33 @@ +## [torch 参数更多 ]torch.minimum + +### [torch.minimum](https://pytorch.org/docs/stable/generated/torch.minimum.html#torch.minimum) + +```python +torch.minimum(input, other, *, out=None) +``` + +### [paddle.minimum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/minimum_cn.html) + +```python +paddle.minimum(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.minimum(x, y, out=output) + +# Paddle 写法 +paddle.assign(paddle.minimum(x,y), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mm.md new file mode 100644 index 00000000000..de8a07a0927 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mm.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.mm +### [torch.mm](https://pytorch.org/docs/stable/generated/torch.mm.html?highlight=torch+mm#torch.mm) + +```python +torch.mm(input, + mat2, + *, + out=None) +``` + +### [paddle.mm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/mm_cn.html) + +```python +paddle.mm(input, mat2, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,Paddle 多余参数保持默认即可,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示输入的第一个 Tensor。 | +| mat2 | mat2 | 表示输入的第二个 Tensor。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.mm(a, b, out=y) + +# Paddle 写法 +paddle.assign(paddle.mm(a, b), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mode.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mode.md new file mode 100644 index 00000000000..47888fd80a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mode.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.mode + +### [torch.mode](https://pytorch.org/docs/stable/generated/torch.mode.html) + +```python +torch.mode(input, dim=-1, keepdim=False, *, out=None) +``` + +### [paddle.mode](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/mode_cn.html#mode) + +```python +paddle.mode(x, axis=-1, keepdim=False, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| dim | axis | 指定对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否保留指定的轴。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.mode(x, dim, False, out=(a, b)) + +# Paddle 写法 +out1, out2 = paddle.mode(x, dim, False) +paddle.assign(out1, a), paddle.assign(out2, b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.moveaxis.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.moveaxis.md new file mode 100644 index 00000000000..791f704323c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.moveaxis.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.moveaxis +### [torch.moveaxis](https://pytorch.org/docs/stable/generated/torch.moveaxis.html?highlight=moveaxis#torch.moveaxis) + +```python +torch.moveaxis(input, + source, + destination) +``` + +### [paddle.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/moveaxis_cn.html#moveaxis) + +```python +paddle.moveaxis(x, + source, + destination, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| source | source | 表示将被移动的轴的位置,仅参数名不一致。 | +| destination | destination | 表示轴被移动后的目标位置,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.movedim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.movedim.md new file mode 100644 index 00000000000..3e8e34a8478 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.movedim.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.movedim +### [torch.movedim](https://pytorch.org/docs/stable/generated/torch.movedim.html?highlight=movedim#torch.movedim) + +```python +torch.movedim(input, + source, + destination) +``` + +### [paddle.moveaxis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/moveaxis_cn.html#moveaxis) + +```python +paddle.moveaxis(x, + source, + destination, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| source | source | 表示将被移动的轴的位置,仅参数名不一致。 | +| destination | destination | 表示轴被移动后的目标位置,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.msort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.msort.md new file mode 100644 index 00000000000..e65bb4a681e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.msort.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.msort + +### [torch.msort](https://pytorch.org/docs/stable/generated/torch.msort.html#torch.msort) + +```python +torch.msort(input, *, out=None) +``` + +### [paddle.sort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sort_cn.html#sort) + +```python +paddle.sort(x, axis=-1, descending=False, name=None) +``` + +其中 PyTorch 与 Paddle 有不同的参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | axis | 排序的维度,当维度为 0 时,Paddle 与 PyTorch 功能一致。 | +| - | descending | 设置是否降序排列。PyTorch 无此参数,Paddle 保持默认即可。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写 。 | + +### 转写示例 +#### out:表示输出的 Tensor +```python +# PyTorch 写法 +torch.msort(input, out=out) + +# Paddle 写法 +paddle.assign(paddl.sort(input, axis=0), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mul.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mul.md new file mode 100644 index 00000000000..df23a182f9b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mul.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.mul + +### [torch.mul](https://pytorch.org/docs/stable/generated/torch.mul.html?highlight=torch+mul#torch.mul) + +```python +torch.mul(input, other, *, out=None) +``` + +### [paddle.multiply](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/multiply_cn.html) + +```python +paddle.multiply(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.mul([3, 5], [1, 2], out=y) + +# Paddle 写法 +paddle.assign(paddle.multiply([3, 5], [1, 2]),y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multinomial.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multinomial.md new file mode 100644 index 00000000000..c9a408c702d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multinomial.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ]torch.multinomial +### [torch.multinomial](https://pytorch.org/docs/stable/generated/torch.multinomial.html#torch.multinomial) +```python +torch.multinomial(input, + num_samples, + replacement=False, + *, + generator=None, + out=None) +``` +### [paddle.multinomial](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/multinomial_cn.html) +```python +paddle.multinomial(x, + num_samples=1, + replacement=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| num_samples | num_samples | 表示采样的次数。 | +| replacement | replacement | 表示是否是可放回的采样。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.multinomial(torch.tensor([0.3, 0.5, 0.2]), out=y) + +# Paddle 写法 +paddle.assign(paddle.multinomial(paddle.to_tensor([0.3, 0.5, 0.2])), y) +``` +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multiply.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multiply.md new file mode 100644 index 00000000000..6b4062b05d9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.multiply.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ]torch.multiply + +### [torch.multiply](https://pytorch.org/docs/stable/generated/torch.multiply.html?highlight=torch+multiply#torch.multiply) + +```python +torch.multiply(input, other, *, out=None) +``` + +### [paddle.multiply](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/multiply_cn.html) + +```python +paddle.multiply(x, y, name=None) +``` + +其中 PyTorch 和 Paddle 的 `other` 参数支持类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,torch 支持 Tensor 和 Python Number,paddle 仅支持 Tensor。当输入为 Python Number 时,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### other:输入为 Number +```python +# PyTorch 写法 +torch.multiply(torch.tensor([2, 3, 8, 7]), other=2.0) + +# Paddle 写法 +paddle.multiply(paddle.to_tensor([2, 3, 8, 7]), other=paddle.to_tensor(2.0)) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.multiply([3, 5], [1, 2], out = y) + +# Paddle 写法 +paddle.assign(paddle.multiply([3, 5], [1, 2]) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mv.md new file mode 100644 index 00000000000..1a809fa7c45 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.mv.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.mv +### [torch.mv](https://pytorch.org/docs/stable/generated/torch.mv.html?highlight=torch+mv#torch.mv) +```python +torch.mv(input, vec, out=None) +``` + +### [paddle.mv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/mv_cn.html) + +```python +paddle.mv(x, vec, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| vec | vec | 表示输入的 Tensor 。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写 。 | + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.mv(x, vec, out=y) + +# Paddle 写法 +paddle.assign(paddle.mv(x, vec), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nan_to_num.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nan_to_num.md new file mode 100644 index 00000000000..86e8f62177e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nan_to_num.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.nan_to_num + +### [torch.nan_to_num](https://pytorch.org/docs/stable/generated/torch.nan_to_num.html?highlight=nan_to_num#torch.nan_to_num) + +```python +torch.nan_to_num(input, nan=0.0, posinf=None, neginf=None, *, out=None) +``` + +### [paddle.nan_to_num](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nan_to_num_cn.html#nan-to-num) + +```python +paddle.nan_to_num(x, nan=0.0, posinf=None, neginf=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| nan | nan | 表示用于替换 nan 的值。 | +| posinf | posinf | 表示+inf 的替换值。 | +| neginf | neginf | 表示-inf 的替换值。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.nan_to_num(x, n, pos, neg, out = y) + +# Paddle 写法 +paddle.assign(paddle.nan_to_num(x, n, pos, neg), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmean.md new file mode 100644 index 00000000000..0937e182189 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmean.md @@ -0,0 +1,53 @@ +## [ torch 参数更多 ]torch.nanmean + +### [torch.nanmean](https://pytorch.org/docs/stable/generated/torch.nanmean.html?highlight=nanmean#torch.nanmean) + +```python +torch.nanmean(input, + dim=None, + keepdim=False, + dtype=None, + out=None) +``` + +### [paddle.nanmean](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nanmean_cn.html) + +```python +paddle.nanmean(x, + axis=None, + keepdim=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,可选项,仅参数名不一致。 | +| keepdim | keepdim | 表示是否保留计算后的维度,可选项。 | +| dtype | - | 指定输出数据类型,可选项,PyTorch 默认值为 None,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,可选项,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### dytpe:指定数据类型 + +```python +# PyTorch 写法 +torch.nanmean(x, dim=-1, dtype=torch.float32,out=y) + +# Paddle 写法 +paddle.assign(paddle.nanmean(x.astype('float32'),dim=-1),y) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.nanmean(t, dim=1,out=y) + +# Paddle 写法 +paddle.assign(paddle.nanmean(t, dim=1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmedian.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmedian.md new file mode 100644 index 00000000000..923bf31a370 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanmedian.md @@ -0,0 +1,39 @@ +## [torch 参数更多]torch.nanmedian +### [torch.nanmedian](https://pytorch.org/docs/stable/generated/torch.nanmedian.html?highlight=nanmedian#torch.nanmedian) + +```python +torch.nanmedian(input, + dim=-1, + keepdim=False, + *, + out=None) +``` + +### [paddle.nanmedian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nanmedian_cn.html#nanmedian) + +```python +paddle.nanmedian(x, axis=None, keepdim=False, mode='avg', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 表示是否在输出 Tensor 中保留减小的维度。 | +| - | mode | 当 x 在所需要计算的轴上有偶数个非 NaN 元素时,选择使用平均值或最小值确定非 NaN 中位数的值, PyTorch 无此参数,Paddle 需设置为 'min'。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.nanmedian(a, -1, out=y) + +# Paddle 写法 +paddle.assign(paddle.nanmedian(a, -1, mode='min'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanquantile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanquantile.md new file mode 100644 index 00000000000..12b56a8d4cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nanquantile.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.nanquantile + +### [torch.nanquantile](https://pytorch.org/docs/stable/generated/torch.nanquantile.html?highlight=nanquantile#torch.nanquantile) + +```python +torch.nanquantile(input, + q, + dim=None, + keepdim=False, + *, + interpolation='linear', + out=None) +``` + +### [paddle.nanquantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nanquantile_cn.html#nanquantile) + +```python +paddle.nanquantile(x, + q, + axis=None, + keepdim=False, + interpolation='linear', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| q | q | 待计算的分位数。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。| +| interpolation | interpolation | 当所需分位数位于两个数据点之间时使用的插值方法。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# Pytorch 写法 +torch.nanquantile(torch.tensor([float('nan'), 1., 2., 3.]), 0.6, interpolation='linear', out=y) + +# Paddle 写法 +paddle.assign(paddle.nanquantile(paddle.to_tensor([float('nan'), 1., 2., 3.]), 0.6, interpolation='linear'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow.md new file mode 100644 index 00000000000..19c27e8b933 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow.md @@ -0,0 +1,39 @@ +## [ 参数不一致 ]torch.narrow +### [torch.narrow](https://pytorch.org/docs/stable/generated/torch.narrow.html?highlight=narrow#torch.narrow) +```python +torch.narrow(input, + dim, + start, + length) +``` + + +### [paddle.slice](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/slice_cn.html#slice) +```python +paddle.slice(input, + axes, + starts, + ends) +``` + +其中 PyTorch 的 length 与 Paddle 的 ends 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示输入的 Tensor 。 | +| dim | axes | 表示切片的轴。 | +| start | starts | 表示起始位置。 | +| length | - | 到结束位置的长度,Paddle 无此参数。应修改 ends 实现。 | +| - | ends | 表示结束位置,PyTorch 无此参数。 Paddle 应设为 start + length。 | + + +### 转写示例 +``` python +# PyTorch 写法: +torch.narrow(x, 0, 1, 2) + +# Paddle 写法: +# Paddle 可通过设置 ends-starts=length 来实现 PyTorch 的 length 功能 +paddle.slice(x, [0], [1], [3]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow_copy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow_copy.md new file mode 100644 index 00000000000..3a63ef74e76 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.narrow_copy.md @@ -0,0 +1,18 @@ +## [ 组合替代实现 ]torch.narrow_copy + +### [torch.narrow_copy](https://pytorch.org/docs/stable/generated/torch.narrow_copy.html#torch.narrow_copy) +```python +torch.narrow_copy(input, dim, start, length, *, out=None) +``` + +Paddle 目前无此 API,需要组合替代实现 + +### 转写示例 +``` python +# PyTorch 写法: +torch.narrow_copy(x, 0, 1, 2) + +# Paddle 写法: +# Paddle 可通过设置 ends-starts=length 来实现 PyTorch 的 length 功能 +paddle.assign(paddle.slice(x, [0], [1], [3])) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ne.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ne.md new file mode 100644 index 00000000000..3282e52d20a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ne.md @@ -0,0 +1,39 @@ +## [torch 参数更多 ]torch.ne + +### [torch.ne](https://pytorch.org/docs/stable/generated/torch.ne.html?highlight=torch.ne#torch.ne) + +```python +torch.ne(input, + other, + *, + out=None) +``` + +### [paddle.not_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/not_equal_cn.html#not_equal) + +```python +paddle.not_equal(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.ne(input, other,out=y) + +# Paddle 写法 +paddle.assign(paddle.ne(input, other, y)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.neg.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.neg.md new file mode 100644 index 00000000000..5cc68d3ef51 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.neg.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.neg + +### [torch.neg](https://pytorch.org/docs/stable/generated/torch.neg.html?highlight=neg#torch.neg) + +```python +torch.neg(input, *, out=None) +``` + +### [paddle.neg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/neg_cn.html) + +```python +paddle.neg(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.neg(x , out=y) + +# Paddle 写法 +paddle.assign(paddle.neg(x) , y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.negative.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.negative.md new file mode 100644 index 00000000000..bd94eb2d301 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.negative.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.negative + +### [torch.negative](https://pytorch.org/docs/stable/generated/torch.negative.html?highlight=torch+negative#torch.negative) + +```python +torch.negative(input, *, out=None) +``` + +### [paddle.neg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/neg_cn.html) + +```python +paddle.neg(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.negative(x ,out = y) + +# Paddle 写法 +paddle.assign(paddle.neg(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nextafter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nextafter.md new file mode 100644 index 00000000000..a88acf5dea6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nextafter.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ]torch.nextafter + +### [torch.nextafter](https://pytorch.org/docs/stable/generated/torch.nextafter.html?highlight=nextafter#torch.nextafter) + +```python +torch.nextafter(input, + other, + *, + out=None) +``` + +### [paddle.nextafter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nextafter_cn.html) + +```python +paddle.nextafter(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| other | y | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.nextafter(torch.tensor([1.0, 2.0]), torch.tensor([2.0, 1.0]), out=y) + +# Paddle 写法 +paddle.assign(paddle.nextafter(paddle.to_tensor([1.0, 2.0]),paddle.to_tensor([2.0, 1.0])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.Module.modules.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.Module.modules.md new file mode 100644 index 00000000000..b030a127f3b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.Module.modules.md @@ -0,0 +1,21 @@ +## [ 仅 paddle 参数更多 ]torch.nn.Module.modules + +### [torch.nn.Module.modules](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.modules) + +```python +torch.nn.Module.modules() +``` + +### [paddle.nn.Layer.sublayers](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/Layer_cn.html#sublayers-include-self-false) + +```python +paddle.nn.Layer.sublayers(include_self=False) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| - | include_self | 是否包含本层。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.modules.batchnorm._BatchNorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.modules.batchnorm._BatchNorm.md new file mode 100644 index 00000000000..d7c1b8b1a47 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nn.modules.batchnorm._BatchNorm.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.nn.modules.batchnorm._BatchNorm + +### [torch.nn.modules.batchnorm.\_BatchNorm](https://pytorch.org/docs/stable/_modules/torch/nn/modules/batchnorm.html) + +```python +torch.nn.modules.batchnorm._BatchNorm(num_features, eps=1e-5, momentum=0.1, affine=True, track_running_stats=True, device=None, dtype=None) +``` + +### [paddle.nn.layer.norm.\_BatchNormBase](https://github.com/PaddlePaddle/Paddle/blob/b51d50bc9ee9eaa5cefa18507195b239e4513194/python/paddle/nn/layer/norm.py#L701) + +```python +paddle.nn.layer.norm._BatchNormBase(num_features, momentum=0.9, epsilon=1e-05, weight_attr=None, bias_attr=None, data_format='NCHW', use_global_stats=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------- | ---------------------------- | --------- | +| num_features | num_features | 特征数量。 | +| eps | epsilon | 一个极小正数,仅参数名不一致。 | +| momentum | momentum | 动量因子,参数默认值不一致。 | +| affine | - | 是否进行仿射变换,Paddle 无此参数,需要转写。 +| track_running_stats | - | 是否跟踪运行时的 mean 和 var, Paddle 无此参数。暂无转写方式。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| dtype | - | 参数类型,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | weight_attr | 指定权重参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | bias_attr | 指定偏置参数属性的对象,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | data_format | 指定输入数据格式,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### affine:是否进行仿射变换 + +```python +# 当 PyTorch 的 affine 为`False`,表示 weight 和 bias 不进行更新,torch 写法 +torch.nn.modules.batchnorm._BatchNorm(num_features, affine=False) + +# paddle 写法 +paddle.nn.layer.norm._BatchNormBase(num_features, weight_attr=False, bias_attr=False) + +# 当 PyTorch 的 affine 为`True`,torch 写法 +torch.nn.modules.batchnorm._BatchNorm(num_features, affine=True) + +# paddle 写法 +paddle.nn.layer.norm._BatchNormBase(num_features) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nonzero.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nonzero.md new file mode 100644 index 00000000000..8ec6bbb90e6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.nonzero.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.nonzero +### [torch.nonzero](https://pytorch.org/docs/stable/generated/torch.nonzero.html#torch.nonzero) + +```python +torch.nonzero(input, + *, + out=None, + as_tuple=False) +``` + +### [paddle.nonzero](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nonzero_cn.html) + +```python +paddle.nonzero(x, + as_tuple=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| as_tuple | as_tuple | bool 类型表示输出数据的格式,默认 False 时,输出一个张量,True 时输出一组一维张量。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.nonzero(torch.tensor([3, 5]), out=y) + +# Paddle 写法 +paddle.assign(paddle.nonzero(paddle.to_tensor([3, 5])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.norm.md new file mode 100644 index 00000000000..027672939dd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.norm.md @@ -0,0 +1,47 @@ +## [ torch 参数更多 ]torch.norm + +### [torch.norm](https://pytorch.org/docs/stable/generated/torch.norm.html) + +```python +torch.norm(input, p='fro', dim=None, keepdim=False, out=None, dtype=None) +``` + +### [paddle.linalg.norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/norm_cn.html#norm) + +```python +paddle.linalg.norm(x, p='fro', axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| p | p | 范数(ord)的种类。 | +| dim | axis | 使用范数计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出的 Tensor 中保留和输入一样的维度。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | - | 表示输出 Tensor 的数据类型, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:指定输出 +``` python +# PyTorch 写法: +torch.norm(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.norm(x) , y) +``` + +#### dtype:表示输出 Tensor 的数据类型 + +```python +# PyTorch 写法 +torch.norm(x, dtype=torch.float64) + +# Paddle 写法 +paddle.linalg.norm(x.astype(paddle.float64)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.normal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.normal.md new file mode 100644 index 00000000000..97c1d4e7d8c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.normal.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ]torch.normal +### [torch.normal](https://pytorch.org/docs/stable/generated/torch.normal.html#torch.normal) +```python +torch.normal(mean, + std, + *, + generator=None, + out=None) +``` +### [paddle.normal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/normal_cn.html) +```python +paddle.normal(mean=0.0, + std=1.0, + shape=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| mean | mean | 表示正态分布的均值。 | +| std | std | 表示正态分布的方差。 | +| - | shape | 表示输出 Tensor 的形状,PyTorch 无此参数, Paddle 保持默认即可。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor, Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.normal(torch.tensor([0, 0, 0]), torch.tensor([1.0, 2.0, 3.0]), out=y) + +# Paddle 写法 +paddle.assign(paddle.normal(paddle.to_tensor([0, 0, 0]), paddle.to_tensor([1.0, 2.0, 3.0])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.not_equal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.not_equal.md new file mode 100644 index 00000000000..97b0782b98e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.not_equal.md @@ -0,0 +1,39 @@ +## [torch 参数更多 ]torch.not_equal + +### [torch.not_equal](https://pytorch.org/docs/stable/generated/torch.not_equal.html?highlight=torch.not_equal#torch.not_equal) + +```python +torch.not_equal(input, + other, + *, + out=None) +``` + +### [paddle.not_equal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/not_equal_cn.html#not_equal) + +```python +paddle.not_equal(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------| +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| other | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.not_equal(input, other,out=y) + +# Paddle 写法 +paddle.assign(paddle.not_equal(input, other, y)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.numel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.numel.md new file mode 100644 index 00000000000..d1a3810e2c1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.numel.md @@ -0,0 +1,24 @@ +## [torch 参数更多 ]torch.numel +### [torch.numel](https://pytorch.org/docs/stable/generated/torch.numel.html?highlight=numel#torch.numel) + +```python +torch.numel(input) +``` + +### [paddle.Tensor.size](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#size) + +```python +paddle.Tensor.size +``` + +Paddle 使用类方法来实现,因此忽略第一个参数,无其他参数。 + + +### 转写示例 +```python +# PyTorch 写法 +torch.numel(x) + +# Paddle 写法 +x.size +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones.md new file mode 100644 index 00000000000..6ead163c84c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones.md @@ -0,0 +1,73 @@ +## [ 参数不一致 ]torch.ones +### [torch.ones](https://pytorch.org/docs/stable/generated/torch.ones.html?highlight=ones#torch.ones) + +```python +torch.ones(*size, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.ones](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/ones_cn.html#ones) + +```python +paddle.ones(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *size | shape | 表示输出形状大小,PyTorch 以可变参数方式传入,Paddle 以 list 或 tuple 的方式传入。 | +| out | - | 表示输出的 Tensor, Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示数据类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### *size:输出形状大小 +```python +# PyTorch 写法 +torch.ones(3, 5) + +# Paddle 写法 +paddle.ones([3, 5]) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.ones((3, 2), out=y) + +# Paddle 写法 +paddle.assign(paddle.ones([3, 2]), y) +``` + + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.ones(3, 2, requires_grad=True) + +# Paddle 写法 +x = paddle.ones([3, 2]) +x.stop_gradient = False +``` + + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.ones(3, 2, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.ones([3, 2]) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones_like.md new file mode 100644 index 00000000000..736aaa80812 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ones_like.md @@ -0,0 +1,58 @@ +## [torch 参数更多]torch.ones_like + +### [torch.ones_like](https://pytorch.org/docs/stable/generated/torch.ones_like.html?highlight=ones_like#torch.ones_like) + +```python +torch.ones_like(input, + *, + dtype=None, + layout=None, + device=None, + requires_grad=False, + memory_format=torch.preserve_format) +``` + +### [paddle.ones_like](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/ones_like_cn.html) + +```python +paddle.ones_like(x, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| input | x | 表示输入 Tensor ,仅名称不同。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.ones_like(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.ones_like(x) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.ones_like(x, requires_grad=True) + +# Paddle 写法 +y = paddle.ones_like(x) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.outer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.outer.md new file mode 100644 index 00000000000..0cd90043034 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.outer.md @@ -0,0 +1,35 @@ +## [torch 参数更多 ]torch.outer + +### [torch.outer](https://pytorch.org/docs/stable/generated/torch.outer.html#torch.outer) + +```python +torch.outer(input, vec2, *, out=None) +``` + +### [paddle.outer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/outer_cn.html) + +```python +paddle.outer(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| vec2 | y | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 +```python +# PyTorch 写法 +torch.outer([1., 2., 3., 4.], [1., 2., 3.], out=y) + +# Paddle 写法 +paddle.assign(paddle.outer([1., 2., 3., 4.], [1., 2., 3.]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pca_lowrank.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pca_lowrank.md new file mode 100644 index 00000000000..fcc81b4c7ec --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pca_lowrank.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.pca_lowrank + +### [torch.pca_lowrank](https://pytorch.org/docs/stable/generated/torch.pca_lowrank.html#torch.pca_lowrank) + +```python +torch.pca_lowrank(A, q=None, center=True, niter=2) +``` + +### [paddle.linalg.pca_lowrank](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/pca_lowrank_cn.html) + +```python +paddle.linalg.pca_lowrank(x, q=None, center=True, niter=2, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------------------------------------- | +| A | x | 输入的需要进行线性主成分分析的一个或一批方阵,仅参数名不一致。 | +| q | q | 对输入 Tensor 的秩稍微高估的预估值。 | +| center | center | 是否对输入矩阵进行中心化操作。 | +| niter | niter | 表示子空间进行迭代的数量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.permute.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.permute.md new file mode 100644 index 00000000000..ad8e3d19a26 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.permute.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.permute +### [torch.permute](https://pytorch.org/docs/stable/generated/torch.permute.html?highlight=permute#torch.permute) + +```python +torch.permute(input, + dims) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor,仅参数名不一致。 | +| dims | perm | dims 长度必须和 input 的维度相同,并依照 dims 中数据进行重排,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pinverse.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pinverse.md new file mode 100644 index 00000000000..473b63e3c44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pinverse.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.pinverse +### [torch.pinverse](https://pytorch.org/docs/stable/generated/torch.pinverse.html?highlight=pinverse#torch.pinverse) + +```python +torch.pinverse(input, + rcond=1e-15) +``` + +### [paddle.linalg.pinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/pinv_cn.html#pinv) + +```python +paddle.linalg.pinv(x, + rcond=1e-15, + hermitian=False, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| rcond | rcond | 奇异值(特征值)被截断的阈值,仅参数名不一致。 | +| - | hermitian | 是否为 hermitian 矩阵或者实对称矩阵,PyTorch 无,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.poisson.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.poisson.md new file mode 100644 index 00000000000..b8a577520a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.poisson.md @@ -0,0 +1,20 @@ +## [ torch 参数更多 ]torch.poisson + +### [torch.poisson](https://pytorch.org/docs/stable/generated/torch.poisson.html#torch.poisson) +```python +torch.poisson(input, + generator=None) +``` +### [paddle.poisson](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/poisson_cn.html) +```python +paddle.poisson(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polar.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polar.md new file mode 100644 index 00000000000..b8c3c43b8ba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polar.md @@ -0,0 +1,23 @@ +## [ 组合替代实现 ]torch.polar + +### [torch.polar](https://pytorch.org/docs/stable/generated/torch.polar.html#torch.polar) +```python +torch.polar(abs, angle, *, out=None) +``` + + +构造一个复数张量,其元素为与绝对值 abs 和角 angle 对应的极坐标所对应的笛卡尔坐标,公式为: + +$ out= abs ⋅ cos(angle) + abs ⋅ sin(angle) ⋅ j $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.polar(abs, angle, out=y) + +# Paddle 写法 +y = paddle.complex(abs * paddle.cos(angle), abs * paddle.sin(angle)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polygamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polygamma.md new file mode 100644 index 00000000000..4a3acd224bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.polygamma.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ]torch.polygamma + +### [torch.polygamma](https://pytorch.org/docs/stable/special.html#torch.special.polygamma) + +```python +torch.polygamma(n, + input, + *, + out=None) +``` + +### [paddle.polygamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/polygamma_cn.html) + +```python +paddle.polygamma(x, + n, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| n | n | 指定需要求解 n 阶多伽马函数。 | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.polygamma(1, torch.tensor([1, 0.5]), out=y) + +# Paddle 写法 +paddle.assign(paddle.polygamma(paddle.to_tensor([1, 0.5]), 1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pow.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pow.md new file mode 100644 index 00000000000..6872c23d5bb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.pow.md @@ -0,0 +1,38 @@ +## [torch 参数更多 ]torch.pow + +### [torch.pow](https://pytorch.org/docs/stable/generated/torch.pow.html?highlight=pow#torch.pow) + +```python +torch.pow(input, + exponent, + *, + out=None) +``` + +### [paddle.pow](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/pow_cn.html) + +```python +paddle.pow(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| exponent | y | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.pow([3, 5], 2, out=y) + +# Paddle 写法 +paddle.assign(paddle.pow([3, 5], 2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.prod.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.prod.md new file mode 100644 index 00000000000..a8536cff8ab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.prod.md @@ -0,0 +1,30 @@ +## [ 仅参数名不一致 ]torch.prod +### [torch.prod](https://pytorch.org/docs/stable/generated/torch.prod.html?highlight=prod#torch.prod) + + +```python +torch.prod(input, + dim=None, + keepdim=False, + dtype=None) +``` + +### [paddle.prod](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/prod_cn.html#prod) + +```python +paddle.prod(x, + axis=None, + keepdim=False, + dtype=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行乘积运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 表示是否在输出 Tensor 中保留减小的维度。 | +| dtype | dtype | 表示数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.qr.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.qr.md new file mode 100644 index 00000000000..c848145b57c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.qr.md @@ -0,0 +1,50 @@ +## [ torch 参数更多 ] torch.qr + +### [torch.qr](https://pytorch.org/docs/stable/generated/torch.qr.html#torch.qr) + +```python +torch.qr(input, some=True, *, out=None) +``` + +### [paddle.linalg.qr](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/qr_cn.html#qr) + +```python +paddle.linalg.qr(x, mode='reduced', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor,仅参数名不一致。 | +| some | mode | 表示 QR 分解的行为。 需进行转写。 | +| out | - | 表示输出的 Tensor 元组。 Paddle 无此参数,需要转写。 | + +### 转写示例 +### some:控制 QR 分解的行为 +```python +# 当进行完整的 QR 分解时 +# PyTorch 写法 +q, r = torch.qr(x, some=False) + +# Paddle 写法 +q, r = paddle.linalg.qr(x, mode='complete') + +#当进行减少的 QR 分解时 +# PyTorch 写法 +q, r = torch.qr(x, some=True) + +# Paddle 写法 +q, r = paddle.linalg.qr(x, mode='reduced') +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.qr(x, out = (q, r) ) + +# Paddle 写法 +q, r = paddle.linalg.qr(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.quantile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.quantile.md new file mode 100644 index 00000000000..c719f1a03fa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.quantile.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.quantile + +### [torch.quantile](https://pytorch.org/docs/stable/generated/torch.quantile.html?highlight=quantile#torch.quantile) + +```python +torch.quantile(input, + q, + dim=None, + keepdim=False, + *, + interpolation='linear', + out=None) +``` + +### [paddle.quantile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/quantile_cn.html) + +```python +paddle.quantile(x, + q, + axis=None, + keepdim=False, + interpolation='linear', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| q | q | 待计算的分位数。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| interpolation | interpolation | 当所需分位数位于两个数据点之间时使用的插值方法。| +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.quantile(torch.tensor([0., 1., 2., 3.]), 0.6, interpolation='linear', out=y) + +# Paddle 写法 +paddle.assign(paddle.quantile(paddle.to_tensor([0., 1., 2., 3.]), 0.6, interpolation='linear'), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rad2deg.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rad2deg.md new file mode 100644 index 00000000000..59d7c6df202 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rad2deg.md @@ -0,0 +1,32 @@ +## [torch 参数更多 ]torch.rad2deg + +### [torch.rad2deg](https://pytorch.org/docs/stable/generated/torch.rad2deg.html?highlight=torch+rad2deg#torch.rad2deg) + +```python +torch.rad2deg(input, *, out=None) +``` + +### [paddle.rad2deg](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/rad2deg_cn.html) + +```python +paddle.rad2deg(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.rad2deg(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.rad2deg(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand.md new file mode 100644 index 00000000000..e827e1d4b8c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand.md @@ -0,0 +1,73 @@ +## [ 参数不一致 ]torch.rand + +### [torch.rand](https://pytorch.org/docs/stable/generated/torch.rand.html?highlight=rand#torch.rand) + +```python +torch.rand(*size, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.rand](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/rand_cn.html#rand) + +```python +paddle.rand(shape, + dtype=None, + name=None) +``` + +其中 torch 的 `size` 和 paddle 的 `shape` 用法不一致,torch 还支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *size | shape | 表示输出形状大小,PyTorch 以可变参数方式传入,Paddle 以 list 或 tuple 的方式传入。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数。 | +| dtype | dtype | 表示数据类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### *size:输出形状大小 +```python +# PyTorch 写法 +torch.rand(3, 5) + +# Paddle 写法 +paddle.rand([3, 5]) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.rand([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.rand([3, 5]), y) +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.rand(3, 5, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.rand([3, 5]) +y.cpu() +``` + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.rand([3, 5], requires_grad=True) + +# Paddle 写法 +x = paddle.rand([3, 5]) +x.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand_like.md new file mode 100644 index 00000000000..5b2fe04582c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rand_like.md @@ -0,0 +1,39 @@ +## [ 组合替代实现 ]torch.rand_like + +### [torch.rand_like](https://pytorch.org/docs/stable/generated/torch.rand_like.html#torch.rand_like) +```python +torch.rand_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) +``` + +返回与输入相同大小的张量,该张量由区间[0,1)上均匀分布的随机数填充。 + +### 参数介绍 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | - | 表示输入的 Tensor | +| dtype | - | 表示数据类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放位置,Paddle 无此参数,需要转写。 | +| requires_grad | stop_gradient | 表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +#### input:表示输入的 Tensor +```python +# PyTorch 写法 +torch.rand_like(x) + +# Paddle 写法 +paddle.rand(shape=x.shape, dtype=x.dtype) +``` + +#### dtype:表示数据类型 +```python +# PyTorch 写法 +torch.rand_like(x,dtype=torch.float64) + +# Paddle 写法 +paddle.rand(shape=x.shape, dtype=paddle.float64) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint.md new file mode 100644 index 00000000000..a8939aedef8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint.md @@ -0,0 +1,70 @@ +## [torch 参数更多 ]torch.randint +### [torch.randint](https://pytorch.org/docs/stable/generated/torch.randint.html?highlight=randint#torch.randint) +```python +torch.randint(low=0, + high, + size, + *, + generator=None, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.randint](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/randint_cn.html#randint) +```python +paddle.randint(low=0, + high=None, + shape=[1], + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| low | low | 表示生成的随机值范围的下限(区间一般包含)。 | +| high | high | 表示生成的随机值范围的上限(区间一般不包含)。 | +| size | shape | 表示输出形状大小。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示数据类型。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.randint(10, (2, 2), out=y) + +# Paddle 写法 +paddle.assign(paddle.randint(10, shape=[2, 2]), y) +``` + + +#### requires_grad:是否求梯度 +```python +# PyTorch 写法 +x = torch.randint(10, (2, 2), requires_grad=True) + +# Paddle 写法 +x = paddle.randint(10, shape=[2, 2]) +x.stop_gradient = False +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.randint(10, (2, 2), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.randint(10, shape=[2, 2]) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint_like.md new file mode 100644 index 00000000000..d1ed0d3c5a7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randint_like.md @@ -0,0 +1,65 @@ +## [torch 参数更多 ]torch.randint_like + +### [torch.randint_like](https://pytorch.org/docs/stable/generated/torch.randint_like.html?highlight=randint_like#torch.randint_like) + +```python +torch.randint_like(input, + low=0, + high, + *, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False, + memory_format=torch.preserve_format) +``` + +### [paddle.randint_like](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/randint_like_cn.html) + +```python +paddle.randint_like(x, + low=0, + high=None, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| low | low | 表示生成的随机值范围的下限(区间一般包含)。 | +| high | high | 表示生成的随机值范围的上限(区间一般不包含)。 | +| dtype | dtype | 表示数据类型。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +torch.randint_like(x, 10, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.randint_like(x, 10) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +x = torch.randint_like(x, 10, requires_grad=True) + +# Paddle 写法 +x = paddle.randint_like(x, 10) +x.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn.md new file mode 100644 index 00000000000..e925c9dd6be --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn.md @@ -0,0 +1,74 @@ +## [ 参数不一致 ]torch.randn + +### [torch.randn](https://pytorch.org/docs/stable/generated/torch.randn.html?highlight=randn#torch.randn) + +```python +torch.randn(*size, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.randn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/randn_cn.html#randn) + +```python +paddle.randn(shape, + dtype=None, + name=None) +``` + +其中 torch 的 `size` 和 paddle 的 `shape` 用法不一致,torch 还支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *size | shape | 表示输出形状大小,PyTorch 以可变参数方式传入,Paddle 以 list 或 tuple 的方式传入。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 的数据类型。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | + + + +### 转写示例 +#### *size:输出形状大小 +```python +# PyTorch 写法 +torch.randn(3, 5) + +# Paddle 写法 +paddle.randn([3, 5]) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.randn([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.randn([3, 5]), y) +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.randn((2, 2), device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.randn([2, 2]) +y.cpu() +``` + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.randn([3, 5], requires_grad=True) + +# Paddle 写法 +x = paddle.randn([3, 5]) +x.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn_like.md new file mode 100644 index 00000000000..24d09c1c3bf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randn_like.md @@ -0,0 +1,49 @@ +## [ 组合替代实现 ]torch.randn_like + +### [torch.randn_like](https://pytorch.org/docs/stable/generated/torch.randn_like.html#torch.randn_like) +```python +torch.randn_like(input, *, dtype=None, layout=None, device=None, requires_grad=False, memory_format=torch.preserve_format) +``` + +返回与输入相同大小的张量,该张量由区间[0,1)上均匀分布的随机数填充。 + +### 参数介绍 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | - | 表示输入的 Tensor | +| dtype | - | 表示数据类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放位置,Paddle 无此参数,需要转写。 | +| requires_grad | stop_gradient | 表示是否不阻断梯度传导,Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +#### input:表示输入的 Tensor +```python +# PyTorch 写法 +torch.randn_like(x) + +# Paddle 写法 +paddle.randn(shape=x.shape, dtype=x.dtype) +``` + +#### dtype:表示数据类型 +```python +# PyTorch 写法 +torch.randn_like(x,dtype=torch.float64) + +# Paddle 写法 +paddle.randn(shape=x.shape, dtype=paddle.float64) +``` + +#### requires_grad:表示是否不阻断梯度传导 +```python +# PyTorch 写法 +y = torch.randn_like(x,requires_grad=True) + +# Paddle 写法 +y = paddle.randn(shape=x.shape, dtype=x.dtype) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randperm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randperm.md new file mode 100644 index 00000000000..67fbed77388 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.randperm.md @@ -0,0 +1,83 @@ +## [torch 参数更多 ]torch.randperm + +### [torch.randperm](https://pytorch.org/docs/stable/generated/torch.randperm.html?highlight=rand#torch.randperm) + +```python +torch.randperm(n, + *, + generator=None, + out=None, + dtype=torch.int64, + layout=torch.strided, + device=None, + requires_grad=False, + pin_memory=False) +``` + +### [paddle.randperm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/randperm_cn.html#randperm) + +```python +paddle.randperm(n, + dtype='int64', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| n | n | 表示随机序列的上限。 | +| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示数据类型。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | +| pin_memeory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.randperm(10, out=y) + +# Paddle 写法 +paddle.assign(paddle.randperm(10), y) +``` + + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +x = torch.randperm(10, dtype=torch.float64,requires_grad=True) + +# Paddle 写法 +x = paddle.randperm(10) +x.stop_gradient = False +``` + +#### pin_memory:是否分配到固定内存上 + +```python +# PyTorch 写法 +x = torch.randperm(10, pin_memory=True) + +# Paddle 写法 +x = paddle.randperm(10).pin_memory() +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +torch.randperm(10, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.randperm(10) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.range.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.range.md new file mode 100644 index 00000000000..c64a77933e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.range.md @@ -0,0 +1,74 @@ +## [torch 参数更多]torch.range + +### [torch.range](https://pytorch.org/docs/stable/generated/torch.range.html?highlight=range#torch.range) + +```python +torch.range(start=0, + end, + step=1, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.arange](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/arange_cn.html) + +```python +paddle.arange(start=0, + end=None, + step=1, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| start | start | 表示区间起点(且区间包括此值)。 | +| end | end | 表示区间终点(且通常区间不包括此值)。 | +| step | step | 表示均匀分割的步长。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.range(5, out=y) + +# Paddle 写法 +paddle.assign(paddle.arange(5), y) +``` + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.range(5, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.arange(5) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.range(5, requires_grad=True) + +# Paddle 写法 +y = paddle.arange(5) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ravel.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ravel.md new file mode 100644 index 00000000000..e74dca60eae --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.ravel.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.ravel +### [torch.ravel](https://pytorch.org/docs/stable/generated/torch.ravel.html?highlight=ravel#torch.ravel) + +```python +torch.ravel(input) +``` + +### [paddle.flatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/flatten_cn.html) + +```python +paddle.flatten(x, start_axis=0, stop_axis=- 1, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | start_axis | 表示 flatten 展开的起始维度, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | stop_axis | 表示 flatten 展开的结束维度, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.real.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.real.md new file mode 100644 index 00000000000..5389f88543f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.real.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.real +### [torch.real](https://pytorch.org/docs/stable/generated/torch.real.html?highlight=real#torch.real) + +```python +torch.real(input) +``` + +### [paddle.real](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/real_cn.html#real) + +```python +paddle.real(x) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor , 仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reciprocal.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reciprocal.md new file mode 100644 index 00000000000..5e749f06326 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reciprocal.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.reciprocal + +### [torch.reciprocal](https://pytorch.org/docs/stable/generated/torch.reciprocal.html?highlight=torch+reciprocal#torch.reciprocal) + +```python +torch.reciprocal(input, + *, + out=None) +``` + +### [paddle.reciprocal](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/reciprocal_cn.html) + +```python +paddle.reciprocal(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.reciprocal([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.reciprocal([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.relu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.relu.md new file mode 100644 index 00000000000..82cbd174c86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.relu.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.relu + +### [torch.relu]() + +```python +torch.relu(input) +``` + +### [paddle.nn.functional.relu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/relu_cn.html#relu) + +```python +paddle.nn.functional.relu(x, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.remainder.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.remainder.md new file mode 100644 index 00000000000..901431a29f7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.remainder.md @@ -0,0 +1,37 @@ +## [torch 参数更多 ]torch.remainder +### [torch.remainder](https://pytorch.org/docs/stable/generated/torch.remainder.html?highlight=remainder#torch.remainder) + +```python +torch.remainder(input, + other, + *, + out=None) +``` + +### [paddle.remainder](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/remainder_cn.html#remainder) + +```python +paddle.remainder(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 被除数,PyTorch 可为 Tensor or Scalar,Paddle 仅可为 Tensor。 | +| other | y | 除数,PyTorch 可为 Tensor or Scalar,Paddle 仅可为 Tensor。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.remainder([3, 5], 2, out=y) + +# Paddle 写法 +paddle.assign(paddle.remainder([3, 5], 2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.renorm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.renorm.md new file mode 100644 index 00000000000..a6310dc42fb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.renorm.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.renorm + +### [torch.renorm](https://pytorch.org/docs/stable/generated/torch.renorm.html#torch-renorm) + +```python +torch.renorm(input, p, dim, maxnorm, *, out=None) +``` + +### [paddle.renorm]() + +```python +paddle.renorm(input, p, axis, max_norm) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | input | 表示输入的 Tensor 。 | +| p | p | 表示 p-范数计算的 p 值。| +| dim | axis | 表示切分的维度,仅参数名不一致。 | +| maxnorm | max_norm | 表示子张量的 p-范数最大值,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.renorm(x, 1, 0, 5, out=output) + +# Paddle 写法 +paddle.assign(paddle.renorm(x, 1, 0, 5), output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.repeat_interleave.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.repeat_interleave.md new file mode 100644 index 00000000000..920346fecfe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.repeat_interleave.md @@ -0,0 +1,24 @@ +## [ torch 参数更多]torch.repeat_interleave + +### [torch.repeat_interleave](https://pytorch.org/docs/stable/generated/torch.repeat_interleave.html#torch-repeat-interleave) + +```python +torch.repeat_interleave(input, repeats, dim=None, *, output_size=None) +``` + +### [paddle.repeat_interleave](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/repeat_interleave_cn.html#repeat-interleave) + +```python +paddle.repeat_interleave(x, repeats, axis=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| repeats | repeats | 表示指定复制次数的 1-D Tensor 或指定的复制次数。 | +| dim | axis | 表示复制取值的维度,仅参数名不一致。 | +| output_size | - | 表示给定维度的总输出尺寸,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reshape.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reshape.md new file mode 100644 index 00000000000..983fcede165 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.reshape.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.reshape +### [torch.reshape](https://pytorch.org/docs/stable/generated/torch.reshape.html?highlight=reshape#torch.reshape) + +```python +torch.reshape(input, + shape) +``` + +### [paddle.reshape](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/reshape_cn.html#reshape) + +```python +paddle.reshape(x, + shape, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 N-D Tensor ,仅参数名不一致。 | +| shape | shape | 表示输出 Tensor 的 shape 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.roll.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.roll.md new file mode 100644 index 00000000000..7d57add8d8d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.roll.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.roll +### [torch.roll](https://pytorch.org/docs/stable/generated/torch.roll.html?highlight=roll#torch.roll) + +```python +torch.roll(input, + shifts, + dims=None) +``` + +### [paddle.roll](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/roll_cn.html#roll) + +```python +paddle.roll(x, + shifts, + axis=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| shifts | shifts | 表示偏移量。 | +| dims | axis | 表示滚动的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rot90.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rot90.md new file mode 100644 index 00000000000..5ea88710035 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rot90.md @@ -0,0 +1,26 @@ +## [仅参数名不一致]torch.rot90 + +### [torch.rot90](https://pytorch.org/docs/stable/generated/torch.rot90.html?highlight=torch+rot90#torch.rot90) +```python +torch.rot90(input, + k=1, + dims=[0, 1]) +``` + +### [paddle.rot90](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/rot90_cn.html#rot90) + +```python +paddle.rot90(x, + k=1, + axes=[0, 1], + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| k | k | 表示旋转方向和次数。 | +| dims | axes | axes 指定旋转的平面,维度必须为 2 ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.round.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.round.md new file mode 100644 index 00000000000..7ed8ad72678 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.round.md @@ -0,0 +1,47 @@ +## [torch 参数更多 ]torch.round +### [torch.round](https://pytorch.org/docs/stable/generated/torch.round.html?highlight=round#torch.round) + +```python +torch.round(input, + *, + decimals=0, + out=None) +``` + +### [paddle.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/round_cn.html#round) + +```python +paddle.round(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| decimals | - | 要舍入到的小数位数,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### decimals:要舍入到的小数位数 +```python +# PyTorch 写法 +torch.round([3.345, 5.774], decimals=2) + +# Paddle 写法 +paddle.round(1e2 * [3.345, 5.774]) / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.round([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.round([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.row_stack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.row_stack.md new file mode 100644 index 00000000000..dc9497a88fc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.row_stack.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.row_stack + +### [torch.row_stack](https://pytorch.org/docs/stable/generated/torch.row_stack.html#torch.row_stack) + +```python +torch.row_stack(tensors, *, out=None) +``` + +### [paddle.row_stack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/row_stack_cn.html) + +```python +paddle.row_stack(x, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rrelu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rrelu.md new file mode 100644 index 00000000000..9b02f7f6bd7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rrelu.md @@ -0,0 +1,24 @@ +## [ 仅参数默认值不一致 ]torch.rrelu + +### [torch.rrelu](https://pytorch.org/docs/stable/generated/torch.nn.functional.rrelu.html#torch.nn.functional.rrelu) + +```python +torch.rrelu(input, lower=1./8, upper=1./3, training=False) +``` + +### [paddle.nn.functional.rrelu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/rrelu_cn.html) + +```python +paddle.nn.functional.rrelu(x, lower=1./8, upper=1./3, training=True, name=None) +``` + +其中 PyTorch 和 Paddle 功能一致,仅参数名与参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| lower | lower | 负值斜率的随机值范围下限。 | +| upper | upper | 负值斜率的随机值范围上限。 | +| training | training | 标记是否为训练阶段,仅参数默认值不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rsqrt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rsqrt.md new file mode 100644 index 00000000000..50038ac5863 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.rsqrt.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.rsqrt +### [torch.rsqrt](https://pytorch.org/docs/stable/generated/torch.rsqrt.html?highlight=rsqrt#torch.rsqrt) + +```python +torch.rsqrt(input, + *, + out=None) +``` + +### [paddle.rsqrt](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/rsqrt_cn.html#rsqrt) + +```python +paddle.rsqrt(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.rsqrt([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.rsqrt([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.save.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.save.md new file mode 100644 index 00000000000..1ad263bf855 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.save.md @@ -0,0 +1,29 @@ +## [torch 参数更多 ]torch.save +### [torch.save](https://pytorch.org/docs/stable/generated/torch.save.html?highlight=save#torch.save) + +```python +torch.save(obj, + f, + pickle_module=pickle, + pickle_protocol=DEFAULT_PROTOCOL, + _use_new_zipfile_serialization=True) +``` + +### [paddle.save](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/save_cn.html#save) + +```python +paddle.save(obj, + path, + protocol=4) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| obj | obj | 要保存的对象实例,torch 支持 io.BytesIO、io.StringIO、文件,paddle 只支持文件,暂无转写方式。| +| f | path | 表示存储的路径。 | +| pickle_module | - | 表示用于 pickling 元数据和对象的模块,Paddle 无此参数,暂无转写方式。 | +| pickle_protocol| protocol | pickle 模块的协议版本。 | +| _use_new_zipfile_serialization | - | 是否以旧格式加载文件,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scalar_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scalar_tensor.md new file mode 100644 index 00000000000..76f8c310c53 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scalar_tensor.md @@ -0,0 +1,60 @@ +## [torch 参数更多 ]torch.scalar_tensor +### [torch.scalar_tensor] + +```python +torch.scalar_tensor(s, + dtype=torch.float32, + layout=torch.strided, + device=None, + requires_grad=False, + pin_memory=False) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, + dtype=None, + place=None, + stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| s | data | 表示输入的数据。 | +| dtype | dtype | 表示数据的类型。两者参数默认值不同,Paddle 应设置为 paddle.float32。 | +| layout | - | 数据布局格式,Paddle 无此参数。一般对训练结果影响不大,可直接删除。 | +| device | place | 表示 Tensor 存放设备位置,两者参数类型不相同,需要转写。 | +| requires_grad | stop_gradient | 表示是否计算梯度, 两者参数意义不相同,Paddle 输入与 PyTorch 逻辑相反。需要转写。 | +| pin_memeory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 Paddle 需要对结果使用 padlde.Tensor.pin_memory()。 | + +### 转写示例 +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.tensor(3, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.to_tensor(3, dtype=paddle.float32, place=paddle.CPUPlace()) +``` + +#### requires_grad:是否不阻断梯度传导 +```python +# PyTorch 写法 +x = torch.tensor(3, requires_grad=True) + +# Paddle 写法 +x = paddle.to_tensor(3, dtype=paddle.float32, stop_gradient=False) +``` + +#### pin_memory:是否分配到固定内存上 +```python +# PyTorch 写法 +x = torch.tensor(3, pin_memory=True) + +# Paddle 写法 +x = paddle.to_tensor(3, dtype=paddle.float32).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md new file mode 100644 index 00000000000..91ca1c61dd3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter.md @@ -0,0 +1,47 @@ +## [torch 参数更多]torch.scatter + +### [torch.scatter](https://pytorch.org/docs/2.0/generated/torch.scatter.html?highlight=torch+scatter#torch.scatter) + +```python +torch.scatter(input,dim, index, src, reduce=None,out=None) +``` + +### [paddle.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/put_along_axis_cn.html#cn-api-paddle-tensor-put-along-axis) + +```python +paddle.put_along_axis(arr,indices, values, axis, reduce="assign", include_self=True, broadcast=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------- | +| input | arr | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| reduce | reduce | 归约操作类型 。 | +| - | include_self | 表示插入 values 时是否包含 arr 中的元素,PyTorch 无此参数| +| - | broadcast | 表示是否需要广播 indices 矩阵,PyTorch 无此参数,Paddle 应设置为 'False' 结果才与 pytorch 一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +index = torch.tensor([[0],[1],[2]]) +input = torch.zeros(3, 5) +out = torch.zeros(3, 5) +torch.scatter(input,1, index, 1.0,out=out) + +# Paddle 写法 +index = paddle.to_tensor(data=[[0], [1], [2]]) +input = paddle.zeros(shape=[3, 5]) +out = paddle.zeros(shape=[3, 5]) +paddle.assign(paddle.put_along_axis(input, 1, index, 1.0), output=out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter_add.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter_add.md new file mode 100644 index 00000000000..0cbf374643b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.scatter_add.md @@ -0,0 +1,35 @@ +## [ 仅 paddle 参数更多 ]torch.scatter_add + +### [torch.scatter_add](https://pytorch.org/docs/stable/generated/torch.scatter_add.html#torch.scatter_add) + +```python +torch.scatter_add(input, + dim, + index, + src) +``` + +### [paddle.put_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/put_along_axis_cn.html) + +```python +paddle.put_along_axis(arr, + indices, + values, + axis, + reduce='assign', + include_self=True, + broadcast=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | arr | 表示输入 Tensor ,仅参数名不一致。 | +| dim | axis | 表示在哪一个维度 scatter ,仅参数名不一致。 | +| index | indices | 表示输入的索引张量,仅参数名不一致。 | +| src | values | 表示需要插入的值,仅参数名不一致。 | +| - | reduce | 表示插入 values 时的计算方式,PyTorch 无此参数,Paddle 应设置为 'add' 。 | +| - | include_self | 表示插入 values 时是否包含 arr 中的元素,PyTorch 无此参数,Paddle 应设置为 'True' 。 | +| - | broadcast | 表示是否需要广播 indices 矩阵,PyTorch 无此参数,Paddle 应设置为 'False' 结果才与 pytorch 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.searchsorted.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.searchsorted.md new file mode 100644 index 00000000000..586e5c4ba68 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.searchsorted.md @@ -0,0 +1,69 @@ +## [ torch 参数更多]torch.searchsorted + +### [torch.searchsorted](https://pytorch.org/docs/stable/generated/torch.searchsorted.html#torch-searchsorted) + +```python +torch.searchsorted(sorted_sequence, + values, + *, + out_int32=False, + right=False, + side='left', + out=None, + sorter=None) +``` + +### [paddle.searchsorted](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/searchsorted_cn.html#searchsorted) + +```python +paddle.searchsorted(sorted_sequence, + values, + out_int32=False, + right=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------- | +| sorted_sequence | sorted_sequence | 表示待查找的 Tensor 。 | +| values | values | 表示用于查找的 Tensor。 | +| out_int32 | out_int32 | 表示输出的数据类型。 | +| right | right | 表示查找对应的上边界或下边界。 | +| side | - | 表示查找对应的上边界或下边界,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | +| sorter | - | 表示 sorted_sequence 元素无序时对应的升序索引,Paddle 无此参数,一般对网络训练结果影响不大。需要转写。 | + +### 转写示例 +#### side:指定查找对应的上边界或下边界 + +```python +# PyTorch 写法 +torch.searchsorted(x,y, side='right') + +# Paddle 写法 +paddle.searchsorted(x,y,right=True) +``` + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.searchsorted(x,y, out=output) + +# Paddle 写法 +paddle.assign(paddle.searchsorted(x,y), output) +``` + +#### sorter: 提供 sorted_sequence 为无序 Tensor 时,相对应的升序索引 + +```python +# PyTorch 写法 +torch.searchsorted(x,y, sorter=sorter) + +# Paddle 写法 +paddle.searchsorted(x.take_along_axis(axis = -1, indices = sorter), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.seed.md new file mode 100644 index 00000000000..4ea864f3a79 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.seed.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.seed + +### [torch.seed](https://pytorch.org/docs/stable/generated/torch.seed.html#torch.seed) +```python +torch.seed() +``` + +将生成随机数的种子设置为非确定性随机数。返回一个用于播种 RNG 的 64 位数字。 + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +```python +# PyTorch 写法 +torch.seed() + +# Paddle 写法 +paddle.get_rng_state()[0].current_seed() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select.md new file mode 100644 index 00000000000..f01ec665f40 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.select + +### [torch.select](https://pytorch.org/docs/stable/generated/torch.select.html#torch.select) + +```python +torch.select(input, dim, index) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.select(a, dim=dim, index=index) + +# Paddle 写法 +y = paddle.index_select(a, index=paddle.to_tensor([index]), axis=dim).squeeze(dim) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select_scatter.md new file mode 100644 index 00000000000..949b48ce947 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.select_scatter.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ] torch.select_scatter + +### [torch.select_scatter](https://pytorch.org/docs/stable/generated/torch.select_scatter.html#torch-select-scatter) + +```python +torch.select_scatter(input, src, dim, index) +``` + +### [paddle.select_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/select_scatter_cn.html) + +```python +paddle.select_scatter(x, values, axis, index, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------- | +| input | x | 输入张量,被嵌入的张量,仅参数名不一致。 | +| src | values | 用于嵌入的张量,仅参数名不一致。 | +| dim | axis | 嵌入的维度,仅参数名不一致。 | +| index | index | 选择的索引。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.selu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.selu.md new file mode 100644 index 00000000000..1eb744e4a21 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.selu.md @@ -0,0 +1,23 @@ +## [仅 paddle 参数更多]torch.selu + +### [torch.selu](https://pytorch.org/docs/stable/generated/torch.nn.functional.selu.html#torch.nn.functional.selu) + +```python +torch.selu(input) +``` + +### [paddle.nn.functional.selu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/selu_cn.html) + +```python +paddle.nn.functional.selu(x, scale=1.0507009873554804934193349852946, alpha=1.6732632423543772848170429916717, name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| - | scale | selu 激活计算公式中的 scale 值,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | alpha | selu 激活计算公式中的 alpha 值,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_default_tensor_type.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_default_tensor_type.md new file mode 100644 index 00000000000..7e893ed2bd7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_default_tensor_type.md @@ -0,0 +1,33 @@ +## [ 参数不一致 ]torch.set_default_tensor_type + +### [torch.set\_default\_tensor\_type](https://pytorch.org/docs/stable/generated/torch.set_default_tensor_type.html) + +```python +torch.set_default_tensor_type(t) +``` + +### [paddle.set\_default\_dtype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/set_default_dtype_cn.html#set-default-dtype) + +```python +paddle.set_default_dtype(d) +``` + +其中 PyTorch 与 Paddle 的参数类型不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| t | d | 指定的默认张量类型,参数类型不一致。PyTorch 支持张量类型或其名称字符串(如 `torch.FloatTensor`,Paddle 支持直接指定 `dtype`(如 `paddle.float32`),需要转写。 | + +### 转写示例 + +#### t 张量类型 + +```python +# PyTorch +torch.set_default_tensor_type(torch.FloatTensor) + +# Paddle +paddle.set_default_dtype(paddle.float32) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md new file mode 100644 index 00000000000..f976612710c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_printoptions.md @@ -0,0 +1,58 @@ +## [ torch 参数更多 ]torch.set_printoptions + +### [torch.set_printoptions](https://pytorch.org/docs/stable/generated/torch.set_printoptions.html?highlight=torch+set_printoptions#torch.set_printoptions) + +```python +torch.set_printoptions(precision=None, threshold=None, edgeitems=None, linewidth=None, profile=None, sci_mode=None) +``` + +### [paddle.set_printoptions](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/set_printoptions_cn.html) + +```python +paddle.set_printoptions(precision=None, threshold=None, edgeitems=None, sci_mode=None, linewidth=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | ------------ | ------------------------------------------------------------ | +| precision | precision | 浮点数的小数位数, PyTorch 默认值为 4,Paddle 默认为 8。 | +| threshold | threshold | 打印的元素个数上限,默认值为 1000。 | +| edgeitems | edgeitems | 以缩略形式打印时左右两边的元素个数,默认值为 3。 | +| linewidth | linewidth | 每行的字符数,默认值为 80。 | +| sci_mode | sci_mode | 是否以科学计数法打印,PyTorch 默认根据网络自动选择, Paddle 默认值为 False。 | +| profile | - | 预设风格,支持 `default`, `short`, `full`。 Paddle 无此参数, 需要转写。 | + +### 转写示例 + +#### profile:预设风格,设置为 `default`。 + +```python +# PyTorch 写法 +torch.set_printoptions(profile='default') + +# Paddle 写法 +paddle.set_printoptions(precision=4, threshold=1000, edgeitems=3, linewidth=80) +``` + +#### profile:预设风格,设置为 `short`。 + +```python +# PyTorch 写法 +torch.set_printoptions(profile='short') + +# Paddle 写法 +paddle.set_printoptions(precision=2, threshold=1000, edgeitems=2, linewidth=80) +``` + +#### profile:预设风格,设置为 `full`。 + +```python +# PyTorch 写法 +torch.set_printoptions(profile='full') + +# Paddle 写法 +paddle.set_printoptions(precision=4, threshold=1000000, edgeitems=3, linewidth=80) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_rng_state.md new file mode 100644 index 00000000000..3ddb6998f3e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.set_rng_state.md @@ -0,0 +1,34 @@ +## [参数不一致] torch.set_rng_state + +### [torch.set_rng_state](https://pytorch.org/docs/stable/generated/torch.set_rng_state.html#torch.set_rng_state) + +```python +torch.set_rng_state(new_state) +``` + +### [paddle.set_rng_state]() + +```python +paddle.set_rng_state(state_list) +``` + +其中 PyTorch 与 Paddle 的输入参数类型不一致 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| new_state | state_list | 表示需要设置的新状态,PyTorch 输入类型为 torch.ByteTensor, Paddle 为 list[GeneratorState] | + + + +### 转写示例 + +#### new_state: 指定输入 +```python +# PyTorch 写法 +torch.set_rng_state(x) + +# Paddle 写法 +paddle.set_rng_state(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sgn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sgn.md new file mode 100644 index 00000000000..a57bd8f2d5d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sgn.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.sgn +### [torch.sgn](https://pytorch.org/docs/stable/generated/torch.sgn.html?highlight=torch+sgn#torch.sgn) + +```python +torch.sgn(input, + *, + out=None) +``` + +### [paddle.sgn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sgn_cn.html) + +```python +paddle.sgn(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sgn([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.sgn([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sigmoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sigmoid.md new file mode 100644 index 00000000000..eebfae2da44 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sigmoid.md @@ -0,0 +1,30 @@ +## [torch 参数更多 ]torch.sigmoid +### [torch.sigmoid](https://pytorch.org/docs/stable/generated/torch.sigmoid.html?highlight=sigmoid#torch.sigmoid) + +```python +torch.sigmoid(input, *, out=None) +``` + +### [paddle.nn.functional.sigmoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/sigmoid_cn.html#sigmoid) + +```python +paddle.nn.functional.sigmoid(x, name=None) +``` + +功能一致,torch 参数更多,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sigmoid(input, out=z) + +# Paddle 写法 +paddle.assign(paddle.nn.functional.sigmoid(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sign.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sign.md new file mode 100644 index 00000000000..283559b6b50 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sign.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.sign +### [torch.sign](https://pytorch.org/docs/stable/generated/torch.sign.html?highlight=sign#torch.sign) + +```python +torch.sign(input, + *, + out=None) +``` + +### [paddle.sign](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sign_cn.html#sign) + +```python +paddle.sign(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sign([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.sign([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.signbit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.signbit.md new file mode 100644 index 00000000000..5b1d6825252 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.signbit.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.signbit + +### [torch.signbit](https://pytorch.org/docs/stable/generated/torch.signbit.html#torch-signbit) + +```python +torch.signbit(input, *, out=None) +``` + +### [paddle.signbit](https://github.com/PaddlePaddle/Paddle/blob/9ce3a54f456011c664c70fbcd318f2e1af0a7d81/python/paddle/tensor/math.py#L7175) + +```python +paddle.signbit(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.signbit([1., 2., 3., -1.], out=y) + +# Paddle 写法 +paddle.assign(paddle.signbit([1., 2., 3., -1.]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sin.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sin.md new file mode 100644 index 00000000000..d3f0fe321ae --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sin.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.sin +### [torch.sin](https://pytorch.org/docs/stable/generated/torch.sin.html?highlight=sin#torch.sin) + +```python +torch.sin(input, + *, + out=None) +``` + +### [paddle.sin](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sin_cn.html#sin) + +```python +paddle.sin(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sin([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.sin([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinc.md new file mode 100644 index 00000000000..bd97c9609a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinc.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.sinc + +### [torch.sinc](https://pytorch.org/docs/stable/generated/torch.sinc.html#torch.sinc) + +```python +torch.sinc(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.sinc(a) + +# Paddle 写法 +import numpy +y = paddle.where(a==0, x=paddle.to_tensor([1], dtype=a.dtype), y=paddle.sin(numpy.pi*a)/(numpy.pi*a)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinh.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinh.md new file mode 100644 index 00000000000..967f1dd383c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sinh.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.sinh +### [torch.sinh](https://pytorch.org/docs/stable/generated/torch.sinh.html?highlight=sinh#torch.sinh) + +```python +torch.sinh(input, + *, + out=None) +``` + +### [paddle.sinh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sinh_cn.html#sinh) + +```python +paddle.sinh(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sinh([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.sinh([3, 5]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slice_scatter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slice_scatter.md new file mode 100644 index 00000000000..5ade4a9d99f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slice_scatter.md @@ -0,0 +1,36 @@ +## [ 参数不一致 ]torch.slice_scatter + +### [torch.slice_scatter](https://pytorch.org/docs/stable/generated/torch.slice_scatter.html#torch.slice_scatter) + +```python +torch.slice_scatter(input, src, dim=0, start=None, end=None, step=1) +``` + +### [paddle.slice_scatter](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/slice_scatter.html) + +```python +paddle.slice_scatter(x, value, axes, starts, ends, strides, name=None) +``` + +两者功能一致,参数不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的目标矩阵, 仅参数名不一致。 | +| src | value | 嵌入的值,仅参数名不一致。 | +| dim | axes | 嵌入的维度,PyTorch 为 int 类型,Paddle 为 list of int。 | +| start | starts | 嵌入起始索引,PyTorch 为 int 类型,Paddle 为 list of int。 | +| end | ends | 嵌入截至索引,PyTorch 为 int 类型,Paddle 为 list of int。 | +| step | strides | 嵌入步长,PyTorch 为 int 类型,Paddle 为 list of int。 | + +### 转写示例 + +```python +# PyTorch 写法 +torch.slice_scatter(input, src, dim=0, start=1, end=5, step=2) + +# Paddle 写法 +paddle.slice_scatter(x, value, axes=[0], starts=[1], ends=[5], strides=[2]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slogdet.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slogdet.md new file mode 100644 index 00000000000..706345b5616 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.slogdet.md @@ -0,0 +1,47 @@ +## [ 参数不一致 ]torch.slogdet +### [torch.slogdet](https://pytorch.org/docs/stable/generated/torch.slogdet.html?highlight=slogdet#torch.slogdet) + +```python +torch.slogdet(input *, out=None) +``` + +### [paddle.linalg.slogdet](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/slogdet_cn.html#slogdet) + +```python +paddle.linalg.slogdet(x) +``` + +两者功能一致,返回参数的个数不同,PyTorch 返回两个 Tesnor,Paddle 返回一个 Tensor,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tuple ,Paddle 无此参数,需要转写。 | +| 返回值 | 返回值 | PyTorch 返回两个 Tesnor,Paddle 返回一个 Tensor,需要转写。 | + + + +### 转写示例 + +#### 返回值 +```python +# PyTorch 写法 +torch.slogdet(x) + +# Paddle 写法 +y = paddle.linalg.slogdet(x) +(y[0], y[1]) +``` + +#### out:输出的 Tensor +```python +# PyTorch 写法 +torch.slogdet(x, out=(y1, y2)) + +# Paddle 写法 +z = paddle.linalg.slogdet(a) +paddle.assign(z[0], y1) +paddle.assign(z[1], y2) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.softmax.md new file mode 100644 index 00000000000..084bcac6424 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.softmax.md @@ -0,0 +1,36 @@ +## [ torch 参数更多 ]torch.softmax + +### [torch.softmax](https://pytorch.org/docs/stable/generated/torch.softmax.html) + +```python +torch.softmax(input, dim, *, dtype=None, out=None) +``` + +### [paddle.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softmax_cn.html#softmax) + +```python +paddle.nn.functional.softmax(x, axis=-1, dtype=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 表示输入张量,仅参数名不一致。 | +| dim | axis | 表示对输入 Tensor 进行运算的轴,仅参数名不一致。 | +| dtype | dtype | 表示返回张量所需的数据类型。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out + +```python +# PyTorch +torch.softmax(x, dim, out=y) + +# Paddle +paddle.assign(paddle.nn.functional.softmax(x, dim), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sort.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sort.md new file mode 100644 index 00000000000..0f9311303a5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sort.md @@ -0,0 +1,47 @@ +## [ 参数不一致 ]torch.sort + +### [torch.sort](https://pytorch.org/docs/stable/generated/torch.sort.html?highlight=sort#torch.sort) + +```python +torch.sort(input, + dim=-1, + descending=False, + stable=False, + *, + out=None) +``` + +### [paddle.sort](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sort_cn.html#paddle.sort) + +```python +paddle.sort(x, + axis=-1, + descending=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,同时两个 api 的返回参数类型不同,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 指定对输入 Tensor 进行运算的轴。默认值为-1, 仅参数名不一致。 | +| descending |descending | 指定算法排序的方向。如果设置为 True,算法按照降序排序。如果设置为 False 或者不设置,按照升序排序。默认值为 False,参数名相同。 | +| stable | - | 使排序程序更稳定,保证等价元素的顺序得以保留。Paddle 无此参数,对于排序算法的稳定性来说不是很重要,直接删除即可。 | +| out | - | 表示以(Tensor, LongTensor)输出的元组,含义是排序后的返回值和对应元素索引。Paddle 无此参数,若返回排序后的元素,需要转写;若需要返回元素和元素索引,需要结合 argsort 进行转写。 | + +注:PyTorch 返回 (Tensor, LongTensor),Paddle 返回 Tensor 。 + +### 转写示例 +#### out:指定输出 +```python +# 若要返回排序后的元素和元素索引,需要结合 argsort 进行转写 +# PyTorch 写法 +torch.sort(input, -1, True, out = (y, indices)) + +# Paddle 写法 +paddle.assign(paddle.sort(input, -1, True), y) +paddle.assign(paddle.argsort(input, -1, True), indices) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_coo_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_coo_tensor.md new file mode 100644 index 00000000000..515bf9aae26 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_coo_tensor.md @@ -0,0 +1,46 @@ +## [ 参数不一致 ]torch.sparse_coo_tensor + +### [torch.sparse_coo_tensor](https://pytorch.org/docs/stable/generated/torch.sparse_coo_tensor.html?highlight=torch+sparse_coo_tensor#torch.sparse_coo_tensor) + +```python +torch.sparse_coo_tensor(indices,values,size=None, * , dtype=None,device=None,requires_grad=False) +``` + +### [paddle.sparse.sparse_coo_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/sparse_coo_tensor_cn.html#sparse-coo-tensor) + +```python +paddle.sparse.sparse_coo_tensor(indices, values, shape=None, dtype=None, place=None, stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ----------- | ----------------------------------------- | +| indices | indices | 表示初始化 tensor 的数据。 | +| values | values | 表示初始化 tensor 的数据。 | +| dtype | dtype | 表示创建 tensor 的数据类型。 | +| size | shape | 表示张量的大小,仅参数名不一致。 | +| device | place | 表示创建 tensor 的设备位置,仅参数名不一致。 | +| requires_grad | stop_gradient | 两者参数功能相反,需要转写。 | + +### 转写示例 + +```python +# PyTorch 写法 +import torch + +indices = [[0, 1, 2], [1, 2, 0]] +values = [1.0, 2.0, 3.0] +dense_shape = [3, 3] +coo = torch.sparse_coo_tensor(indices, values, dense_shape,requires_grad=False) + +# Paddle 写法 +import paddle + +indices = [[0, 1, 2], [1, 2, 0]] +values = [1.0, 2.0, 3.0] +dense_shape = [3, 3] +coo = paddle.sparse.sparse_coo_tensor(indices, values, dense_shape,stop_gradient= True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_csr_tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_csr_tensor.md new file mode 100644 index 00000000000..7ae394d688e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sparse_csr_tensor.md @@ -0,0 +1,48 @@ +## [torch 参数更多]torch.sparse_csr_tensor + +### [torch.sparse_csr_tensor](https://pytorch.org/docs/stable/generated/torch.sparse_csr_tensor.html#torch.sparse_csr_tensor) + +```python +torch.sparse_csr_tensor(crow_indices, col_indices, values, size=None, *, dtype=None, device=None, requires_grad=False, check_invariants=None) +``` + +### [paddle.sparse.sparse_csr_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/sparse_csr_tensor_cn.html#sparse-csr-tensor) + +```python +paddle.sparse.sparse_csr_tensor(crows, cols, values, shape, dtype=None, place=None, stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------------- | ------------- | -------------------------------------------------------------- | +| crow_indices | crows | 每行第一个非零元素在 values 的起始位置,仅参数名不一致。 | +| col_indices | cols | 一维数组,存储每个非零元素的列信息,仅参数名不一致。 | +| values | values | 一维数组,存储非零元素。 | +| size | shape | 稀疏 Tensor 的形状,仅参数名不一致。 | +| dtype | dtype | 创建 tensor 的数据类型。 | +| device | place | 创建 tensor 的设备位置,仅参数名不一致。 | +| requires_grad | stop_gradient | 是否阻断 Autograd 的梯度传导,两者参数功能相反,需要转写。 | +| check_invariants | - | 是否检查稀疏 Tensor 变量,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### requires_grad 参数:是否阻断 Autograd 的梯度传导 + +```python +# PyTorch 写法 +crows = [0, 2, 3, 5] +cols = [1, 3, 2, 0, 1] +values = [1, 2, 3, 4, 5] +dense_shape = [3, 4] +csr = torch.sparse_csr_tensor(crows, cols, values, dense_shape, requires_grad=False) + +# Paddle 写法 +crows = [0, 2, 3, 5] +cols = [1, 3, 2, 0, 1] +values = [1, 2, 3, 4, 5] +dense_shape = [3, 4] +csr = paddle.sparse.sparse_csr_tensor(crows, cols, values, dense_shape, stop_gradient= True) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.split.md new file mode 100644 index 00000000000..fa5c4d041ce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.split.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ]torch.split +### [torch.split](https://pytorch.org/docs/stable/generated/torch.split.html?highlight=torch%20split#torch.split) + +```python +torch.split(tensor, + split_size_or_sections, + dim=0) +``` + +### [paddle.split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/split_cn.html#split) + +```python +paddle.split(x, + num_or_sections, + axis=0, + name=None) +``` + +其中 PyTorch 的 `split_size_or_sections` 与 Paddle 的 `num_or_sections` 用法不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | x | 表示输入 Tensor ,仅参数名不一致。 | +| `split_size_or_sections`| num_or_sections| 当类型为 int 时,torch 表示单个块大小,paddle 表示结果有多少个块,需要转写。 | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | + + +### 转写示例 +#### split_size_or_sections:单个块大小 +```python +split_size = 2 +dim = 1 +# PyTorch 写法 +torch.split(a, split_size, dim) +# 在输入 dim 时,返回 (values, indices) + +# Paddle 写法 +paddle.split(a, a.shape[dims]/split_size, dim) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sqrt.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sqrt.md new file mode 100644 index 00000000000..c307d01d869 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sqrt.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.sqrt +### [torch.sqrt](https://pytorch.org/docs/stable/generated/torch.sqrt.html?highlight=sqrt#torch.sqrt) + +```python +torch.sqrt(input, + *, + out=None) +``` + +### [paddle.sqrt](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sqrt_cn.html#sqrt) + +```python +paddle.sqrt(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.sqrt([0.1, 0.2], out=y) + +# Paddle 写法 +paddle.assign(paddle.sqrt([0.1, 0.2]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.square.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.square.md new file mode 100644 index 00000000000..8aa7cb862c8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.square.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.square +### [torch.square](https://pytorch.org/docs/stable/generated/torch.square.html?highlight=square#torch.square) + +```python +torch.square(input, + *, + out=None) +``` + +### [paddle.square](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/square_cn.html) + +```python +paddle.square(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.square([0.1, 0.2], out=y) + +# Paddle 写法 +paddle.assign(paddle.square([0.1, 0.2]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.squeeze.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.squeeze.md new file mode 100644 index 00000000000..136d10b5ec8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.squeeze.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.squeeze +### [torch.squeeze](https://pytorch.org/docs/stable/generated/torch.squeeze.html?highlight=squeeze#torch.squeeze) + +```python +torch.squeeze(input, + dim=None) +``` + +### [paddle.squeeze](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/squeeze_cn.html#squeeze) + +```python +paddle.squeeze(x, + axis=None, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示要压缩的轴,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stack.md new file mode 100644 index 00000000000..3d089ffccff --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stack.md @@ -0,0 +1,38 @@ +## [ torch 参数更多 ]torch.stack + +### [torch.stack](https://pytorch.org/docs/stable/generated/torch.stack.html#torch.stack) + +```python +torch.stack(tensors, + dim=0, + *, + out=None) +``` + +### [paddle.stack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/stack_cn.html) + +```python +paddle.stack(x, + axis=0, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示要堆叠的轴,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.stack(torch.tensor([3, 5]), out=y) + +# Paddle 写法 +paddle.assign(paddle.stack(paddle.to_tensor([3, 5])), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std.md new file mode 100644 index 00000000000..bcc431e5807 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std.md @@ -0,0 +1,55 @@ +## [ torch 参数更多 ]torch.std + +### [torch.std](https://pytorch.org/docs/stable/generated/torch.std.html) + +```python +torch.std(input, dim=None, unbiased=True, keepdim=False, *, correction=1, out=None) +``` + +### [paddle.std](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/std_cn.html#std) + +```python +paddle.std(x, axis=None, unbiased=True, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| input | x | 输入张量,仅参数名不一致。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| unbiased | unbiased | 是否使用无偏估计来计算标准差。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| correction | - | 样本尺寸与其自由度的差异,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### correction + +```python +# PyTorch +torch.std(x, dim, correction=0) + +# Paddle +paddle.std(x, dim, unbiased=False) + + +# PyTorch +torch.std(x, dim, correction=1) + +# Paddle +paddle.std(x, dim, unbiased=True) +``` + +#### out + +```python +# PyTorch +torch.std(x, out=y) + +# Paddle +paddle.assign(paddle.std(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std_mean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std_mean.md new file mode 100644 index 00000000000..16f62ca4a0f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.std_mean.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ]torch.std_mean + +### [torch.std_mean](https://pytorch.org/docs/stable/generated/torch.std_mean.html?highlight=std_mean#torch.std_mean) +```python +# 用法一: +torch.std_mean(input, unbiased=True) +# 用法二: +torch.std_mean(input, dim, unbiased=True, keepdim=False) +``` + +### 功能介绍 +用于实现返回 Tensor 的标准差和均值,PaddlePaddle 目前暂无对应 API,可使用如下代码组合实现该 API。 + +```python +# PyTorch 写法 +std, mean = torch.std_mean(x, dim=1) + +# Paddle 写法 +std = paddle.std(x, axis=1) +mean = paddle.mean(x, axis=1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stft.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stft.md new file mode 100644 index 00000000000..96d5dfe2185 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.stft.md @@ -0,0 +1,59 @@ +## [torch 参数更多 ]torch.stft + +### [torch.stft](https://pytorch.org/docs/stable/generated/torch.stft.html?highlight=stft#torch.stft) + +```python +torch.stft(input, + n_fft, + hop_length=None, + win_length=None, + window=None, + center=True, + pad_mode='reflect', + normalized=False, + onesided=None, + return_complex=None) +``` + +### [paddle.signal.stft](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/signal/stft_cn.html#paddle.signal.stft) + +```python +paddle.signal.stft(x, + n_fft, + hop_length=None, + win_length=None, + window=None, + center=True, + pad_mode='reflect', + normalized=False, + onesided=True, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的数据,是维度为 1D 或者 2D 的 Tensor, 数据类型可为复数(复信号),仅参数名不一致。 | +| n_fft | n_fft | 离散傅里叶变换的样本点个数。 | +| hop_length | hop_length | 对输入分帧时,相邻两帧偏移的样本点个数。默认为 None(为 n_ff/4)。 | +| win_length | win_length | 信号窗的长度。默认为 None(为 n_fft)。 | +| window | window | 维度为 1D 长度为 win_length 的 Tensor,数据类型可为复数。默认为 None。 | +| center | center | 选择是否将输入信号进行补长。默认为 True。 | +| pad_mode | pad_mode | 当 center 为 True 时,确定 padding 的模式。 | +| normalized | normalized | 是否将傅里叶变换的结果乘以值为 1/sqrt(n) 的缩放系数。 | +| onesided | onesided | 当输入为实信号时,选择是否只返回傅里叶变换结果的一半的频点值,如果输入的信号或者窗函数的 数据类型是复数,则此时不能设置为 True。默认为 True。 | +| return_complex| - | 表示当输入为复数时,是否以复数形式返回,还是将实部与虚部分开以实数形式返回。Paddle 目前只支持返回复数,分开返回实部与虚部的情况,需要使用 as_real 进行转写。 | + + +### 转写示例 +#### return_complex:是否返回复数 +```python +# PyTorch 写法 +y = torch.stft(input, n_fft=512, return_complex=False) + +# Paddle 写法 +y = paddle.as_real(paddle.stft(input, n_fft=512)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sub.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sub.md new file mode 100644 index 00000000000..0ed9caab2a3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sub.md @@ -0,0 +1,49 @@ +## [ torch 参数更多 ]torch.sub +### [torch.sub](https://pytorch.org/docs/stable/generated/torch.sub.html?highlight=torch%20sub#torch.sub) + +```python +torch.sub(input, + other, + *, + alpha=1, + out=None) +``` + +### [paddle.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/subtract_cn.html#subtract) + +```python +paddle.subtract(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示被减数的 Tensor,仅参数名不一致。 | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数,需要转写。 Paddle 应设置 y = alpha * other。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +torch.sub(x, y, alpha=2) + +# Paddle 写法 +paddle.subtract(x, 2*y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` +#### out:指定输出 +```python +# PyTorch 写法 +torch.sub(x, y, out=z) + +# Paddle 写法 +paddle.assign(paddle.subtract(x, y), z) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.subtract.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.subtract.md new file mode 100644 index 00000000000..4894b73bd27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.subtract.md @@ -0,0 +1,50 @@ +## [torch 参数更多 ]torch.subtract +### [torch.subtract](https://pytorch.org/docs/stable/generated/torch.subtract.html?highlight=subtract#torch.subtract) + +```python +torch.subtract(input, + other, + *, + alpha=1, + out=None) +``` + +### [paddle.subtract](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/subtract_cn.html#subtract) + +```python +paddle.subtract(x, + y, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示被减数的 Tensor,仅参数名不一致。 | +| other | y | 表示减数的 Tensor,仅参数名不一致。 | +| alpha | - | 表示`other`的乘数,Paddle 无此参数。Paddle 应设置 y = alpha * other。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数。 | + +### 功能差异 + +### 转写示例 +#### alpha:表示`other`的乘数 +```python +# PyTorch 写法 +torch.subtract(x, y, alpha=2) + +# Paddle 写法 +paddle.subtract(x, 2*y) + +# 注:Paddle 直接将 alpha 与 y 相乘实现 +``` +#### out:指定输出 +```python +# PyTorch 写法 +torch.subtract(x, y, out=z) + +# Paddle 写法 +paddle.assign(paddle.subtract(x, y), z) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sum.md new file mode 100644 index 00000000000..7c74c462403 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.sum.md @@ -0,0 +1,29 @@ +## [ 仅参数名不一致 ]torch.sum +### [torch.sum](https://pytorch.org/docs/stable/generated/torch.sum.html?highlight=sum#torch.sum) + +```python +torch.sum(input, + dim=None, + keepdim=False, + dtype=None) +``` + +### [paddle.sum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sum_cn.html#sum) + +```python +paddle.sum(x, + axis=None, + dtype=None, + keepdim=False, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| dtype | dtype | 表示数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd.md new file mode 100644 index 00000000000..2ad83a1803e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd.md @@ -0,0 +1,42 @@ +## [ torch 参数更多 ] torch.svd + +### [torch.svd](https://pytorch.org/docs/stable/generated/torch.svd.html?highlight=torch+svd#torch.svd) + +```python +torch.svd(input, some=True, compute_uv=True, *, out=None) +``` + +### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/svd_cn.html#svd) + +```python +paddle.linalg.svd(x, full_matrics=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor ,仅参数名不一致。 | +| some | full_matrics | 表示需计算的奇异值数目。 与 PyTorch 默认值不同,需要转写。 | +| compute_uv | - | 表示是否计算 U 和 V 。Paddle 无此参数,暂无转写方式。 | +| out | - | 表示输出的 Tensor 元组。 Paddle 无此参数,需要转写。 | + +### 转写示例 +#### some:表示需计算的奇异值数目 +```python +# PyTorch 写法 +u, s, v = torch.svd(x, some = True ) + +# Paddle 写法 +u, s, v = paddle.linalg.svd(x, full_matrics = False) +``` +#### out:指定输出 +```python +# PyTorch 写法 +torch.svd(x, out=(u, s, v) ) + +# Paddle 写法 +u, s, v = paddle.linalg.svd(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd_lowrank.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd_lowrank.md new file mode 100644 index 00000000000..93cb363a604 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.svd_lowrank.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ] torch.svd_lowrank + +### [torch.svd_lowrank](https://pytorch.org/docs/stable/generated/torch.svd_lowrank.html?highlight=torch+svd_lowrank#torch.svd_lowrank) + +```python +torch.svd_lowrank(A, q=6, niter=2, M=None) +``` + +### [paddle.linalg.svd_lowrank](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/svd_lowrank_cn.html) + +```python +paddle.linalg.svd_lowrank(x, q=None, niter=2, M=None name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 表示输入 Tensor,仅参数名不一致。 | +| q | q | 表示输入 Tensor 略高估计秩。 | +| niter | niter | 表示子空间进行迭代的数量。 | +| M | M | 表示输入 Tensor 的平均值矩阵。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapaxes.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapaxes.md new file mode 100644 index 00000000000..6a0161daab3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapaxes.md @@ -0,0 +1,40 @@ +## [ 参数不一致 ] torch.swapaxes + +### [torch.swapaxes](https://pytorch.org/docs/stable/generated/torch.swapaxes.html#torch.swapaxes) + +```python +torch.swapaxes(input, axis0, axis1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +其中 PyTorch 的 `axis0、axis1` 与 Paddle 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor。 | +| axis0 | - | PyTorch 转置的第一个维度,Paddle 无此参数,需要转写。 | +| axis1 | - | PyTorch 转置的第二个维度,Paddle 无此参数,需要转写。 | +| - | perm | Paddle 可通过 perm 参数,等价的实现 torch 的 axis0、axis1 的功能。| + + +### 转写示例 + +#### axis0、axis1 参数: 转置的维度设置 +``` python +# PyTorch 写法: +torch.swapaxes(x, axis0=0, axis1=1) + +# Paddle 写法: +paddle.transpose(x, perm=[1, 0, 2]) + +# 注:x 为 3D Tensor +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapdims.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapdims.md new file mode 100644 index 00000000000..afc9ec803f1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.swapdims.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ] torch.swapdims + +### [torch.swapdims](https://pytorch.org/docs/stable/generated/torch.swapdims.html#torch.swapdims) + +```python +torch.swapdims(input, + dim0, + dim1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +其中 PyTorch 的 `dim0、dim1` 与 Paddle 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor。 | +| dim0 | - | PyTorch 转置的第一个维度,Paddle 无此参数,需要转写。 | +| dim1 | - | PyTorch 转置的第二个维度,Paddle 无此参数,需要转写。 | +| - | perm | Paddle 可通过 perm 参数,等价的实现 torch 的 dim0、dim1 的功能。| + + +### 转写示例 + +#### dim0、dim1 参数: 转置的维度设置 +``` python +# PyTorch 写法: +torch.swapdims(x, dim0=0, dim1=1) + +# Paddle 写法: +paddle.transpose(x, perm=[1, 0, 2]) + +# 注:x 为 3D Tensor +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.symeig.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.symeig.md new file mode 100644 index 00000000000..be21a82e648 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.symeig.md @@ -0,0 +1,64 @@ +## [ torch 参数更多 ] torch.symeig + +### [torch.symeig](https://pytorch.org/docs/stable/generated/torch.symeig.html?highlight=torch+symeig#torch.symeig) + +```python +# pytorch1.9 以上版本不支持 +torch.symeig(input, eigenvectors=False, upper=True, *, out=None) +``` + +### [paddle.linalg.eigh](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/eigh_cn.html#eigh) + +```python +# eigenvectors 为 True +paddle.linalg.eigh(x, UPLO='L', name=None) + +# eigenvectors 为 False +paddle.linalg.eigvalsh(x, UPLO='L', name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的对称 Tensor,仅参数名不一致。 | +| eigenvectors | - | 表示是否计算特征向量。Paddle 无此参数,需要转写。 | +| upper | UPLO | 表示计算上三角或者下三角矩阵。 需进行转写。 | +| out | - | 表示输出的 Tensor 元组, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### eigenvectors:表示是否计算特征向量 +```python +# PyTorch 写法,eigenvectors 为 False +e, _ = torch.symeig(x, eigenvectors=False) + +# Paddle 写法 +e = paddle.linalg.eigvalsh(x) + +# PyTorch 写法,eigenvectors 为 True +e, v = torch.symeig(x, eigenvectors=True) + +# Paddle 写法 +e, v = paddle.linalg.eigh(x) +``` + +#### upper:表示计算上三角或者下三角矩阵 +```python +# PyTorch 写法 +e, v = torch.symeig(x, upper = False) + +# Paddle 写法 +e, v = paddle.linalg.eigh(x, UPLO = 'L') +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.symeig(x, out=(e, v) ) + +# Paddle 写法 +e, v = paddle.linalg.eigh(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take.md new file mode 100644 index 00000000000..6f46e216fa2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.take +### [torch.take](https://pytorch.org/docs/stable/generated/torch.take.html?highlight=torch+take#torch.take) + +```python +torch.take(input, index) +``` + +### [paddle.take](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/take_cn.html#take) + +```python +paddle.take(x, index, mode='raise', name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| index | index | 表示索引矩阵,仅参数名不一致。 | +| - | mode | 表示索引越界后的处理方式, PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take_along_dim.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take_along_dim.md new file mode 100644 index 00000000000..90e1c243749 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.take_along_dim.md @@ -0,0 +1,41 @@ +## [ torch 参数更多 ]torch.take_along_dim + +### [torch.take_along_dim](https://pytorch.org/docs/stable/generated/torch.take_along_dim.html?highlight=torch+take_along_dim#torch.take_along_dim) + +```python +torch.take_along_dim(input, + indices, + dim, + out=None) +``` + +### [paddle.take_along_axis](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/take_along_axis_cn.html) + +```python +paddle.take_along_axis(arr, + indices, + axis, + broadcast=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | arr | 表示输入的 Tensor ,仅参数名不一致。 | +| indices | indices | 表示索引矩阵 ,仅参数名不一致。 | +| dim | axis | 表示沿着哪个维度获取对应的值,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.take_along_dim(t, idx, 1,out=y) + +# Paddle 写法 +paddle.assign(paddle.take_along_axis(t, idx, 1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tan.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tan.md new file mode 100644 index 00000000000..4f6c08615bd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tan.md @@ -0,0 +1,34 @@ +## [ 仅参数名不一致 ]torch.tan + +### [torch.tan](https://pytorch.org/docs/stable/generated/torch.tan.html) + +```python +torch.tan(input, *, out=None) +``` + +### [paddle.tan](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/tan_cn.html#tan) + +```python +paddle.tan(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out + +```python +# PyTorch +torch.tan(x, out=y) + +# Paddle +paddle.assign(paddle.tan(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor.md new file mode 100644 index 00000000000..dffc762fadb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor.md @@ -0,0 +1,58 @@ +## [torch 参数更多 ]torch.tensor +### [torch.tensor](https://pytorch.org/docs/stable/generated/torch.tensor.html?highlight=tensor#torch.tensor) + +```python +torch.tensor(data, + dtype=None, + device=None, + requires_grad=False, + pin_memory=False) +``` + +### [paddle.to_tensor](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/to_tensor_cn.html#to-tensor) + +```python +paddle.to_tensor(data, + dtype=None, + place=None, + stop_gradient=True) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| data | data | 表示输入的数据。 | +| dtype | dtype | 表示数据的类型。 | +| device | place | 表示 Tensor 存放设备位置,两者参数类型不相同,需要转写。 | +| requires_grad | stop_gradient | 表示是否计算梯度,两者参数功能相反,需要转写。 | +| pin_memeory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.tensor(3, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.to_tensor(3, place=paddle.CPUPlace()) +``` + +#### requires_grad:是否不阻断梯度传导 +```python +# PyTorch 写法 +x = torch.tensor(3, requires_grad=True) + +# Paddle 写法 +x = paddle.to_tensor(3, stop_gradient=False) +``` + +#### pin_memory:是否分配到固定内存上 +```python +# PyTorch 写法 +x = torch.tensor(3, pin_memory=True) + +# Paddle 写法 +x = paddle.to_tensor(3).pin_memory() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor_split.md new file mode 100644 index 00000000000..a6f9f6bb1bd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensor_split.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.tensor_split +### [torch.tensor_split](https://pytorch.org/docs/stable/generated/torch.tensor_split.html) + +```python +torch.tensor_split(input, indices_or_sections, dim=0) +``` + +### [paddle.tensor_split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tensor_split_cn.html) + +```python +paddle.tensor_split(x, num_or_indices, axis=0, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| indices_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensordot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensordot.md new file mode 100644 index 00000000000..9bead5429bd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tensordot.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.tensordot + +### [torch.tensordot](https://pytorch.org/docs/stable/generated/torch.tensordot.html?highlight=tensordot#torch.tensordot) + +```python +torch.tensordot(a,b,dims=2,out=None) +``` + +### [paddle.tensordot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tensordot_cn.html) + +```python +paddle.tensordot(x,y,axes=2,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| a | x | 表示缩并运算的左张量,仅参数名不一致。 | +| b | y | 表示缩并运算的右张量,仅参数名不一致。 | +| dims | axes | 表示对张量做缩并运算的轴,默认值为 2 ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.tensordot(x,y,axes,out=output) + +# Paddle 写法 +paddle.assign(paddle.tensordot(x,y,axes),output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tile.md new file mode 100644 index 00000000000..371c27ba0ae --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tile.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.tile +### [torch.tile](https://pytorch.org/docs/stable/generated/torch.tile.html?highlight=tile#torch.tile) + +```python +torch.tile(input, + dims) +``` + +### [paddle.tile](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tile_cn.html#tile) + +```python +paddle.tile(x, + repeat_times, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dims | repeat_times | 指定输入 x 每个维度的复制次数,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.topk.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.topk.md new file mode 100644 index 00000000000..5f133aa7b86 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.topk.md @@ -0,0 +1,50 @@ +## [ 参数不一致 ]torch.topk + +### [torch.topk](https://pytorch.org/docs/stable/generated/torch.topk.html?highlight=topk#torch.topk) + +```python +torch.topk(input, + k, + dim=None, + largest=True, + sorted=True, + *, + out=None) +``` + +### [paddle.topk](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/topk_cn.html#paddle.topk) + +```python +paddle.topk(x, + k, + axis=None, + largest=True, + sorted=True, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,同时两个 api 的返回参数类型不同,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| k | k | 在指定的轴上进行 top 寻找的数量, 参数名相同。 | +| dim | axis | 指定对输入 Tensor 进行运算的轴。默认值为-1, 仅参数名不一致。| +| largest | largest | 指定算法排序的方向。如果设置为 True,算法按照降序排序,否则按照升序排序。默认值为 True,参数名相同。 | +| sorted | sorted | 控制返回的结果是否按照有序返回,默认为 True。在 GPU 上总是返回有序的结果。参数名相同。 | +| out | - | 表示以(Tensor, LongTensor)输出的元组,含义是查找 topk 后的返回值和对应元素的索引。Paddle 无此参数,需要转写。 | + +注:PyTorch 返回 (Tensor, LongTensor),Paddle 返回 (Tensor, int64)。 + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.topk(input, k=1, dim=-1, out = (y, indices)) + +# Paddle 写法 +y, indices = paddle.topk(input, k=1, axis=-1) +indices = paddle.to_tensor(indices) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trace.md new file mode 100644 index 00000000000..62bdd95b779 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trace.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.trace +### [torch.trace](https://pytorch.org/docs/stable/generated/torch.trace.html?highlight=trace#torch.trace) + +```python +torch.trace(input) +``` +### [paddle.trace](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/trace_cn.html) + +```python +paddle.trace(x, + offset=0, + axis1=0, + axis2=1, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| - | offset | 2D-Tensor 中获取对角线的位置,默认值为 0,即主对角线,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | axis1 | 当输入的 Tensor 维度大于 2D 时,获取对角线的二维平面的第一维,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | axis2 | 当输入的 Tensor 维度大于 2D 时,获取对角线的二维平面的第二维,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.transpose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.transpose.md new file mode 100644 index 00000000000..b0574cde58e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.transpose.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ] torch.transpose + +### [torch.transpose](https://pytorch.org/docs/stable/generated/torch.transpose.html?highlight=transpose#torch.transpose) + +```python +torch.transpose(input, + dim0, + dim1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/transpose_cn.html#transpose) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +其中 PyTorch 的 `dim0、dim1` 与 Paddle 用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor。 | +| dim0 | - | PyTorch 转置的第一个维度,Paddle 无此参数,需要转写。 | +| dim1 | - | PyTorch 转置的第二个维度,Paddle 无此参数,需要转写。 | +| - | perm | Paddle 可通过 perm 参数,等价的实现 torch 的 dim0、dim1 的功能。| + + +### 转写示例 + +#### dim0、dim1 参数: 转置的维度设置 +``` python +# PyTorch 写法: +torch.transpose(x, dim0=0, dim1=1) + +# Paddle 写法: +paddle.transpose(x, perm=[1, 0, 2]) + +# 注:x 为 3D Tensor +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trapezoid.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trapezoid.md new file mode 100644 index 00000000000..3fdcded1ae0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trapezoid.md @@ -0,0 +1,24 @@ +## [仅参数名不一致]torch.trapezoid + +### [torch.trapezoid](https://pytorch.org/docs/stable/generated/torch.trapezoid.html#torch.trapezoid) + +```python +torch.trapezoid(y, x=None, *, dx=None, dim=- 1) +``` + +### [paddle.trapezoid](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/trapezoid_cn.html#trapezoid) + +```python +paddle.trapezoid(y, x=None, dx=None, axis=- 1, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------- | +| y | y | 输入多维 Tensor。 | +| x | x | y 中数值对应的浮点数所组成的 Tensor。 | +| dx | dx | 相邻采样点之间的常数间隔。 | +| dim | axis | 计算 trapezoid rule 时 y 的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triangular_solve.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triangular_solve.md new file mode 100644 index 00000000000..bc002e44046 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triangular_solve.md @@ -0,0 +1,38 @@ +## [torch 参数更多]torch.triangular_solve + +### [torch.triangular_solve](https://pytorch.org/docs/stable/generated/torch.triangular_solve.html#torch.triangular_solve) + +```python +torch.triangular_solve(b, A, upper=True, transpose=False, unitriangular=False, *, out=None) +``` + +### [paddle.linalg.triangular_solve](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/linalg/triangular_solve_cn.html) + +```python +paddle.linalg.triangular_solve(x, y, upper=True, transpose=False, unitriangular=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------- | ----------------------------------------------------------- | +| A | x | 线性方程组左边的系数方阵,仅参数名不一致。 | +| b | y | 线性方程组右边的矩阵,仅参数名不一致。 | +| upper | upper | 对系数矩阵 x 取上三角还是下三角。 | +| transpose | transpose | 是否对系数矩阵 x 进行转置。 | +| unitriangular | unitriangular | 如果为 True,则将系数矩阵 x 对角线元素假设为 1 来求解方程。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.triangular_solve(x2, x1, out=y) + +# Paddle 写法: +paddle.assign(paddle.linalg.triangular_solve(x1, x2), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril.md new file mode 100644 index 00000000000..a4be1c6f229 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril.md @@ -0,0 +1,35 @@ +## [ torch 参数更多]torch.tril + +### [torch.tril](https://pytorch.org/docs/stable/generated/torch.tril.html?highlight=tril#torch.tril) + +```python +torch.tril(input,diagonal=0,*,out=None) +``` + +### [paddle.tril](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tril_cn.html) + +```python +paddle.tril(input,diagonal=0,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| input | input | 表示输入的 Tensor 。 | +| diagonal | diagonal | 表示指定的对角线,默认值是 0 ,表示主对角线。如果 diagonal > 0 ,表示主对角线之上的对角线;如果 diagonal < 0 ,表示主对角线之下的对角线。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.tril(input,diagonal,out=output) + +# Paddle 写法 +paddle.assign(paddle.tril(input,diagonal),output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril_indices.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril_indices.md new file mode 100644 index 00000000000..fb7879fe56b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.tril_indices.md @@ -0,0 +1,39 @@ +## [ torch 参数更多]torch.tril_indices + +### [torch.tril_indices](https://pytorch.org/docs/stable/generated/torch.tril_indices.html?highlight=tril_indices#torch.tril_indices) + +```python +torch.tril_indices(row,col,offset=0,*,dtype=torch.long,device='cpu',layout=torch.strided) +``` + +### [paddle.tril_indices](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/tril_indices_cn.html) + +```python +paddle.tril_indices(row,col,offset=0,dtype='int64') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| row | row | 表示输入 Tensor 的行数。 | +| col | col | 表示输入 Tensor 的列数。 | +| offset | offset | 表示从指定二维平面中获取对角线的位置。如果 offset = 0 ,取主对角线;如果 offset > 0 ,取主对角线右上的对角线;如果 offset < 0 ,取主对角线左下的对角线。 | +| dtype | dtype | 表示输出张量的数据类型。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +torch.tril_indices(row,col,offset,dtype,device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.tril_indices(row,col,offset,dtype) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu.md new file mode 100644 index 00000000000..59265cf5b77 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu.md @@ -0,0 +1,36 @@ +## [ torch 参数更多]torch.triu + +### [torch.triu](https://pytorch.org/docs/stable/generated/torch.triu.html?highlight=triu#torch.triu) + +```python +torch.triu(input,diagonal=0,*,out=None) +``` + +### [paddle.triu](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/triu_cn.html) + +```python +paddle.triu(input,diagonal=0,name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| input | input | 表示输入的 Tensor 。 | +| diagonal | diagonal | 指定的对角线,默认值为 0 ,表示主对角线。如果 diagonal > 0 ,表示主对角线之上的对角线;如果 diagonal < 0 ,表示主对角线之下的对角线。 | +| out | - | 表示输出的 Tensor , Paddle 没有此参数,需要转写。 | + +### 转写示例 + +#### out: 输出的 Tensor + +```python +# PyTorch 写法 +torch.triu(input,diagonal,out=output) + + +# Paddle 写法 +paddle.assign(paddle.triu(input,diagonal),output) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu_indices.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu_indices.md new file mode 100644 index 00000000000..86e56575eb7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.triu_indices.md @@ -0,0 +1,39 @@ +## [ torch 参数更多]torch.triu_indices + +### [torch.triu_indices](https://pytorch.org/docs/stable/generated/torch.triu_indices.html?highlight=triu_indices#torch.triu_indices) + +```python +torch.triu_indices(row,col,offset=0,*,dtype=torch.long,device='cpu',layout=torch.strided) +``` + +### [paddle.triu_indices](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/triu_indices_cn.html) + +```python +paddle.triu_indices(row,col=None,offset=0,dtype='int64') +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------- | ------- | +| row | row | 表示输入 Tensor 的行数。 | +| col | col | 表示输入 Tensor 的列数。 | +| offset | offset | 表示从指定二维平面中获取对角线的位置。如果 offset = 0 ,取主对角线;如果 offset > 0 ,取主对角线右上的对角线;如果 offset < 0 ,取主对角线左下的对角线。 | +| dtype | dtype | 表示数据类型。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.triu_indices(row,col,offset,dtype,device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.triu_indices(row,col,offset,dtype) +y.cpu() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.true_divide.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.true_divide.md new file mode 100644 index 00000000000..376a8748092 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.true_divide.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.true_divide + +### [torch.true\_divide](https://pytorch.org/docs/stable/generated/torch.true_divide.html) + +```python +torch.true_divide(input, other, *, out) +``` + +### [paddle.divide](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/divide_cn.html#divide) + +```python +paddle.divide(x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -- | +| input | x | 输入 Tensor,仅参数名不一致。 | +| other | y | 输入 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out + +```python +# PyTorch +torch.true_divide(x, y, out=z) + +# Paddle +paddle.assign(paddle.div(x, y), z) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trunc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trunc.md new file mode 100644 index 00000000000..ad822ea73a8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.trunc.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.trunc +### [torch.trunc](https://pytorch.org/docs/stable/generated/torch.trunc.html?highlight=torch+trunc#torch.trunc) + +```python +torch.trunc(input, + *, + out=None) +``` + +### [paddle.trunc](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/trunc_cn.html) + +```python +paddle.trunc(input, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | input | 表示输入的 Tensor。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.trunc(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.trunc(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unbind.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unbind.md new file mode 100644 index 00000000000..2294786cc84 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unbind.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.unbind +### [torch.unbind](https://pytorch.org/docs/stable/generated/torch.unbind.html?highlight=unbind#torch.unbind) + +```python +torch.unbind(input, + dim=0) +``` + +### [paddle.unbind](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/unbind_cn.html#unbind) + +```python +paddle.unbind(x, + axis=0) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的多维 Tensor ,仅参数名不一致。 | +| dim | axis | 表示需要分割的维度,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unflatten.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unflatten.md new file mode 100644 index 00000000000..21a3885c255 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unflatten.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ] torch.unflatten + +### [torch.unflatten](https://pytorch.org/docs/stable/generated/torch.unflatten.html#torch.unflatten) + +```python +torch.unflatten(input, dim, sizes) +``` + +### [paddle.unflatten](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/unflatten_cn.html#unflatten) + +```python +paddle.unflatten(x, axis, shape, name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入 Tensor,仅参数名不一致。 | +| dim | axis | 需要变换的维度,仅参数名不一致。 | +| sizes | shape | 维度变换的新形状,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique.md new file mode 100644 index 00000000000..9c6018a88f1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.unique +### [torch.unique](https://pytorch.org/docs/stable/generated/torch.unique.html?highlight=unique#torch.unique) + +```python +torch.unique(input, + sorted, + return_inverse, + return_counts, + dim=None) +``` + +### [paddle.unique](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/unique_cn.html#unique) + +```python +paddle.unique(x, + return_index=False, + return_inverse=False, + return_counts=False, + axis=None, + dtype='int64', + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入 Tensor。 | +| sorted | - | 表示是否按升序返回排列,Paddle 无此参数。暂无转写方式 | +| - | return_index | 表示是否返回独有元素在输入 Tensor 中的索引,PyTorch 无此参数。Paddle 保持默认即可。 | +| return_inverse| return_inverse| 表示是否返回输入 Tensor 的元素对应在独有元素中的索引。 | +| return_counts | return_counts| 表示是否返回每个独有元素在输入 Tensor 中的个数。 | +| dim | axis | 表示指定选取独有元素的轴。 | +| - | dtype | 表示返回值的类型,PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique_consecutive.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique_consecutive.md new file mode 100644 index 00000000000..5862eac61b8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unique_consecutive.md @@ -0,0 +1,29 @@ +## [ 仅 paddle 参数更多 ]torch.unique_consecutive +### [torch.unique_consecutive](https://pytorch.org/docs/stable/generated/torch.unique_consecutive.html?highlight=unique_consecutive#torch.unique_consecutive) + +```python +torch.unique_consecutive(input, + return_inverse=False, + return_counts=False, + dim=None) +``` + +### [paddle.unique_consecutive](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/unique_consecutive_cn.html#unique-consecutive) + +```python +paddle.unique_consecutive(x, + return_inverse=False, + return_counts=False, + axis=None, + dtype='int64', + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 指定选取连续不重复元素的轴,仅参数名不一致。 | +| - | dtype | 用于设置 inverse 或者 counts 的类型,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unsqueeze.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unsqueeze.md new file mode 100644 index 00000000000..fbf71695b05 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.unsqueeze.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ]torch.unsqueeze +### [torch.unsqueeze](https://pytorch.org/docs/stable/generated/torch.unsqueeze.html?highlight=unsqueeze#torch.unsqueeze) + +```python +torch.unsqueeze(input, + dim) +``` + +### [paddle.unsqueeze](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/unsqueeze_cn.html#unsqueeze) + +```python +paddle.unsqueeze(x, + axis, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示要插入维度的位置,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.utils.data.SequentialSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.utils.data.SequentialSampler.md new file mode 100644 index 00000000000..59c6da3785d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.utils.data.SequentialSampler.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.utils.data.SequentialSampler + +### [torch.utils.data.SequentialSampler](https://pytorch.org/docs/stable/generated/torch.utils.data.SequentialSampler.html) + +```python +torch.utils.data.SequentialSampler(data_source) +``` + +### [paddle.io.SequenceSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/SequenceSampler_cn.html#sequencesampler) + +```python +paddle.io.SequenceSampler(data_source) +``` + +功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -- | +| data_source | data_source | Dataset 或 IterableDataset 的一个子类实例或实现了 `__len__` 的 Python 对象。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vander.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vander.md new file mode 100644 index 00000000000..e4cef2ccad3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vander.md @@ -0,0 +1,27 @@ +## [ 仅参数名不一致 ]torch.vander + +### [torch.vander](https://pytorch.org/docs/stable/generated/torch.vander.html?highlight=vander#torch.vander) + +```python +torch.vander(x, + N, + increasing) +``` + +### [paddle.vander](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/vander_cn.html#vander) + +```python +paddle.vander(x, + n, + increasing) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| x | x | 表示输入的 Tensor。 | +| N | n | 用于指定输出的列数, 仅参数名大小写的区别。 | +| increasing | increasing | 指定输出列的幂次顺序。如果为 True,则幂次从左到右增加。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var.md new file mode 100644 index 00000000000..31d3d3c09e7 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var.md @@ -0,0 +1,55 @@ +## [ torch 参数更多 ]torch.var + +### [torch.var](https://pytorch.org/docs/stable/generated/torch.var.html) + +```python +torch.var(input, dim=None, unbiased=True, keepdim=False, *, correction=1, out=None) +``` + +### [paddle.var](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/var_cn.html#var) + +```python +paddle.var(x, axis=None, unbiased=True, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | -- | +| input | x | 输入张量,仅参数名不一致。 | +| dim | axis | 指定对 x 进行计算的轴,仅参数名不一致。 | +| unbiased | unbiased | 是否使用无偏估计来计算标准差。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| correction | - | 样本尺寸与其自由度的差异,Paddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### correction + +```python +# PyTorch +torch.var(x, dim, correction=0) + +# Paddle +paddle.var(x, dim, unbiased=False) + + +# PyTorch +torch.var(x, dim, correction=1) + +# Paddle +paddle.var(x, dim, unbiased=True) +``` + +#### out + +```python +# PyTorch +torch.var(x, out=y) + +# Paddle +paddle.assign(paddle.var(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var_mean.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var_mean.md new file mode 100644 index 00000000000..80adbd7f222 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.var_mean.md @@ -0,0 +1,25 @@ +## [ 组合替代实现 ]torch.var_mean + +### [torch.var_mean](https://pytorch.org/docs/stable/generated/torch.var_mean.html?highlight=var_mean#torch.var_mean) +```python +# 用法一: +torch.var_mean(input, + unbiased=True) +# 用法二: +torch.var_mean(input, + dim, + keepdim=False, + unbiased=True) +``` + +### 功能介绍 +用于实现返回 Tensor 的方差和均值,PaddlePaddle 目前暂无对应 API,可使用如下代码组合实现该 API。 + +```python +# PyTorch 写法 +var, mean = torch.var_mean(x, dim=1) + +# Paddle 写法 +var = paddle.var(x, axis=1) +mean = paddle.mean(x, axis=1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vdot.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vdot.md new file mode 100644 index 00000000000..5786a99017b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vdot.md @@ -0,0 +1,32 @@ +## [torch 参数更多]torch.vdot + +### [torch.vdot](https://pytorch.org/docs/stable/generated/torch.vdot.html#torch.vdot) + +```python +torch.vdot(input, other, *, out=None) +``` + +### [paddle.dot](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/dot_cn.html#dot) + +```python +paddle.dot(x, y, name=None) +``` + +torch 参数更多,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的向量。 | +| other | y | 被乘的向量。 | +| out | - | 指定输出。Paddle 无此参数,需要转写 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.vdot(x, y, out=out) + +# Paddle 写法 +paddle.assign(paddle.dot(x, y), out) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_complex.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_complex.md new file mode 100644 index 00000000000..7f516c30beb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_complex.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.view_as_complex +### [torch.view_as_complex](https://pytorch.org/docs/stable/generated/torch.view_as_complex.html?highlight=view_as_complex#torch.view_as_complex) + +```python +torch.view_as_complex(input) +``` + +### [paddle.as_complex](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/as_complex_cn.html#as-complex) + +```python +paddle.as_complex(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_real.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_real.md new file mode 100644 index 00000000000..49cf32d6f25 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.view_as_real.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.view_as_real +### [torch.view_as_real](https://pytorch.org/docs/stable/generated/torch.view_as_real.html?highlight=view_as_real#torch.view_as_real) + +```python +torch.view_as_real(input) +``` + +### [paddle.as_real](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/as_real_cn.html#as-real) + +```python +paddle.as_real(x, + name=None) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vsplit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vsplit.md new file mode 100644 index 00000000000..6c3bd3315a6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vsplit.md @@ -0,0 +1,24 @@ +## [ 仅参数名不一致 ]torch.vsplit +### [torch.vsplit](https://pytorch.org/docs/stable/generated/torch.vsplit.html#torch.vsplit) + +```python +torch.vsplit(input, + indices_or_sections) +``` + +### [paddle.vsplit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/vsplit_cn.html) + +```python +paddle.vsplit(x, + num_or_indices, + name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入多维 Tensor ,仅参数名不一致。 | +| indices_or_sections | num_or_indices | 表示分割的数量或索引,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vstack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vstack.md new file mode 100644 index 00000000000..c16c4582ed0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.vstack.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ]torch.vstack + +### [torch.vstack](https://pytorch.org/docs/stable/generated/torch.vstack.html#torch.vstack) + +```python +torch.vstack(tensors, *, out=None) +``` + +### [paddle.vstack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/vstack_cn.html) + +```python +paddle.vstack(x, name=None) +``` + +其中 Paddle 相比 PyTorch 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensors | x | 表示输入的 Tensor ,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.xlogy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.xlogy.md new file mode 100644 index 00000000000..892af4ff2ac --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.xlogy.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.xlogy + +### [torch.xlogy](https://pytorch.org/docs/stable/generated/torch.xlogy.html#torch.xlogy) + +```python +torch.xlogy(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.xlogy(a, b) + +# Paddle 写法 +y = a * paddle.log(b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros.md new file mode 100644 index 00000000000..4ff5673cb9d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros.md @@ -0,0 +1,72 @@ +## [ 参数不一致 ]torch.zeros +### [torch.zeros](https://pytorch.org/docs/stable/generated/torch.zeros.html?highlight=zeros#torch.zeros) + +```python +torch.zeros(*size, + *, + out=None, + dtype=None, + layout=torch.strided, + device=None, + requires_grad=False) +``` + +### [paddle.zeros](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/zeros_cn.html#zeros) + +```python +paddle.zeros(shape, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| *size | shape | 表示输出形状大小,PyTorch 以可变参数方式传入,Paddle 以 list 或 tuple 的方式传入,需要转写。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | +| dtype | dtype | 表示数据类型 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### *size:输出形状大小 +```python +# PyTorch 写法 +torch.zeros(3, 5) + +# Paddle 写法 +paddle.zeros([3, 5]) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.zeros([3, 5], out=y) + +# Paddle 写法 +paddle.assign(paddle.zeros([3, 5]), y) +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.zeros([3, 5], device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.zeros([3, 5]) +y.cpu() +``` + +#### requires_grad:是否需要求反向梯度,需要修改该 Tensor 的 stop_gradient 属性 +```python +# PyTorch 写法 +x = torch.zeros([3, 5], requires_grad=True) + +# Paddle 写法 +x = paddle.zeros([3, 5]) +x.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros_like.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros_like.md new file mode 100644 index 00000000000..0a4d422052a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/ops/torch.zeros_like.md @@ -0,0 +1,58 @@ +## [torch 参数更多]torch.zeros_like + +### [torch.zeros_like](https://pytorch.org/docs/stable/generated/torch.zeros_like.html?highlight=zeros_like#torch.zeros_like) + +```python +torch.zeros_like(input, + *, + dtype=None, + layout=None, + device=None, + requires_grad=False, + memory_format=torch.preserve_format) +``` + +### [paddle.zeros_like](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/zeros_like_cn.html) + +```python +paddle.zeros_like(x, + dtype=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------ | +| input | x | 表示输入 Tensor ,仅名称不同。 | +| dtype | dtype | 表示输出 Tensor 类型。 | +| layout | - | 表示布局方式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度,Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | + +### 转写示例 + +#### device: Tensor 的设备 + +```python +# PyTorch 写法 +y = torch.zeros_like(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.zeros_like(x) +y.cpu() +``` + +#### requires_grad:是否求梯度 + +```python +# PyTorch 写法 +y = torch.zeros_like(x, requires_grad=True) + +# Paddle 写法 +y = paddle.zeros_like(x) +y.stop_gradient = False +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.ASGD.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.ASGD.md new file mode 100644 index 00000000000..0024e0007f0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.ASGD.md @@ -0,0 +1,83 @@ +## [ torch 参数更多 ]torch.optim.ASGD + +### [torch.optim.ASGD](https://pytorch.org/docs/stable/generated/torch.optim.ASGD.html) + +```python +torch.optim.ASGD(params, + lr=0.01, + lambd=0.0001, + alpha=0.75, + t0=1000000.0, + weight_decay=0, + foreach=None, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.ASGD](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/ASGD_cn.html#cn-api-paddle-optimizer-asgd) + +```python +paddle.optimizer.ASGD(learning_rate=0.001, + batch_num=1, + parameters=None, + weight_decay=None, + grad_clip=None, + multi_precision=False, + name=None) +``` + +注:Pytorch 的 ASGD 是有问题的。 +Pytorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致 | +| lr | learning_rate | 学习率,用于参数更新的计算。参数默认值不一致, Pytorch 默认为 `0.0001`, Paddle 默认为 `0.001`,Paddle 需保持与 Pytorch 一致 | +| lambd | - | 衰变项,与 weight_decay 功能重叠,可直接删除 | +| alpha | - | eta 更新的 power,可直接删除 | +| t0 | - | 开始求平均值的点,可直接删除 | +| weight_decay | weight_decay | 权重衰减。参数默认值不一致, Pytorch 默认为 `0`, Paddle 默认为 `None`,Paddle 需保持与 Pytorch 一致 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式 | +| differentiable| - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除 | +| - | batch_num | 完成一个 epoch 所需迭代的次数。 PyTorch 无此参数。假设样本总数为 all_size,Paddle 需将 batch_num 设置为 all_size / batch_size | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可 | +| - | multi_precision | 在基于 GPU 设备的混合精度训练场景中,该参数主要用于保证梯度更新的数值稳定性。 PyTorch 无此参数,Paddle 保持默认即可 | +| - | name | 一般情况下无需设置。 PyTorch 无此参数,Paddle 保持默认即可 | + +### 相关问题 + +torch 当前版本的 ASGD 实现并不完善。转换过来的 paddle ASGD 会与 torch 的不一致(不影响收敛),但是可以正常使用。如果强需求保证转换前后一致,可以自行尝试其他优化器。 + +如果后续 torch 有代码更新,可以联系 @WintersMontagne10335 作 API 调整与对接。 + +#### torch 现存问题 + +在 `_single_tensor_asgd` 中,对 `axs, ax` 进行了更新,但是它们却并没有参与到 `params` 中。 `axs, ax` 完全没有作用。 + +调研到的比较可信的原因是,目前 `ASGD` 的功能并不完善, `axs, ax` 是预留给以后的版本的。 + +另外,weight_decay 是冗余的。 + +当前版本 `ASGD` 的功能,类似于 `SGD` 。 + +详情可见: +- https://discuss.pytorch.org/t/asgd-optimizer-has-a-bug/95060 +- https://discuss.pytorch.org/t/averaged-sgd-implementation/26960 +- https://github.com/pytorch/pytorch/issues/74884 + +#### paddle 实现思路 + +主要参照 [`ASGD` 论文: Minimizing Finite Sums with the Stochastic Average Gradient](https://inria.hal.science/hal-00860051v2) + +核心步骤为: + + 1. 初始化 d, y + 2. 随机采样 + 3. 用本次计算得到的第 i 个样本的梯度信息,替换上一次的梯度信息 + 4. 更新参数 + +伪代码和详细实现步骤可见: +- https://github.com/PaddlePaddle/community/blob/b76313c3b8f8b6a2f808d90fa95dcf265dbef67d/rfcs/APIs/20231111_api_design_for_ASGD.md diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adadelta.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adadelta.md new file mode 100644 index 00000000000..2051eba94e9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adadelta.md @@ -0,0 +1,42 @@ +## [ torch 参数更多 ]torch.optim.Adadelta + +### [torch.optim.Adadelta](https://pytorch.org/docs/stable/generated/torch.optim.Adadelta.html) + +```python +torch.optim.Adadelta(params, + lr=1.0, + rho=0.9, + eps=1e-6, + weight_decay=0, + foreach=None, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.Adadelta](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Adadelta_cn.html#cn-api-paddle-optimizer-adadelta) + +```python +paddle.optimizer.Adadelta(learning_rate=0.001, + epsilon=1e-06, + rho=0.95, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。参数默认值不一致, PyTorch 默认为`1.0`, Paddle 默认为`0.001`,Paddle 需保持与 PyTorch 一致。 | +| rho | rho | 表示衰减速率。参数默认值不一致, PyTorch 默认为`0.9`, Paddle 默认为`0.95`,Paddle 需保持与 PyTorch 一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值,仅参数名不一致。 | +| weight_decay | weight_decay | 表示权重衰减系数,参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adagrad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adagrad.md new file mode 100644 index 00000000000..98ea7a5f206 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adagrad.md @@ -0,0 +1,44 @@ +## [ torch 参数更多 ]torch.optim.Adagrad + +### [torch.optim.Adagrad](https://pytorch.org/docs/stable/generated/torch.optim.Adagrad.html) + +```python +torch.optim.Adagrad(params, + lr=1e-2, + lr_decay=0, + weight_decay=0, + initial_accumulator_value=0, + eps=1e-10, + foreach=None, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.Adagrad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Adagrad_cn.html) + +```python +paddle.optimizer.Adagrad(learning_rate, + epsilon=1e-06, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None, + initial_accumulator_value=0.0) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。参数默认值不一致, PyTorch 默认为`1e-2`, Paddle 为必选参数,Paddle 需保持与 PyTorch 一致。 | +| lr_decay | - | 学习率衰减系数。Paddle 无此参数,暂无转写方式。 | +| weight_decay | weight_decay | 表示权重衰减系数,参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| initial_accumulator_value | initial_accumulator_value | 表示 moment 累加器的初始值,参数完全一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值,参数默认值不一致, PyTorch 默认为`1e-10`, Paddle 为`1e-6`,Paddle 需保持与 PyTorch 一致。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adam.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adam.md new file mode 100644 index 00000000000..979278cd4c3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adam.md @@ -0,0 +1,55 @@ +## [ torch 参数更多 ]torch.optim.Adam + +### [torch.optim.Adam](https://pytorch.org/docs/stable/generated/torch.optim.Adam.html) + +```python +torch.optim.Adam(params, + lr=0.001, + betas=(0.9, 0.999), + eps=1e-08, + weight_decay=0, + amsgrad=False, + foreach=None, + maximize=False, + capturable=False, + differentiable=False, + fused=None) +``` + +### [paddle.optimizer.Adam](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Adam_cn.html) + +```python +paddle.optimizer.Adam(learning_rate=0.001, + beta1=0.9, + beta2=0.999, + epsilon=1e-08, + parameters=None, + weight_decay=None, + grad_clip=None, + lazy_mode=False, + multi_precision=False, + use_multi_tensor=False, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。仅参数名不一致。 | +| betas | beta1、beta2 | 一阶矩估计的指数衰减率。PyTorch 为元祖形式,Paddle 为分开的两个参数。默认值分别一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值。仅参数名不一致。 | +| weight_decay | weight_decay | 表示权重衰减系数,参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| amsgrad | - | 是否使用该算法的 AMSGrad 变体。Paddle 无此参数,暂无转写方式。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| capturable | - | 在 CUDA 图中捕获此实例是否安全。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| fused | - | 是否使用融合实现(仅限 CUDA)。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | +| - | lazy_mode | 设为 True 时,仅更新当前具有梯度的元素。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | multi_precision | 是否在权重更新期间使用 multi-precision。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_multi_tensor | 是否使用 multi-tensor 策略一次性更新所有参数。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.AdamW.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.AdamW.md new file mode 100644 index 00000000000..7f500ea2041 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.AdamW.md @@ -0,0 +1,57 @@ +## [ torch 参数更多 ]torch.optim.AdamW + +### [torch.optim.AdamW](https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html) + +```python +torch.optim.AdamW(params, + lr=0.001, + betas=(0.9, 0.999), + eps=1e-08, + weight_decay=0.01, + amsgrad=False, + maximize=False, + foreach=None, + capturable=False, + differentiable=False, + fused=None) +``` + +### [paddle.optimizer.AdamW](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/AdamW_cn.html) + +```python +paddle.optimizer.AdamW(learning_rate=0.001, + beta1=0.9, + beta2=0.999, + epsilon=1e-08, + parameters=None, + weight_decay=0.01, + lr_ratio=None, + apply_decay_param_fun=None, + grad_clip=None, + name=None, + lazy_mode=False, + multi_precision=False,) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。仅参数名不一致。 | +| betas | beta1、beta2 | 一阶矩估计的指数衰减率。PyTorch 为元祖形式,Paddle 为分开的两个参数。默认值分别一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值。仅参数名不一致。 | +| weight_decay | weight_decay | 表示权重衰减系数。参数名和默认值均一致。 | +| amsgrad | - | 是否使用该算法的 AMSGrad 变体。Paddle 无此参数,暂无转写方式。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| capturable | - | 在 CUDA 图中捕获此实例是否安全。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| fused | - | 是否使用融合实现(仅限 CUDA)。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | lr_ratio | 传入函数时,会为每个参数计算一个权重衰减系数,并使用该系数与学习率的乘积作为新的学习率。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | apply_decay_param_fun | 传入函数时,只有可以使 apply_decay_param_fun(Tensor.name)==True 的 Tensor 会进行 weight decay 更新。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | +| - | lazy_mode | 设为 True 时,仅更新当前具有梯度的元素。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | multi_precision | 在基于 GPU 设备的混合精度训练场景中,该参数主要用于保证梯度更新的数值稳定性。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adamax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adamax.md new file mode 100644 index 00000000000..9d7e8175d02 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Adamax.md @@ -0,0 +1,43 @@ +## [ torch 参数更多 ]torch.optim.Adamax + +### [torch.optim.Adamax](https://pytorch.org/docs/stable/generated/torch.optim.Adamax.html) + +```python +torch.optim.Adamax(params, + lr=0.002, + betas=(0.9, 0.999), + eps=1e-08, + weight_decay=0, + foreach=None, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.Adamax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Adamax_cn.html) + +```python +paddle.optimizer.Adamax(learning_rate=0.001, + beta1=0.9, + beta2=0.999, + epsilon=1e-08, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。参数默认值不一致, PyTorch 默认为`0.002`,PyTorch 默认为`0.001`,Paddle 需保持与 PyTorch 一致。 | +| betas | beta1、beta2 | 一阶矩估计的指数衰减率。PyTorch 为元祖形式,Paddle 为分开的两个参数。默认值分别一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值,参数默认值不一致, PyTorch 默认为`1e-10`, Paddle 为`1e-6`,Paddle 需保持与 PyTorch 一致。 | +| weight_decay | weight_decay | 表示权重衰减系数,参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.LBFGS.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.LBFGS.md new file mode 100644 index 00000000000..cd7175cdf41 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.LBFGS.md @@ -0,0 +1,47 @@ +## [ 仅 paddle 参数更多 ]torch.optim.LBFGS + +### [torch.optim.LBFGS](https://pytorch.org/docs/stable/generated/torch.optim.LBFGS.html) + +```python +torch.optim.LBFGS(params, + lr=1, + max_iter=20, + max_eval=None, + tolerance_grad=1e-07, + tolerance_change=1e-09, + history_size=100, + line_search_fn=None) +``` + +### [paddle.optimizer.LBFGS](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/LBFGS_cn.html) + +```python +paddle.optimizer.LBFGS(learning_rate=1.0, + max_iter=20, + max_eval=None, + tolerance_grad=1e-07, + tolerance_change=1e-09, + history_size=100, + line_search_fn=None, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。仅参数名不一致。 | +| max_iter | max_iter | 每个优化单步的最大迭代次数。参数完全一致。 | +| max_eval | max_eval | 每次优化单步中函数计算的最大数量。参数完全一致。 | +| tolerance_grad | tolerance_grad | 当梯度的范数小于该值时,终止迭代。参数完全一致。 | +| tolerance_change | tolerance_change | 当函数值/x 值/其他参数 两次迭代的改变量小于该值时,终止迭代。参数完全一致。 | +| history_size | history_size | 指定储存的向量对{si,yi}数量。参数完全一致。 | +| line_search_fn | line_search_fn | 指定要使用的线搜索方法。参数完全一致。 | +| - | weight_decay | 表示权重衰减系数。PyTorch 无此参数,Paddle 保持默认即可。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.load_state_dict.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.load_state_dict.md new file mode 100644 index 00000000000..26d0b119353 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.load_state_dict.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.optim.Optimizer.load_state_dict + +### [torch.optim.Optimizer.load_state_dict](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.load_state_dict.html#torch.optim.Optimizer.load_state_dict) + +```python +torch.optim.Optimizer.load_state_dict(state_dict) +``` + +### [paddle.optimizer.Optimizer.load_state_dict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer_cn.html) + +```python +paddle.optimizer.Optimizer.load_state_dict(state_dict) +``` + +两者功能一致,参数完全一致。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ---------- | ---------------- | +| state_dict | state_dict | 表示优化器的状态。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.md new file mode 100644 index 00000000000..2bcfe468d0e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.md @@ -0,0 +1,32 @@ +## [ 仅 paddle 参数更多 ]torch.optim.Optimizer + +### [torch.optim.Optimizer](https://pytorch.org/docs/stable/optim.html#torch.optim.Optimizer) + +```python +torch.optim.Optimizer(params, + defaults) +``` + +### [paddle.optimizer.Optimizer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer_cn.html) + +```python +paddle.optimizer.Optimizer(learning_rate=0.001, + epsilon=1e-08, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,其 `defaults` 可以支持各种参数,但一般只会转写 API 名称,不会转写参数。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| defaults | - | 表示含有优化选项和其默认值的字典,Paddle 无此参数。 | +| - | learning_rate | 学习率,用于参数更新的计算。PyTorch 无此参数,但 defaults 可含有 lr 与之对应。 | +| - | weight_decay | 表示权重衰减系数。 PyTorch 无此参数,但 defaults 可含有 weight_decay 与之对应。 | +| - | epsilon | 保持数值稳定性的短浮点类型值。PyTorch 无此参数,但 defaults 可含有 eps 与之对应。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.state_dict.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.state_dict.md new file mode 100644 index 00000000000..0f741b30cfa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.state_dict.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.optim.Optimizer.state_dict + +### [torch.optim.Optimizer.state_dict](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.state_dict.html?highlight=torch+optim+optimizer+state_dict#torch.optim.Optimizer.state_dict) + +```python +torch.optim.Optimizer.state_dict() +``` + +### [paddle.optimizer.Optimizer.state_dict](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer_cn.html) + +```python +paddle.optimizer.Optimizer.state_dict() +``` + +两者功能一致,均无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.step.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.step.md new file mode 100644 index 00000000000..07f396d3ae1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Optimizer.step.md @@ -0,0 +1,21 @@ +## [ torch 参数更多 ]torch.optim.Optimizer.step + +### [torch.optim.Optimizer.step](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.step.html#torch-optim-optimizer-step) + +```python +torch.optim.Optimizer.step(closure) +``` + +### [paddle.optimizer.Optimizer.step](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Optimizer_cn.html#step) + +```python +paddle.optimizer.Optimizer.step() +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ---------- | ---------------- | +| closure | - | 重新评估模型并返回损失的闭包, Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.RMSprop.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.RMSprop.md new file mode 100644 index 00000000000..730083920cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.RMSprop.md @@ -0,0 +1,46 @@ +## [ torch 参数更多 ]torch.optim.RMSprop + +### [torch.optim.RMSprop](https://pytorch.org/docs/stable/generated/torch.optim.RMSprop.html) + +```python +torch.optim.RMSprop(params, + lr=0.01, + alpha=0.99, + eps=1e-08, + weight_decay=0, + momentum=0, + centered=False, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.RMSProp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/RMSProp_cn.html) + +```python +paddle.optimizer.RMSProp(learning_rate, + rho=0.95, + epsilon=1e-06, + momentum=0.0, + centered=False, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。PyTorch 默认为`0.01`,Paddle 无默认值,Paddle 需保持与 PyTorch 一致。 | +| alpha | rho | 平滑常数。参数默认值不一致, PyTorch 默认为`0.99`,PyTorch 默认为`0.95`,Paddle 需保持与 PyTorch 一致。 | +| eps | epsilon | 保持数值稳定性的短浮点类型值。参数默认值不一致, PyTorch 默认为`1e-08`,PyTorch 默认为`1e-06`,Paddle 需保持与 PyTorch 一致。 | +| weight_decay | weight_decay | 表示权重衰减系数。参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| momentum | momentum | 动量因子。参数完全一致。 | +| centered | centered | 如果为 True,则通过梯度的估计方差,对梯度进行归一化。参数完全一致。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Rprop.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Rprop.md new file mode 100644 index 00000000000..2a1c07ff69c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.Rprop.md @@ -0,0 +1,39 @@ +## [ torch 参数更多 ]torch.optim.Rprop + +### [torch.optim.Rprop](https://pytorch.org/docs/stable/generated/torch.optim.Rprop.html) + +```python +torch.optim.Rprop(params, + lr=0.01, + etas=(0.5, 1.2), + step_sizes=(1e-06, 50), + foreach=None, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.Rprop](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/Rprop_cn.html#cn-api-paddle-optimizer-rprop) + +```python +paddle.optimizer.Rprop(learning_rate=0.001, + learning_rate_range=(1e-5, 50), + parameters=None, + etas=(0.5, 1.2), + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------------- | ----------------------------------------------------------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 初始学习率,用于参数更新的计算。参数默认值不一致, PyTorch 默认为`0.01`, Paddle 默认为`0.001`,Paddle 需保持与 PyTorch 一致。 | +| etas | etas | 用于更新学习率。参数一致。 | +| step_sizes | learning_rate_range | 学习率的范围,参数默认值不一致, PyTorch 默认为`(1e-06, 50)`, Paddle 默认为`(1e-5, 50)`,Paddle 需保持与 PyTorch 一致。 | +| foreach | - | 是否使用优化器的 foreach 实现。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable| - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.SGD.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.SGD.md new file mode 100644 index 00000000000..53b5b335d40 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.SGD.md @@ -0,0 +1,40 @@ +## [ torch 参数更多 ]torch.optim.SGD + +### [torch.optim.SGD](https://pytorch.org/docs/stable/generated/torch.optim.SGD.html) + +```python +torch.optim.SGD(params, + lr, + momentum=0, + dampening=0, + weight_decay=0, + nesterov=False, + maximize=False, + differentiable=False) +``` + +### [paddle.optimizer.SGD](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/SGD_cn.html) + +```python +paddle.optimizer.SGD(learning_rate=0.001, + parameters=None, + weight_decay=None, + grad_clip=None, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------------------- | ------------ | ----------------------------------------------------------------------- | +| params | parameters | 表示指定优化器需要优化的参数,仅参数名不一致。 | +| lr | learning_rate | 学习率,用于参数更新的计算。PyTorch 无默认值,Paddle 默认为`0.001`,Paddle 需保持与 PyTorch 一致。 | +| momentum | - | 动量因子。Paddle 无此参数,暂无转写方式。 | +| dampening | - | 抑制动量。Paddle 无此参数,暂无转写方式。 | +| weight_decay | weight_decay | 表示权重衰减系数。参数默认值不一致, PyTorch 默认为`0`, Paddle 默认为`None`,Paddle 需保持与 PyTorch 一致。 | +| nesterov | - | 打开 nesterov 动量。Paddle 无此参数,暂无转写方式。 | +| maximize | - | 根据目标最大化参数,而不是最小化。Paddle 无此参数,暂无转写方式。 | +| differentiable | - | 是否应通过训练中的优化器步骤进行自动微分。Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | grad_clip | 梯度裁剪的策略。 PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ConstantLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ConstantLR.md new file mode 100644 index 00000000000..005ed097f24 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ConstantLR.md @@ -0,0 +1,46 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.ConstantLR + +### [torch.optim.lr_scheduler.ConstantLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ConstantLR.html) + +```python +torch.optim.lr_scheduler.ConstantLR(optimizer, + factor=0.3333333333333333, + total_iters=5, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.PiecewiseDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/PiecewiseDecay_cn.html) + +```python +paddle.optimizer.lr.PiecewiseDecay(boundaries, + values, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | - | torch.optim.Optimizer 类,Paddle 无此参数。 | +| factor | values | PyTorch 表示乘以学习率的因子,Paddle 表示学习率列表。需要转写,转写思路为:values=[factor*optimizer.lr, optimizer.lr]。 | +| total_iters | boundaries | PyTorch 表示衰减学习率的步数,Paddle 表示指定学习率的边界值列表。需要转写,转写思路为:boundaries = [total_iters]。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.ConstantLR(optimizer=sgd, factor=0.5, total_iters=3) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.PiecewiseDecay(values=[0.5*sgd.get_lr(), sgd.get_lr()], boundaries=[3]) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingLR.md new file mode 100644 index 00000000000..ca13c34fac1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingLR.md @@ -0,0 +1,47 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.CosineAnnealingLR + +### [torch.optim.lr_scheduler.CosineAnnealingLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingLR.html) + +```python +torch.optim.lr_scheduler.CosineAnnealingLR(optimizer, + T_max, + eta_min=0, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.CosineAnnealingDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/CosineAnnealingDecay_cn.html) + +```python +paddle.optimizer.lr.CosineAnnealingDecay(learning_rate, + T_max, + eta_min=0, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| T_max | T_max | 表示训练的上限轮数,是余弦衰减周期的一半。参数完全一致。 | +| eta_min | eta_min | 表示学习率的最小值。参数完全一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.CosineAnnealingLR(optimizer=sgd, T_max=10) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.CosineAnnealingDecay(learning_rate=sgd.get_lr(), T_max=10) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingWarmRestarts.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingWarmRestarts.md new file mode 100644 index 00000000000..3b9af32bebe --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CosineAnnealingWarmRestarts.md @@ -0,0 +1,46 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.CosineAnnealingWarmRestarts + +### [torch.optim.lr_scheduler.CosineAnnealingWarmRestarts](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CosineAnnealingWarmRestarts.html) + +```python +torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer, T_0, T_mult=1, eta_min=0, last_epoch=-1, verbose=False) +``` + +### [paddle.optimizer.lr.CosineAnnealingWarmRestarts](https://github.com/PaddlePaddle/Paddle/blob/d6ea911bd1bfda5604807eeb18318e71b395ac58/python/paddle/optimizer/lr.py#L2371) + +```python +paddle.optimizer.lr.CosineAnnealingWarmRestarts(learning_rate, + T_0, + T_mult=1, + eta_min=0, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| T_0 | T_0 | 首次重启迭代数。 | +| T_mult | T_mult | 重启后变量增加因子。 | +| eta_min | eta_min | 表示学习率的最小值。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。 | + +### 转写示例 + +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.CosineAnnealingWarmRestarts(optimizer=sgd, T_0=1) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.CosineAnnealingWarmRestarts(learning_rate=sgd.get_lr(), T_0=1) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CyclicLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CyclicLR.md new file mode 100644 index 00000000000..b8fdf35685a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.CyclicLR.md @@ -0,0 +1,70 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.CyclicLR + +### [torch.optim.lr_scheduler.CyclicLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.CyclicLR.html) + +```python +torch.optim.lr_scheduler.CyclicLR(optimizer, + base_lr, + max_lr, + step_size_up=2000, + step_size_down=None, + mode='triangular', + gamma=1.0, + scale_fn=None, + scale_mode='cycle', + cycle_momentum=True, + base_momentum=0.8, + max_momentum=0.9, + last_epoch=- 1, + verbose=False) +``` + +### [paddle.optimizer.lr.CyclicLR](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/CyclicLR_cn.html) + +```python +paddle.optimizer.lr.CyclicLR(base_learning_rate, + max_learning_rate, + step_size_up, + step_size_down=None, + mode='triangular', + exp_gamma=1., + scale_fn=None, + scale_mode='cycle', + last_epoch=- 1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | - | PyTorch 的是 torch.optim.Optimizer 类,Paddle 无对应参数。 | +| base_lr | base_learning_rate | 表示初始学习率,也是学习率变化的下边界。仅参数名不一致。 | +| max_lr | max_learning_rate | 表示最大学习率。仅参数名不一致。 | +| step_size_up | step_size_up | 表示学习率从初始学习率增长到最大学习率所需步数。PyTorch 默认值为 2000,Paddle 无默认值,Paddle 需保持与 PyTorch 一致。 | +| step_size_down | step_size_down | 表示学习率从最大学习率下降到初始学习率所需步数。若未指定,则其值默认等于 step_size_up。参数完全一致。 | +| mode | mode | 可以是 triangular、triangular2 或者 exp_range。参数完全一致。 | +| gamma | exp_gamma | 表示缩放函数中的常量。仅参数名不一致。 | +| scale_fn | scale_fn | 一个有且仅有单个参数的函数,且对于任意的输入 x,都必须满足 0 ≤ scale_fn(x) ≤ 1;如果该参数被指定,则会忽略 mode 参数。参数完全一致。 | +| scale_mode | scale_mode | cycle 或者 iterations,表示缩放函数使用 cycle 数或 iterations 数作为输入。参数完全一致。 | +| cycle_momentum | - | 如果"True",动量反向循环 'base_momentum' 和 'max_momentum' 之间的学习率。Paddle 无此参数,暂无转写方式。 | +| base_momentum | - | 每个参数组的循环中的动量下边界。Paddle 无此参数,暂无转写方式。 | +| max_momentum | - | 每个参数组的循环中的动量上边界。Paddle 无此参数,暂无转写方式。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.CyclicLR(optimizer=sgd, base_lr=0.01, max_lr=0.1) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.CyclicLR(base_learning_rate=0.01, max_learning_rate=0.1, step_size_up=2000) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ExponentialLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ExponentialLR.md new file mode 100644 index 00000000000..56ccd1b61a2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ExponentialLR.md @@ -0,0 +1,44 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.ExponentialLR + +### [torch.optim.lr_scheduler.ExponentialLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ExponentialLR.html) + +```python +torch.optim.lr_scheduler.ExponentialLR(optimizer, + gamma, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.ExponentialDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/ExponentialDecay_cn.html) + +```python +paddle.optimizer.lr.ExponentialDecay(learning_rate, + gamma, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| gamma | gamma | 表示衰减率。参数完全一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.ExponentialLR(optimizer=sgd, gamma=0.5) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.ExponentialDecay(learning_rate=sgd.get_lr(), gamma=0.5) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LambdaLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LambdaLR.md new file mode 100644 index 00000000000..3a49270088e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LambdaLR.md @@ -0,0 +1,44 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.LambdaLR + +### [torch.optim.lr_scheduler.LambdaLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.LambdaLR.html) + +```python +torch.optim.lr_scheduler.LambdaLR(optimizer, + lr_lambda, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.LambdaDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/LambdaDecay_cn.html) + +```python +paddle.optimizer.lr.LambdaDecay(learning_rate, + lr_lambda, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| lr_lambda | lr_lambda | 表示 lambda 函数,其通过 epoch 计算出一个因子,该因子会乘以初始学习率。PyTorch 可以是 lambda 函数的列表, Paddle 只能表示 lambda 函数。当 PyTorch 是 lambda 函数的列表时,暂无转写方式。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.LambdaLR(optimizer=sgd, lr_lambda=lambda x:0.95**x) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.LambdaDecay(learning_rate=sgd.get_lr(), lr_lambda=lambda x:0.95**x) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LinearLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LinearLR.md new file mode 100644 index 00000000000..18b78003bdb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.LinearLR.md @@ -0,0 +1,41 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.LinearLR + +### [torch.optim.lr_scheduler.LinearLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.LinearLR.html) + +```python +torch.optim.lr_scheduler.LinearLR(optimizer, start_factor=0.3333333333333333, end_factor=1.0, total_iters=5, last_epoch=-1, verbose=False) +``` + +### [paddle.optimizer.lr.LinearLR](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/LinearLR_cn.html#linearlr) + +```python +paddle.optimizer.lr.LinearLR(learning_rate, total_steps, start_factor=1. / 3, end_factor=1.0, last_epoch=- 1, verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| start_factor | start_factor | 初始学习率因子。 | +| end_factor | end_factor | 最终学习率因子。 | +| total_iters | total_steps | 学习率从初始学习率线性增长到最终学习率所需要的步数,仅参数名不一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。 | + +### 转写示例 + +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.LinearLR(optimizer=sgd) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.LinearLR(learning_rate=sgd.get_lr(), total_steps=5) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiStepLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiStepLR.md new file mode 100644 index 00000000000..a64d1ab1074 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiStepLR.md @@ -0,0 +1,47 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.MultiStepLR + +### [torch.optim.lr_scheduler.MultiStepLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.MultiStepLR.html) + +```python +torch.optim.lr_scheduler.MultiStepLR(optimizer, + milestones, + gamma=0.1, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.MultiStepDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/MultiStepDecay_cn.html) + +```python +paddle.optimizer.lr.MultiStepDecay(learning_rate, + milestones, + gamma=0.1, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| milestones | milestones | 表示轮数下标列表,必须递增。参数完全一致。 | +| gamma | gamma | 表示学习率衰减率。参数完全一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer=sgd, milestones=[2,4,6]) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.MultiStepDecay(learning_rate=sgd.get_lr(), milestones=[2,4,6]) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiplicativeLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiplicativeLR.md new file mode 100644 index 00000000000..67be341fa93 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.MultiplicativeLR.md @@ -0,0 +1,44 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.MultiplicativeLR + +### [torch.optim.lr_scheduler.MultiplicativeLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.MultiplicativeLR.html) + +```python +torch.optim.lr_scheduler.MultiplicativeLR(optimizer, + lr_lambda, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.MultiplicativeDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/MultiplicativeDecay_cn.html) + +```python +paddle.optimizer.lr.MultiplicativeDecay(learning_rate, + lr_lambda, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| lr_lambda | lr_lambda | 表示 lambda 函数,其通过 epoch 计算出一个因子,该因子会乘以初始学习率。PyTorch 可以是 lambda 函数的列表,Paddle 只能表示 lambda 函数。当 PyTorch 是 lambda 函数的列表时,暂无转写方式。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.MultiplicativeLR(optimizer=sgd, lr_lambda=lambda x:0.95**x) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.MultiplicativeDecay(learning_rate=sgd.get_lr(), lr_lambda=lambda x:0.95**x) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.OneCycleLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.OneCycleLR.md new file mode 100644 index 00000000000..df8dd484b08 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.OneCycleLR.md @@ -0,0 +1,70 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.OneCycleLR + +### [torch.optim.lr_scheduler.OneCycleLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.OneCycleLR.html) + +```python +torch.optim.lr_scheduler.OneCycleLR(optimizer, + max_lr, + total_steps=None, + epochs=None, + steps_per_epoch=None, + pct_start=0.3, + anneal_strategy='cos', + cycle_momentum=True, + base_momentum=0.85, + max_momentum=0.95, + div_factor=25.0, + final_div_factor=10000.0, + three_phase=False, + last_epoch=- 1, + verbose=False) +``` + +### [paddle.optimizer.lr.OneCycleLR](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/OneCycleLR_cn.html) + +```python +paddle.optimizer.lr.OneCycleLR(max_learning_rate, + total_steps, + divide_factor=25., + end_learning_rate=0.0001, + phase_pct=0.3, + anneal_strategy='cos', + three_phase=False, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | - | PyTorch 的是 torch.optim.Optimizer 类,Paddle 无对应参数。 | +| max_lr | max_learning_rate | 表示最大学习率。参数完全一致。 | +| total_steps, epochs, steps_per_epoch | total_steps | 训练过程中总的迭代数。PyTorch 默认 total_steps 为 None,则需要从 PyTorch 的参数 steps_per_epoch 和 epochs 计算得出此参数,计算公式为:total_steps=steps_per_epoch*epochs,需要转写。 | +| pct_start | phase_pct | 表示学习率从初始学习率增长到最大学习率所需迭代数占总迭代数的比例。仅参数名不一致。 | +| anneal_strategy | anneal_strategy | 调整学习率的策略。必须是 ( cos , linear )其中之一。参数完全一致。 | +| cycle_momentum | - | 如果“True”,动量反向循环 'base_momentum' 和 'max_momentum' 之间的学习率。Paddle 无此参数,暂无转写方式。 | +| base_momentum | - | 每个参数组的循环中的动量下边界。Paddle 无此参数,暂无转写方式。 | +| max_momentum | - | 每个参数组的循环中的动量上边界。Paddle 无此参数,暂无转写方式。 | +| div_factor | divide_factor | 该参数用于推断初始学习率,公式为 initial_learning_rate = max_learning_rate/divide_factor。仅参数名不一致。 | +| final_div_factor | - | 通过 min_lr = initial_lr/final_div_factor 确定最小学习率。Paddle 无此参数,暂无转写方式。 | +| - | end_learning_rate | 最小学习率,学习率变化的下边界。PyTorch 无对应参数,Paddle 可通过公式:min_lr = max_lr/(div_factor * final_div_factor) 计算得出并设置。 | +| three_phase | three_phase | 是否使用三阶段调度策略。参数完全一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.OneCycleLR(optimizer=sgd, max_lr=0.01, steps_per_epoch=20, epochs=10) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.OneCycleLR(max_learning_rate=0.01, total_steps=20*10, end_learning_rate=max_lr/(25*10000)) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ReduceLROnPlateau.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ReduceLROnPlateau.md new file mode 100644 index 00000000000..d6e639bea88 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.ReduceLROnPlateau.md @@ -0,0 +1,62 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.ReduceLROnPlateau + +### [torch.optim.lr_scheduler.ReduceLROnPlateau](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.ReduceLROnPlateau.html) + +```python +torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, + mode='min', + factor=0.1, + patience=10, + threshold=0.0001, + threshold_mode='rel', + cooldown=0, + min_lr=0, + eps=1e-08, + verbose=False) +``` + +### [paddle.optimizer.lr.ReduceOnPlateau](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/ReduceOnPlateau_cn.html) + +```python +paddle.optimizer.lr.ReduceOnPlateau(learning_rate, + mode='min', + factor=0.1, + patience=10, + threshold=1e-4, + threshold_mode='rel', + cooldown=0, + min_lr=0, + epsilon=1e-8, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| mode | mode | 'min' 和 'max' 之一。通常情况下,为 'min',此时当 loss 停止下降时学习率将衰减。参数完全一致。 | +| factor | factor | 表示学习率衰减的比例。参数完全一致。 | +| patience | patience | 当 loss 连续 patience 个 epoch 没有下降(对应 mode: 'min')或上升(对应 mode: 'max')时,学习率才会衰减。参数完全一致。 | +| threshold | threshold | threshold 和 threshold_mode 两个参数将会决定 loss 最小变化的阈值。小于该阈值的变化将会被忽视。参数完全一致。 | +| threshold_mode | threshold_mode | 'rel' 和 'abs' 之一。在 'rel' 模式下,loss 最小变化的阈值是 last_loss * threshold,其中 last_loss 是 loss 在上个 epoch 的值。在 'abs' 模式下,loss 最小变化的阈值是 threshold。参数完全一致。 | +| cooldown | cooldown | 在学习率每次衰减之后,会进入时长为 cooldown 个 step 的冷静期。参数完全一致。 | +| min_lr | min_lr | 最小的学习率。衰减后的学习率最低下界限。参数完全一致。 | +| eps | epsilon | 如果新旧学习率间的差异小于 epsilon,则不会更新。仅参数名不一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer=sgd, 'min') + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.ReduceOnPlateau(learning_rate=sgd.get_lr(), 'min') +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.StepLR.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.StepLR.md new file mode 100644 index 00000000000..14c1537af22 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/optimizer/torch.optim.lr_scheduler.StepLR.md @@ -0,0 +1,47 @@ +## [ 组合替代实现 ]torch.optim.lr_scheduler.StepLR + +### [torch.optim.lr_scheduler.StepLR](https://pytorch.org/docs/stable/generated/torch.optim.lr_scheduler.StepLR.html) + +```python +torch.optim.lr_scheduler.StepLR(optimizer, + step_size, + gamma=0.1, + last_epoch=-1, + verbose=False) +``` + +### [paddle.optimizer.lr.StepDecay](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/optimizer/lr/StepDecay_cn.html) + +```python +paddle.optimizer.lr.StepDecay(learning_rate, + step_size, + gamma=0.1, + last_epoch=-1, + verbose=False) +``` + +两者 API 功能一致, 参数用法不一致,PyTorch 是 Scheduler 实例持有 Optimizer 实例,Paddle 是 Optimizer 实例持有 Scheduler 实例。由于持有关系相反,因此 Paddle 使用 Optimizer.set_lr_scheduler 来设置这种持有关系。具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------------------------ | +| optimizer | learning_rate | PyTorch 的 optimizer 类型是 torch.optim.Optimizer,Paddle 的 learning_rate 类型是 float,两者功能上不直接一致,但可通过设置 leaning_rate = optimizer.get_lr() 来对应一致。 | +| step_size | step_size | 表示学习率衰减轮数间隔。参数完全一致。 | +| gamma | gamma | 表示学习率衰减率。参数完全一致。 | +| last_epoch | last_epoch | 上一轮的轮数,重启训练时设置为上一轮的 epoch 数。参数完全一致。 | +| verbose | verbose | 如果是 True,则在每一轮更新时在标准输出 stdout 输出一条信息。参数完全一致。 | + +### 转写示例 +```python +# PyTorch 写法 +linear = torch.nn.Linear(10, 10) +sgd = torch.optimizer.SGD(lr=0.5, parameters=linear.parameters()) +scheduler = torch.optim.lr_scheduler.StepLR(optimizer=sgd, step_size=2) + +# Paddle 写法 +linear = paddle.nn.linear(10, 10) +sgd = paddle.optimizer.SGD(learning_rate=0.5, parameters=linear.parameters()) +scheduler = paddle.optimizer.lr.StepDecay(learning_rate=sgd.get_lr(), step_size=2) +sgd.set_lr_scheduler(scheduler) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/.gitkeep b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/.gitkeep new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.__version__.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.__version__.md new file mode 100644 index 00000000000..f77ba98decb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.__version__.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.__version__ + +### [torch.__version__]() + +```python +torch.__version__ +``` + +### [paddle.__version__]() + +```python +paddle.__version__ +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autocast.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autocast.md new file mode 100644 index 00000000000..0868b0e5375 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autocast.md @@ -0,0 +1,28 @@ +## [torch 参数更多]torch.autocast + +### [torch.autocast](https://pytorch.org/docs/stable/amp.html?highlight=autocast#torch.autocast) + +```python +torch.autocast(device_type, dtype=None, enabled=True, cache_enabled=None) +``` + +### [paddle.amp.auto_cast](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amp/auto_cast_cn.html) + +```python +paddle.amp.auto_cast(enable=True, custom_white_list=None, custom_black_list=None, level='O1', dtype='float16', use_promote=True) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| device_type | - | 设备类型,Paddle 不区分设备,可直接删除。 | +| enabled | enable | 是否开启自动混合精度。 | +| dtype | dtype | 使用的数据类型。 | +| cache_enabled | - | 是否启用权重缓存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | custom_white_list | 自定义算子白名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | custom_black_list | 自定义算子黑名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | level | 混合精度训练模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_promote | 当一个算子存在 float32 类型的输入时,按照 Promote to the Widest 原则,选择 float32 数据类型进行计算。仅在 AMP-O2 训练时可配置。默认为 True。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.backward.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.backward.md new file mode 100644 index 00000000000..9264f121659 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.backward.md @@ -0,0 +1,23 @@ +## [仅 paddle 参数更多]torch.autograd.Function.backward + +### [torch.autograd.Function.backward](https://pytorch.org/docs/stable/generated/torch.autograd.Function.backward.html#torch.autograd.Function.backward) + +```python +torch.autograd.Function.backward(ctx, *grad_outputs) +``` + +### [paddle.autograd.PyLayer.backward](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayer_cn.html#backward-ctx-args-kwargs) + +```python +paddle.autograd.PyLayer.backward(ctx, *args, **kwargs) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| ctx | ctx | 上下文对象。 | +| grad_outputs | args | forward 输出 Tensor 的梯度,仅参数名不一致。 | +| - | kwargs | forward 输出 Tensor 的梯度,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.forward.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.forward.md new file mode 100644 index 00000000000..fa8722770de --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.forward.md @@ -0,0 +1,23 @@ +## [参数完全一致]torch.autograd.Function.forward + +### [torch.autograd.Function.forward](https://pytorch.org/docs/stable/generated/torch.autograd.Function.forward.html#torch.autograd.Function.forward) + +```python +torch.autograd.Function.forward(ctx, *args, **kwargs) +``` + +### [paddle.autograd.PyLayer.forward](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayer_cn.html#forward-ctx-args-kwargs) + +```python +paddle.autograd.PyLayer.forward(ctx, *args, **kwargs) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------ | +| ctx | ctx | 上下文对象。 | +| args | args | 自定义算子的输入。 | +| kwargs | kwargs | 自定义算子的输入。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.md new file mode 100644 index 00000000000..bc50bde43fa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.Function.md @@ -0,0 +1,22 @@ +## [torch 参数更多]torch.autograd.Function + +### [torch.autograd.Function](https://pytorch.org/docs/stable/autograd.html#torch.autograd.Function) + +```python +torch.autograd.Function(*args, **kwargs) +``` + +### [paddle.autograd.PyLayer](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayer_cn.html#paddle.autograd.PyLayer) + +```python +paddle.autograd.PyLayer() +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,但该类一般用于继承实现,不会调用其参数。 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------- | +| args | - | 自定义参数,Paddle 无此参数,可直接删除。 | +| kwargs | - | 自定义参数,Paddle 无此参数,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.backward.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.backward.md new file mode 100644 index 00000000000..f961b9e7c90 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.backward.md @@ -0,0 +1,26 @@ +## [torch 参数更多]torch.autograd.backward + +### [torch.autograd.backward](https://pytorch.org/docs/stable/generated/torch.autograd.backward.html#torch.autograd.backward) + +```python +torch.autograd.backward(tensors, grad_tensors=None, retain_graph=None, create_graph=False, grad_variables=None, inputs=None) +``` + +### [paddle.autograd.backward](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/backward_cn.html) + +```python +paddle.autograd.backward(tensors, grad_tensors=None, retain_graph=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------------- | ------------ | ------------------------------------- | +| tensors | tensors | 将要计算梯度的 Tensors 列表。 | +| grad_tensors | grad_tensors | tensors 的初始梯度值。 | +| retain_graph | retain_graph | 如果为 False,反向计算图将被释放。 | +| create_graph | - | 是否创建图,Paddle 无此参数,暂无转写方式。 | +| grad_variables | - | 创建图关联变量,Paddle 无此参数,暂无转写方式。 | +| inputs | - | 将累积的梯度,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.enable_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.enable_grad.md new file mode 100644 index 00000000000..bf999c17e0f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.enable_grad.md @@ -0,0 +1,13 @@ +## [无参数]torch.autograd.enable_grad + +### [torch.autograd.enable_grad](https://pytorch.org/docs/stable/generated/torch.enable_grad.html#enable-grad) + +```python +torch.autograd.enable_grad() +``` + +### [paddle.enable_grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/enable_grad.html#enable-grad) + +```python +paddle.enable_grad() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.mark_non_differentiable.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.mark_non_differentiable.md new file mode 100644 index 00000000000..7d1cba81418 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.mark_non_differentiable.md @@ -0,0 +1,21 @@ +## [仅参数名不一致]torch.autograd.function.FunctionCtx.mark_non_differentiable + +### [torch.autograd.function.FunctionCtx.mark_non_differentiable](https://pytorch.org/docs/stable/generated/torch.autograd.function.FunctionCtx.mark_non_differentiable.html#torch.autograd.function.FunctionCtx.mark_non_differentiable) + +```python +torch.autograd.function.FunctionCtx.mark_non_differentiable(*args) +``` + +### [paddle.autograd.PyLayerContext.mark_non_differentiable](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayerContext_cn.html#mark-non-differentiable-self-tensors) + +```python +paddle.autograd.PyLayerContext.mark_non_differentiable(*tensors) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------- | +| args | tensors | 需要标记不需要反向的 Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.save_for_backward.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.save_for_backward.md new file mode 100644 index 00000000000..c3f9850d67d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.save_for_backward.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.autograd.function.FunctionCtx.save_for_backward + +### [torch.autograd.function.FunctionCtx.save_for_backward](https://pytorch.org/docs/stable/generated/torch.autograd.function.FunctionCtx.save_for_backward.html#torch.autograd.function.FunctionCtx.save_for_backward) + +```python +torch.autograd.function.FunctionCtx.save_for_backward(*tensors) +``` + +### [paddle.autograd.PyLayerContext.save_for_backward](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayerContext_cn.html#save-for-backward-tensors) + +```python +paddle.autograd.PyLayerContext.save_for_backward(*tensors) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------- | +| tensors | tensors | 需要被暂存的 Tensor。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.set_materialize_grads.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.set_materialize_grads.md new file mode 100644 index 00000000000..1f77d473b00 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.function.FunctionCtx.set_materialize_grads.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.autograd.function.FunctionCtx.set_materialize_grads + +### [torch.autograd.function.FunctionCtx.set_materialize_grads](https://pytorch.org/docs/stable/generated/torch.autograd.function.FunctionCtx.set_materialize_grads.html#torch.autograd.function.FunctionCtx.set_materialize_grads) + +```python +torch.autograd.function.FunctionCtx.set_materialize_grads(value) +``` + +### [paddle.autograd.PyLayerContext.set_materialize_grads](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/PyLayerContext_cn.html#set-materialize-grads-self-value) + +```python +paddle.autograd.PyLayerContext.set_materialize_grads(value) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------- | +| value | value | 是否要框架来初始化未初始化的反向梯度。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.hessian.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.hessian.md new file mode 100644 index 00000000000..255e0af87c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.hessian.md @@ -0,0 +1,27 @@ +## [torch 参数更多]torch.autograd.functional.hessian + +### [torch.autograd.functional.hessian](https://pytorch.org/docs/stable/generated/torch.autograd.functional.hessian.html#torch.autograd.functional.hessian) + +```python +torch.autograd.functional.hessian(func, inputs, create_graph=False, strict=False, vectorize=False, outer_jacobian_strategy='reverse-mode') +``` + +### [paddle.incubate.autograd.Hessian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/incubate/autograd/Hessian_cn.html) + +```python +paddle.incubate.autograd.Hessian(func, xs, is_batched=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------------------- | ------------ | ------------------------------------------------------------------- | +| func | func | Python 函数。 | +| inputs | xs | 函数 func 的输入参数。 | +| create_graph | - | 是否创建图,Paddle 无此参数,暂无转写方式。 | +| strict | - | 是否在存在一个与所有输出无关的输入时抛出错误,Paddle 无此参数,暂无转写方式。 | +| vectorize | - | 体验中功能,Paddle 无此参数,暂无转写方式。 | +| outer_jacobian_strategy | - | AD 计算模式,Paddle 无此参数,暂无转写方式。 | +| - | is_batched | 表示包含 batch 维,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jacobian.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jacobian.md new file mode 100644 index 00000000000..4db0c7c6fea --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jacobian.md @@ -0,0 +1,27 @@ +## [torch 参数更多]torch.autograd.functional.jacobian + +### [torch.autograd.functional.jacobian](https://pytorch.org/docs/stable/generated/torch.autograd.functional.jacobian.html#torch.autograd.functional.jacobian) + +```python +torch.autograd.functional.jacobian(func, inputs, create_graph=False, strict=False, vectorize=False, strategy='reverse-mode') +``` + +### [paddle.incubate.autograd.Jacobian](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/incubate/autograd/Jacobian_cn.html) + +```python +paddle.incubate.autograd.Jacobian(func, xs, is_batched=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| func | func | Python 函数。 | +| inputs | xs | 函数 func 的输入参数。 | +| create_graph | - | 是否创建图,Paddle 无此参数,暂无转写方式。 | +| strict | - | 是否在存在一个与所有输出无关的输入时抛出错误,Paddle 无此参数,暂无转写方式。 | +| vectorize | - | 体验中功能,Paddle 无此参数,暂无转写方式。 | +| strategy | - | AD 计算模式,Paddle 无此参数,暂无转写方式。 | +| - | is_batched | 表示包含 batch 维,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jvp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jvp.md new file mode 100644 index 00000000000..dcb94477a48 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.jvp.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.autograd.functional.jvp + +### [torch.autograd.functional.jvp](https://pytorch.org/docs/stable/generated/torch.autograd.functional.jvp.html#torch.autograd.functional.jvp) + +```python +torch.autograd.functional.jvp(func, inputs, v=None, create_graph=False, strict=False) +``` + +### [paddle.incubate.autograd.jvp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/incubate/autograd/jvp_cn.html) + +```python +paddle.incubate.autograd.jvp(func, xs, v=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| func | func | Python 函数。 | +| inputs | xs | 函数 func 的输入参数。 | +| v | v | 用于计算 jvp 的输入向量。 | +| create_graph | - | 是否创建图,Paddle 无此参数,暂无转写方式。 | +| strict | - | 是否在存在一个与所有输出无关的输入时抛出错误,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.vjp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.vjp.md new file mode 100644 index 00000000000..82b105d884e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.functional.vjp.md @@ -0,0 +1,25 @@ +## [torch 参数更多]torch.autograd.functional.vjp + +### [torch.autograd.functional.vjp](https://pytorch.org/docs/stable/generated/torch.autograd.functional.vjp.html#torch.autograd.functional.vjp) + +```python +torch.autograd.functional.vjp(func, inputs, v=None, create_graph=False, strict=False) +``` + +### [paddle.incubate.autograd.vjp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/incubate/autograd/vjp_cn.html) + +```python +paddle.incubate.autograd.vjp(func, xs, v=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| func | func | Python 函数。 | +| inputs | xs | 函数 func 的输入参数。 | +| v | v | 用于计算 vjp 的输入向量。 | +| create_graph | - | 是否创建图,Paddle 无此参数,暂无转写方式。 | +| strict | - | 是否在存在一个与所有输出无关的输入时抛出错误,Paddle 无此参数,暂无转写方式。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.grad.md new file mode 100644 index 00000000000..31a491f7b88 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.grad.md @@ -0,0 +1,29 @@ +## [torch 参数更多]torch.autograd.grad + +### [torch.autograd.grad](https://pytorch.org/docs/stable/generated/torch.autograd.grad.html#torch.autograd.grad) + +```python +torch.autograd.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, is_grads_batched=False) +``` + +### [paddle.grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/grad_cn.html) + +```python +paddle.grad(outputs, inputs, grad_outputs=None, retain_graph=None, create_graph=False, only_inputs=True, allow_unused=False, no_grad_vars=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------------- | ------------ | ------------------------------------------------------------ | +| outputs | outputs | 用于计算梯度的图的输出变量。 | +| inputs | inputs | 用于计算梯度的图的输入变量。 | +| grad_outputs | grad_outputs | outputs 变量梯度的初始值。 | +| retain_graph | retain_graph | 是否保留计算梯度的前向图。 | +| create_graph | create_graph | 是否创建计算过程中的反向图。 | +| only_inputs | only_inputs | 是否只计算 inputs 的梯度。 | +| allow_unused | allow_unused | 决定当某些 inputs 变量不在计算图中时抛出错误还是返回 None。 | +| is_grads_batched | - | 是否反向使用批量,Paddle 无此参数,暂无转写方式。 | +| - | no_grad_vars | 指明不需要计算梯度的变量,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.graph.saved_tensors_hooks.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.graph.saved_tensors_hooks.md new file mode 100644 index 00000000000..f99ec0e50c4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.graph.saved_tensors_hooks.md @@ -0,0 +1,22 @@ +## [参数完全一致]torch.autograd.graph.saved_tensors_hooks + +### [torch.autograd.graph.saved_tensors_hooks](https://pytorch.org/docs/stable/autograd.html?highlight=saved_tensors_hooks#torch.autograd.graph.saved_tensors_hooks) + +```python +torch.autograd.graph.saved_tensors_hooks(pack_hook, unpack_hook) +``` + +### [paddle.autograd.saved_tensors_hooks](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/autograd/saved_tensors_hooks_cn.html) + +```python +paddle.autograd.saved_tensors_hooks(pack_hook, unpack_hook) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| pack_hook | pack_hook | 当某个算子的前向执行时,存在 Tensor 需要保留给反向计算梯度使用时, pack_hook 将会被调用。 | +| unpack_hook | unpack_hook | 当反向执行,需要用到前向保留的 Tensor 时, unpack_hook 会被调用。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.profiler.profile.export_chrome_trace.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.profiler.profile.export_chrome_trace.md new file mode 100644 index 00000000000..cb3f89c27b5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.profiler.profile.export_chrome_trace.md @@ -0,0 +1,22 @@ +## [仅 paddle 参数更多]torch.autograd.profiler.profile.export_chrome_trace + +### [torch.autograd.profiler.profile.export_chrome_trace](https://pytorch.org/docs/stable/generated/torch.autograd.profiler.profile.export_chrome_trace.html#torch.autograd.profiler.profile.export_chrome_trace) + +```python +torch.autograd.profiler.profile.export_chrome_trace(path) +``` + +### [paddle.profiler.export_chrome_tracing](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/profiler/export_chrome_tracing_cn.html) + +```python +paddle.profiler.export_chrome_tracing(dir_name: str, worker_name: Optional[str] = None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------------------------------------- | +| path | dir_name | 性能数据导出所保存到的文件夹路径,仅参数名不一致。 | +| - | worker_name | 性能数据导出所保存到的文件名前缀,PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.set_grad_enabled.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.set_grad_enabled.md new file mode 100644 index 00000000000..2ce397fc9e1 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.autograd.set_grad_enabled.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.autograd.set_grad_enabled + +### [torch.autograd.set_grad_enabled](https://pytorch.org/docs/stable/generated/torch.set_grad_enabled.html) + +```python +torch.autograd.set_grad_enabled(mode) +``` + +### [paddle.set_grad_enabled](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/set_grad_enabled_cn.html) + +```python +paddle.set_grad_enabled(mode) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------- | +| mode | mode | 启用(True)或禁用(False)动态图梯度计算。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cuda.is_built.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cuda.is_built.md new file mode 100644 index 00000000000..7e6f6164066 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cuda.is_built.md @@ -0,0 +1,14 @@ +## [ 无参数 ]torch.backends.cuda.is_built + +### [torch.backends.cuda.is_built](https://pytorch.org/docs/stable/backends.html?highlight=torch+backends+cudnn+is_available#torch.backends.cuda.is_built) +```python +torch.backends.cuda.is_built() +``` + +### [paddle.device.is_compiled_with_cuda](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/device/is_compiled_with_cuda_cn.html#is-compiled-with-cuda) + +```python +paddle.device.is_compiled_with_cuda() +``` + +检测是否在 cuda 环境下编译安装包。无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cudnn.is_available.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cudnn.is_available.md new file mode 100644 index 00000000000..9ace0640470 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.backends.cudnn.is_available.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.backends.cudnn.is_available + +### [torch.backends.cudnn.is_available](https://pytorch.org/docs/stable/backends.html?highlight=torch+backends+cudnn+is_available#torch.backends.cudnn.is_available) +```python +torch.backends.cudnn.is_available() +``` + +检测当前 cudnn 是否可用。 + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +```python +# PyTorch 写法 +torch.backends.cudnn.is_available() + +# Paddle 写法 +bool(paddle.device.get_cudnn_version()) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.cpu.amp.autocast.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.cpu.amp.autocast.md new file mode 100644 index 00000000000..3cbae40e72a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.cpu.amp.autocast.md @@ -0,0 +1,27 @@ +## [仅 paddle 参数更多]torch.cpu.amp.autocast + +### [torch.cpu.amp.autocast](https://pytorch.org/docs/stable/amp.html?highlight=autocast#torch.cpu.amp.autocast) + +```python +torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloat16, cache_enabled=True) +``` + +### [paddle.amp.auto_cast](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/amp/auto_cast_cn.html) + +```python +paddle.amp.auto_cast(enable=True, custom_white_list=None, custom_black_list=None, level='O1', dtype='float16', use_promote=True) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| enabled | enable | 是否开启自动混合精度。 | +| dtype | dtype | 使用的数据类型。 | +| cache_enabled | - | 是否启用权重缓存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | custom_white_list | 自定义算子白名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | custom_black_list | 自定义算子黑名单,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | level | 混合精度训练模式,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | use_promote | 当一个算子存在 float32 类型的输入时,按照 Promote to the Widest 原则,选择 float32 数据类型进行计算。仅在 AMP-O2 训练时可配置。默认为 True。PyTorch 无此参数,Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.diag_embed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.diag_embed.md new file mode 100644 index 00000000000..b0e965174af --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.diag_embed.md @@ -0,0 +1,24 @@ +## [ 参数完全一致 ] torch.diag_embed + +### [torch.diag_embed](https://pytorch.org/docs/stable/generated/torch.diag_embed.html) + +```python +torch.diag_embed(input, offset=0, dim1=-2, dim2=-1) +``` + +### [paddle.diag_embed](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/diag_embed_cn.html) + +```python +paddle.diag_embed(input, offset=0, dim1=- 2, dim2=- 1) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| input | input | 输入变量,至少为 1D 数组,支持数据类型为 float32、float64、int32、int64。 | +| offset | offset | 从指定的二维平面中获取对角线的位置,默认值为 0,即主对角线。 | +| dim1 | dim1 | 填充对角线的二维平面的第一维,默认值为 -2。 | +| dim2 | dim2 | 填充对角线的二维平面的第二维,默认值为 -1。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.get_default_dtype.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.get_default_dtype.md new file mode 100644 index 00000000000..69a87deeceb --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.get_default_dtype.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.get_default_dtype + +### [torch.get_default_dtype](https://pytorch.org/docs/stable/generated/torch.get_default_dtype.html#torch-get-default-dtype) + +```python +torch.get_default_dtype() +``` + +### [paddle.get_default_dtype](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/get_default_dtype_cn.html#get-default-dtype) + +```python +paddle.get_default_dtype() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.is_grad_enabled.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.is_grad_enabled.md new file mode 100644 index 00000000000..2ecf914b558 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.is_grad_enabled.md @@ -0,0 +1,15 @@ +## [无参数]torch.is_grad_enabled + +### [torch.is_grad_enabled](https://pytorch.org/docs/stable/generated/torch.is_grad_enabled.html?highlight=torch+is_grad_enabled#torch.is_grad_enabled) + +```python +torch.is_grad_enabled() +``` + +### [paddle.is_grad_enabled](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/is_grad_enabled_cn.html#is-grad-enabled) + +```python +paddle.is_grad_enabled() +``` + +功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.jit.load.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.jit.load.md new file mode 100644 index 00000000000..4dc27e87ea6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.jit.load.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.jit.load + +### [torch.jit.load](https://pytorch.org/docs/stable/generated/torch.jit.load.html#torch.jit.load) + +```python +torch.jit.load(f, map_location=None, _extra_files=None) +``` + +### [paddle.jit.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/jit/load_cn.html) + +```python +paddle.jit.load(path, **configs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------------------- | +| f | path | PyTorch 为文件对象或文件名包含后缀,Paddle 为文件名不包含后缀,读取 .pdiparams,.pdmodel 等后缀文件。 | +| map_location | - | 存储位置,Paddle 无此参数,暂无转写方式。 | +| \_extra_files | - | 额外加载的文件,Paddle 无此参数,暂无转写方式。 | +| - | configs | 其他用于兼容的载入配置选项,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### f 参数用法不同 + +```python +# PyTorch 写法: +torch.jit.load('scriptmodule.pt') + +# Paddle 写法: +paddle.jit.load('example_model/linear') +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.manual_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.manual_seed.md new file mode 100644 index 00000000000..2d81cba98bc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.manual_seed.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.manual_seed + +### [torch.manual_seed](https://pytorch.org/docs/stable/generated/torch.manual_seed.html#torch-manual-seed) + +```python +torch.manual_seed(seed) +``` + +### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/seed_cn.html) + +```python +paddle.seed(seed) +``` + +两者参数和用法完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| seed | seed | 要设置的的随机种子,两者参数和用法完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.multiprocessing.spawn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.multiprocessing.spawn.md new file mode 100644 index 00000000000..70d40ba595f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.multiprocessing.spawn.md @@ -0,0 +1,26 @@ +## [torch 参数更多]torch.multiprocessing.spawn + +### [torch.multiprocessing.spawn](https://pytorch.org/docs/stable/multiprocessing.html#torch.multiprocessing.spawn) + +```python +torch.multiprocessing.spawn(fn, args=(), nprocs=1, join=True, daemon=False, start_method='spawn') +``` + +### [paddle.distributed.spawn](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/distributed/spawn_cn.html#spawn) + +```python +paddle.distributed.spawn(func, args=(), nprocs=- 1, join=True, daemon=False, **options) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| fn | func | Python 函数。 | +| args | args | 函数 func 的输入参数。 | +| nprocs | nprocs | 启动进程的数目。 与 PyTorch 默认值不同, Paddle 应设置为 `1`。 | +| join | join | 对所有启动的进程执行阻塞的 join,等待进程执行结束。 | +| start_method | - | 启动方式。 PyTorch 已弃用,Paddle 无此参数,对网络训练结果无影响,可直接删除。 | +| - | options | 其他初始化并行执行环境的配置选项。 PyTorch 无此参数, Paddle 保持默认即可。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.nansum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.nansum.md new file mode 100644 index 00000000000..4d7f615420c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.nansum.md @@ -0,0 +1,24 @@ +## [ 仅 paddle 参数更多 ] torch.nansum + +### [torch.nansum](https://pytorch.org/docs/stable/generated/torch.nansum.html) + +```python +torch.nansum(input, *, dtype=None) +``` + +### [paddle.nansum](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nansum_cn.html) + +```python +paddle.nansum(x, axis=None, dtype=None, keepdim=False, name=None) +``` + +Paddle 比 PyTorch 支持更多参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| input | x | 输入的 Tensor,数据类型为:float16、float32、float64、int32 或 int64。仅参数名不一致。 | +| - | axis | 求和运算的维度。PyTorch 无此参数,Paddle 保持默认即可。 | +| dtype | dtype | 输出变量的数据类型。若参数为空,则输出变量的数据类型和输入变量相同,默认值为 None。 | +| - | keepdim | 是否在输出 Tensor 中保留减小的维度。PyTorch 无此参数,Paddle 保持默认即可。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.no_grad.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.no_grad.md new file mode 100644 index 00000000000..20370edffbd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.no_grad.md @@ -0,0 +1,21 @@ +## [ 仅参数名不一致 ] torch.no_grad + +### [torch.no_grad](https://pytorch.org/docs/stable/generated/torch.no_grad.html) + +```python +torch.no_grad(orig_func=None) +``` + +### [paddle.no_grad](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/no_grad_cn.html) + +```python +paddle.no_grad(func=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| orig_func | func | no_grad 装饰器所应用的对象,仅参数名不同。no_grad 作为上下文管理器使用时,可忽略该参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.onnx.export.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.onnx.export.md new file mode 100644 index 00000000000..f7e6f80876e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.onnx.export.md @@ -0,0 +1,63 @@ +## [torch 参数更多]torch.onnx.export + +### [torch.onnx.export](https://pytorch.org/docs/stable/onnx.html#torch.onnx.export) + +```python +torch.onnx.export(model, args, f, export_params=True, verbose=False, training=, input_names=None, output_names=None, operator_export_type=, opset_version=None, do_constant_folding=True, dynamic_axes=None, keep_initializers_as_inputs=None, custom_opsets=None, export_modules_as_functions=False) +``` + +### [paddle.onnx.export](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/onnx/export_cn.html) + +```python +paddle.onnx.export(layer, path, input_spec=None, opset_version=9, **configs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------ | +| model | layer | 导出的模型,PyTorch 类型为 torch.nn.Module, torch.jit.ScriptModule 或 torch.jit.ScriptFunction,Paddle 为 Layer 对象,需要转写。 | +| args | - | 模型参数,Paddle 无此参数,暂无转写方式。 | +| f | path | PyTorch 为存储模型路径,Paddle 为存储模型的路径前缀,需要转写。 | +| export_params | - | 是否导出参数,Paddle 无此参数,暂无转写方式。 | +| verbose | - | 是否输出详细信息,Paddle 无此参数,暂无转写方式。 | +| training | - | 训练模式,Paddle 无此参数,暂无转写方式。 | +| input_names | - | 输入节点名称列表,Paddle 无此参数,暂无转写方式。 | +| output_names | - | 输出节点名称列表,Paddle 无此参数,暂无转写方式。 | +| operator_export_type | - | 操作导出类型,Paddle 无此参数,暂无转写方式。 | +| opset_version | opset_version | opset 版本。 | +| do_constant_folding | - | 是否进行 constant-folding 优化,Paddle 无此参数,暂无转写方式。 | +| dynamic_axes | - | 是否动态维度,Paddle 无此参数,暂无转写方式。 | +| keep_initializers_as_inputs | - | 是否增加初始化器到输入,Paddle 无此参数,暂无转写方式。 | +| custom_opsets | - | 自定义 opset,Paddle 无此参数,暂无转写方式。 | +| export_modules_as_functions | - | 是否导出模型为 functions,Paddle 无此参数,暂无转写方式。 | +| - | input_spec | 描述存储模型 forward 方法的输入,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | configs | 其他用于兼容的存储配置选项,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### 参数类型不同 + +```python +# PyTorch 写法 +torch.onnx.export( + model, + ( + x, + {y: z}, + {} + ), + "test.onnx.pb" +) + +# Paddle 写法 +model = Logic() +x = paddle.to_tensor([1]) +y = paddle.to_tensor([2]) +# Static and run model. +paddle.jit.to_static(model) +out = model(x, y, z=True) +paddle.onnx.export(model, 'pruned', input_spec=[x], output_spec=[out]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.optim.Optimizer.add_param_group.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.optim.Optimizer.add_param_group.md new file mode 100644 index 00000000000..28c7cefb01b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.optim.Optimizer.add_param_group.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ]torch.optim.Optimizer.add_param_group + +### [torch.optim.Optimizer.add_param_group](https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.add_param_group.html?highlight=torch+optim+optimizer+add_param_group#torch.optim.Optimizer.add_param_group) + +```python +torch.optim.Optimizer.add_param_group(param_group) +``` + +### [paddle.optimizer.Optimizer._add_param_group]() + +```python +paddle.optimizer.Optimizer._add_param_group(param_group) +``` + +参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------ | ------------ | ------------------------------------------------------------------- | +| param_group | param_group | 被添加的参数。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.profile.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.profile.md new file mode 100644 index 00000000000..fc3ff36c354 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.profile.md @@ -0,0 +1,64 @@ +## [torch 参数更多]torch.profiler.profile + +### [torch.profiler.profile](https://pytorch.org/docs/stable/profiler.html#torch.profiler.profile) + +```python +torch.profiler.profile(*, activities=None, schedule=None, on_trace_ready=None, record_shapes=False, profile_memory=False, with_stack=False, with_flops=False, with_modules=False, experimental_config=None, use_cuda=None) +``` + +### [paddle.profiler.Profiler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/profiler/Profiler_cn.html) + +```python +paddle.profiler.Profiler(*, targets=None, scheduler=None, on_trace_ready=None, record_shapes=False, profile_memory=False, timer_only=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------- | +| activities | targets | 指定性能分析所要分析的设备,PyTorch 为 torch.profiler.ProfilerActivity 类型,Paddle 为 paddle.profiler.ProfilerTarget 类型。 | +| schedule | scheduler | 如果是 Callable 对象,代表是性能分析器状态的调度器,仅参数名不一致。 | +| on_trace_ready | on_trace_ready | 处理性能分析器的回调函数。 | +| record_shapes | record_shapes | 如果设置为 True, 则会开启收集框架算子输入张量的 shape。 | +| profile_memory | profile_memory | 如果设置为 True, 则会开启收集显存分析的数据。 | +| with_stack | - | 记录 source 信息,Paddle 无此参数,暂无转写方式。 | +| with_flops | - | 使用公式来估计浮点计算,Paddle 无此参数,暂无转写方式。 | +| with_modules | - | 记录模块层次,Paddle 无此参数,暂无转写方式。 | +| experimental_config | - | 实验性特征配置,Paddle 无此参数,暂无转写方式。 | +| use_cuda | - | 已废弃,Paddle 无此参数,暂无转写方式。 | +| - | timer_only | 如果设置为 True,将只统计模型的数据读取和每一个迭代所消耗的时间,而不进行性能分析,PyTorch 无此参数,Paddle 保持默认即可。 | + +### 转写示例 + +#### 参数类型不同 + +```python +# PyTorch 写法: +with torch.profiler.profile( + activities=[ + torch.profiler.ProfilerActivity.CPU, + torch.profiler.ProfilerActivity.CUDA, + ], + schedule=torch.profiler.schedule( + wait=1, + warmup=1, + active=2), + on_trace_ready=torch.profiler.tensorboard_trace_handler('./log') +) as p: + for iter in range(10): + p.step() + +# Paddle 写法: +with paddle.profiler.Profiler( + targets=[ + paddle.profiler.ProfilerTarget.CPU, + paddle.profiler.ProfilerTarget.GPU + ], + scheduler=(2, 5), + on_trace_ready = paddle.profiler.export_chrome_tracing('./log') +) as p: + for iter in range(10): + p.step() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.schedule.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.schedule.md new file mode 100644 index 00000000000..a93d15c8dd3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.profiler.schedule.md @@ -0,0 +1,25 @@ +## [仅参数名不一致]torch.profiler.schedule + +### [torch.profiler.schedule](https://pytorch.org/docs/stable/profiler.html#torch.profiler.schedule) + +```python +torch.profiler.schedule(*, wait, warmup, active, repeat=0, skip_first=0) +``` + +### [paddle.profiler.make_scheduler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/profiler/make_scheduler_cn.html) + +```python +paddle.profiler.make_scheduler(*, closed, ready, record, repeat=0, skip_first=0) +``` + +两者功能一致,参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ------------ | ------------------------------------------------------------------- | +| wait | closed | 处于 wait/ProfilerState.CLOSED 状态的 step 数量,仅参数名不一致。 | +| warmup | ready | 处于 warmup/ProfilerState.READY 状态的 step 数量,仅参数名不一致。 | +| active | record | 处于 active/ProfilerState.RECORD 状态的 step 数量,仅参数名不一致。 | +| repeat | repeat | 重复次数。 | +| skip_first | skip_first | 首次 skip 步骤数量。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.get_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.get_rng_state.md new file mode 100644 index 00000000000..342213ff97f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.get_rng_state.md @@ -0,0 +1,33 @@ +## [参数不一致] torch.random.get_rng_state + +### [torch.random.get_rng_state](https://pytorch.org/docs/stable/random.html#torch.random.get_rng_state) + +```python +torch.random.get_rng_state() +``` + +### [paddle.get_rng_state]() + +```python +paddle.get_rng_state() +``` + +其中 PyTorch 与 Paddle 的返回参数类型不一致 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| Tensor | GeneratorState | 返回类型不一致, PyTorch 返回 torch.ByteTensor,Paddle 返回 GeneratorState 对象。需要转写。 | + + + +### 转写示例 +#### 返回参数类型不同 +```python +# PyTorch 写法 +x = torch.random.get_rng_state() + +# Paddle 写法 +x = paddle.get_rng_state() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.initial_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.initial_seed.md new file mode 100644 index 00000000000..049d2bc4340 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.initial_seed.md @@ -0,0 +1,21 @@ +## [ 组合替代实现 ]torch.random.initial_seed + +### [torch.random.initial_seed](https://pytorch.org/docs/stable/random.html#torch.random.initial_seed) + +```python +torch.random.initial_seed() +``` + +获取当前随机数种子。返回一个用于播种 RNG 的 64 位数字。 + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.random.initial_seed() + +# Paddle 写法 +paddle.get_rng_state()[0].current_seed() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.manual_seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.manual_seed.md new file mode 100644 index 00000000000..c480e500781 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.manual_seed.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.random.manual_seed + +### [torch.random.manual_seed](https://pytorch.org/docs/stable/random.html?highlight=torch+random+manual_seed#torch.random.manual_seed) + +```python +torch.random.manual_seed(seed) +``` + +### [paddle.seed](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/seed_cn.html) + +```python +paddle.seed(seed) +``` + +两者参数和用法完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| seed | seed | 要设置的的随机种子,两者参数和用法完全一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.seed.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.seed.md new file mode 100644 index 00000000000..962d9f64d3c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.seed.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.random.seed + +### [torch.random.seed](https://pytorch.org/docs/stable/random.html#torch.random.seed) +```python +torch.random.seed() +``` + +将生成随机数的种子设置为非确定性随机数。返回一个用于播种 RNG 的 64 位数字。 + +PaddlePaddle 目前无对应 API,可使用如下代码组合实现该 API。 + +### 转写示例 +```python +# PyTorch 写法 +torch.random.seed() + +# Paddle 写法 +paddle.get_rng_state()[0].current_seed() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.set_rng_state.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.set_rng_state.md new file mode 100644 index 00000000000..f80c3610e77 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.random.set_rng_state.md @@ -0,0 +1,34 @@ +## [参数不一致] torch.random.set_rng_state + +### [torch.random.set_rng_state](https://pytorch.org/docs/stable/random.html#torch.random.set_rng_state) + +```python +torch.random.set_rng_state(new_state) +``` + +### [paddle.set_rng_state]() + +```python +paddle.set_rng_state(state_list) +``` + +其中 PyTorch 与 Paddle 的输入参数类型不一致 + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| new_state | state_list | 表示需要设置的新状态,PyTorch 输入类型为 torch.ByteTensor, Paddle 为 list[GeneratorState], 需要转写。 | + + + +### 转写示例 + +#### new_state: 指定输入 +```python +# PyTorch 写法 +torch.random.set_rng_state(x) + +# Paddle 写法 +paddle.set_rng_state(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_default_dtype.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_default_dtype.md new file mode 100644 index 00000000000..208c9a96379 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_default_dtype.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.set_default_dtype + +### [torch.set_default_dtype](https://pytorch.org/docs/stable/generated/torch.set_default_dtype.html) + +```python +torch.set_default_dtype(d) +``` + +### [paddle.set_default_dtype](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/set_default_dtype_cn.html) + +```python +paddle.set_default_dtype(d) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| d | d | 全局默认数据类型,torch 支持 float32 和 float64,paddle 支持 float16、float32 和 float64。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_grad_enabled.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_grad_enabled.md new file mode 100644 index 00000000000..4356e1e74e5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.set_grad_enabled.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.set_grad_enabled + +### [torch.set_grad_enabled](https://pytorch.org/docs/stable/generated/torch.set_grad_enabled.html) + +```python +torch.set_grad_enabled(mode) +``` + +### [paddle.set_grad_enabled](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/set_grad_enabled_cn.html) + +```python +paddle.set_grad_enabled(mode) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ----------------------------------------------------------------------------------------- | +| mode | mode | 启用(True)或禁用(False)动态图梯度计算。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.digamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.digamma.md new file mode 100644 index 00000000000..7fc7d887e27 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.digamma.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ]torch.special.digamma +### [torch.special.digamma](https://pytorch.org/docs/stable/special.html#torch.special.digamma) +```python +torch.special.digamma(input, + *, + out=None) +``` + +### [paddle.digamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/special.digamma_cn.html) +```python +paddle.digamma(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.special.digamma(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.digamma(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erf.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erf.md new file mode 100644 index 00000000000..51ca2f6998e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erf.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.special.erf + +### [torch.special.erf](https://pytorch.org/docs/stable/special.html?highlight=torch+special+erf#torch.special.erf) + +```python +torch.special.erf(input, + out=None) +``` + +### [paddle.erf](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/erf_cn.html) + +```python +paddle.erf(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.erf(t, out=y) + +# Paddle 写法 +paddle.assign(paddle.erf(t), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfc.md new file mode 100644 index 00000000000..9d3e2772255 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfc.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.special.erfc + +### [torch.special.erfc](https://pytorch.org/docs/stable/special.html#torch.special.erfc) + +```python +torch.special.erfc(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.erfc(x) + +# Paddle 写法 +y = 1 - paddle.erf(x) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfcx.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfcx.md new file mode 100644 index 00000000000..501297330f0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfcx.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.special.erfcx + +### [torch.special.erfcx](https://pytorch.org/docs/stable/special.html#torch.special.erfcx) + +```python +torch.special.erfcx(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.erfcx(x) + +# Paddle 写法 +y = paddle.exp(x ** 2) * (1.0 - paddle.erf(x)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfinv.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfinv.md new file mode 100644 index 00000000000..1b346fa7722 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.erfinv.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.special.erfinv + +### [torch.special.erfinv](https://pytorch.org/docs/stable/special.html#torch.special.erfinv) + +```python +torch.special.erfinv(input, *, out=None) +``` + +### [paddle.erfinv](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/erfinv_cn.html) + +```python +paddle.erfinv(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.erfinv(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.erfinv(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.exp2.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.exp2.md new file mode 100644 index 00000000000..8c24106a81c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.exp2.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.special.exp2 + +### [torch.special.exp2](https://pytorch.org/docs/stable/special.html#torch.special.exp2) + +```python +torch.special.exp2(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.exp2(x) + +# Paddle 写法 +y = 2 ** x +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expit.md new file mode 100644 index 00000000000..2264c97e846 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expit.md @@ -0,0 +1,19 @@ +## [组合替代实现]torch.special.expit + +### [torch.special.expit](https://pytorch.org/docs/stable/special.html#torch.special.expit) + +```python +torch.special.expit(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.expit(x) + +# Paddle 写法 +y = 1 / (1 + 1 / paddle.exp(x)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expm1.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expm1.md new file mode 100644 index 00000000000..141e1364b92 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.expm1.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ]torch.special.expm1 +### [torch.special.expm1](https://pytorch.org/docs/stable/special.html#torch.special.expm1) + +```python +torch.special.expm1(input, + *, + out=None) +``` + +### [paddle.expm1](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/expm1_cn.html) + +```python +paddle.expm1(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 该 OP 的输入为多维 Tensor。数据类型为:float16、float32、float64,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.special.expm1([2, 3, 8, 7], [1, 5, 3, 3], out=y) + +# Paddle 写法 +paddle.assign(paddle.expm1([2, 3, 8, 7], [1, 5, 3, 3]), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.gammaln.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.gammaln.md new file mode 100644 index 00000000000..f681ac7e6e8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.gammaln.md @@ -0,0 +1,34 @@ +## [torch 参数更多]torch.special.gammaln + +### [torch.special.gammaln](https://pytorch.org/docs/stable/special.html#torch.special.gammaln) + +```python +torch.special.gammaln(input, *, out=None) +``` + +### [paddle.lgamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/lgamma_cn.html#lgamma) + +```python +paddle.lgamma(x, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.gammaln(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.lgamma(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0.md new file mode 100644 index 00000000000..84f0462bdba --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.special.i0 + +### [torch.special.i0](https://pytorch.org/docs/stable/special.html#torch.special.i0) + +```python +torch.special.i0(input, *, out=None) +``` + +### [paddle.i0](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/i0_cn.html) + +```python +paddle.i0(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +x = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) +torch.special.i0(x, out=y) + +# Paddle 写法 +x = paddle.to_tensor([1, 2, 3, 4, 5], dtype="float32") +paddle.assign(paddle.i0(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0e.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0e.md new file mode 100644 index 00000000000..7772b7ef5b3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i0e.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.special.i0e + +### [torch.special.i0e](https://pytorch.org/docs/stable/special.html#torch.special.i0e) + +```python +torch.special.i0e(input, *, out=None) +``` + +### [paddle.i0e](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/i0e_cn.html) + +```python +paddle.i0e(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +x = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) +torch.special.i0e(x, out=y) + +# Paddle 写法 +x = paddle.to_tensor([1, 2, 3, 4, 5], dtype="float32") +paddle.assign(paddle.i0e(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1.md new file mode 100644 index 00000000000..f686e040942 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.special.i1 + +### [torch.special.i1](https://pytorch.org/docs/stable/special.html#torch.special.i1) + +```python +torch.special.i1(input, *, out=None) +``` + +### [paddle.i1](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/i1_cn.html) + +```python +paddle.i1(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +x = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) +torch.special.i1(x, out=y) + +# Paddle 写法 +x = paddle.to_tensor([1, 2, 3, 4, 5], dtype="float32") +paddle.assign(paddle.i1(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1e.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1e.md new file mode 100644 index 00000000000..160ca681dd6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.i1e.md @@ -0,0 +1,36 @@ +## [torch 参数更多]torch.special.i1e + +### [torch.special.i1e](https://pytorch.org/docs/stable/special.html#torch.special.i1e) + +```python +torch.special.i1e(input, *, out=None) +``` + +### [paddle.i1e](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/i1e_cn.html) + +```python +paddle.i1e(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +x = torch.tensor([1, 2, 3, 4, 5], dtype=torch.float32) +torch.special.i1e(x, out=y) + +# Paddle 写法 +x = paddle.to_tensor([1, 2, 3, 4, 5], dtype="float32") +paddle.assign(paddle.i1e(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log1p.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log1p.md new file mode 100644 index 00000000000..2c05add048b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log1p.md @@ -0,0 +1,34 @@ +## [torch 参数更多 ]torch.special.log1p +### [torch.special.log1p](https://pytorch.org/docs/stable/special.html#torch.special.log1p) + +```python +torch.special.log1p(input, + *, + out=None) +``` + +### [paddle.log1p](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/log1p_cn.html#log1p) + +```python +paddle.log1p(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.special.log1p(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.log1p(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log_softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log_softmax.md new file mode 100644 index 00000000000..e85a5136d17 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.log_softmax.md @@ -0,0 +1,23 @@ +## [仅参数名不一致]torch.special.log_softmax + +### [torch.special.log_softmax](https://pytorch.org/docs/stable/special.html#torch.special.log_softmax) + +```python +torch.special.log_softmax(input, dim, *, dtype=None) +``` + +### [paddle.nn.functional.log_softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/log_softmax_cn.html) + +```python +paddle.nn.functional.log_softmax(x, axis=- 1, dtype=None, name=None) +``` + +其中功能一致, 仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| dim | axis | 指定对输入 x 进行运算的轴,仅参数名不一致。 | +| dtype | dtype | 输出 Tensor 的数据类型。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logit.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logit.md new file mode 100644 index 00000000000..fd0cbc4e5f9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logit.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.special.logit + +### [torch.special.logit](https://pytorch.org/docs/stable/special.html#torch.special.logit) + +```python +torch.special.logit(input, eps=None, *, out=None) +``` + +### [paddle.logit](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logit_cn.html) + +```python +paddle.logit(x, eps=None, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| eps | eps | 传入该参数后可将 x 的范围控制在 [eps,1−eps]。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.logit(x, out=y) + +# Paddle 写法 +paddle.assign(paddle.logit(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logsumexp.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logsumexp.md new file mode 100644 index 00000000000..b5693594802 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.logsumexp.md @@ -0,0 +1,32 @@ +## [ torch 参数更多 ]torch.special.logsumexp +### [torch.special.logsumexp](https://pytorch.org/docs/stable/special.html#torch.special.logsumexp) + +```python +torch.special.logsumexp(input, dim, keepdim=False, *, out=None) +``` + +### [paddle.logsumexp](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/logsumexp_cn.html) + +```python +paddle.logsumexp(x, axis=None, keepdim=False, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 输入的 Tensor.仅参数名不一致。 | +| dim | axis | 指定对输入进行计算的轴。仅参数名不一致。 | +| keepdim | keepdim | 是否在输出 Tensor 中保留减小的维度。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.special.logsumexp(input, dim=1, out=y) + +# Paddle 写法 +paddle.assign(paddle.logsumexp(input, axis=1), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.multigammaln.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.multigammaln.md new file mode 100644 index 00000000000..8a681489e07 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.multigammaln.md @@ -0,0 +1,35 @@ +## [torch 参数更多]torch.special.multigammaln + +### [torch.special.multigammaln](https://pytorch.org/docs/stable/special.html#torch.special.multigammaln) + +```python +torch.special.multigammaln(input, p, *, out=None) +``` + +### [paddle.multigammaln](https://github.com/PaddlePaddle/Paddle/blob/be090bd0bc9ac7a8595296c316b3a6ed3dc60ba6/python/paddle/tensor/math.py#L5099) + +```python +paddle.multigammaln(x, p, name=None) +``` + +其中 PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ----------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| p | p | 维度的数量。 | +| out | - | 表示输出的 Tensor, Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.multigammaln(x, p, out=y) + +# Paddle 写法 +paddle.assign(paddle.multigammaln(x, p), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.ndtri.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.ndtri.md new file mode 100644 index 00000000000..2a6c8c7c66f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.ndtri.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.special.ndtri + +### [torch.special.ndtri](https://pytorch.org/docs/stable/special.html#torch.special.ndtri) + +```python +torch.special.ndtri(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.ndtri(a) + +# Paddle 写法 +y = 2 ** (1/2) * paddle.erfinv(2*a-1) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.polygamma.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.polygamma.md new file mode 100644 index 00000000000..c9ce6bb72e9 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.polygamma.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ]torch.special.polygamma + +### [torch.special.polygamma](https://pytorch.org/docs/stable/special.html#torch.special.polygamma) + +```python +torch.special.polygamma(n, input, *, out=None) +``` + +### [paddle.polygamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/polygamma_cn.html#paddle.polygamma) + +```python +paddle.polygamma(x, n, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---------------------------------------------------- | +| n | n | 指定需要求解 n 阶多伽马函数。 | +| input | x | 表示输入的 Tensor,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.special.polygamma(n, x, out=y) + +# Paddle 写法 +paddle.assign(paddle.polygamma(x, n), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.psi.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.psi.md new file mode 100644 index 00000000000..daf40a4b757 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.psi.md @@ -0,0 +1,31 @@ +## [ torch 参数更多 ]torch.special.psi +### [torch.special.psi](https://pytorch.org/docs/stable/special.html#torch.special.psi) +```python +torch.special.psi(input, + *, + out=None) +``` + +### [paddle.digamma](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/special.digamma_cn.html) +```python +paddle.digamma(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor , Paddle 无此参数,需要转写。 | + +### 转写示例 +#### out:指定输出 +```python +# PyTorch 写法 +torch.special.psi(input, out=y) + +# Paddle 写法 +paddle.assign(paddle.digamma(input), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.round.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.round.md new file mode 100644 index 00000000000..cd0e79ef829 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.round.md @@ -0,0 +1,47 @@ +## [torch 参数更多]torch.special.round + +### [torch.special.round](https://pytorch.org/docs/stable/special.html#torch.special.round) + +```python +# torch.special.round 为 torch.round 别名,参数和 torch.round 相同 +torch.special.round(input, *, decimals=0, out=None) +``` + +### [paddle.round](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/round_cn.html) + +```python +paddle.round(x, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | -------------------------------------------------- | +| input | x | 输入的 Tensor,仅参数名不一致。 | +| decimals | - | 舍入到的小数位数,PaddlePaddle 无此参数,需要转写。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### decimals:要舍入到的小数位数 +```python +# PyTorch 写法 +torch.special.round(x, decimals=2) + +# Paddle 写法 +paddle.round(1e2 * x) / 1e2 + +# 注:Paddle 可使用 10 的 decimals 次方来实现 +``` + +#### out 参数:输出的 Tensor + +```python +# PyTorch 写法: +torch.special.round(x, out=y) + +# Paddle 写法: +paddle.assign(paddle.round(x), y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.sinc.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.sinc.md new file mode 100644 index 00000000000..1190122a8da --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.sinc.md @@ -0,0 +1,20 @@ +## [ 组合替代实现 ]torch.special.sinc + +### [torch.special.sinc](https://pytorch.org/docs/stable/special.html#torch.special.sinc) + +```python +torch.special.sinc(input, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.sinc(a) + +# Paddle 写法 +import numpy +y = paddle.where(a==0, x=paddle.to_tensor([1], dtype=a.dtype), y=paddle.sin(numpy.pi*a)/(numpy.pi*a)) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.softmax.md new file mode 100644 index 00000000000..383466744fa --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.softmax.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.special.softmax + +### [torch.special.softmax](https://pytorch.org/docs/stable/special.html#torch.special.softmax) + +```python +torch.special.softmax(input, dim, *, dtype=None) +``` + +### [paddle.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/functional/softmax_cn.html) + +```python +paddle.nn.functional.softmax(x, axis=- 1, dtype=None, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | --------------------------------------------- | +| input | x | 表示输入 Tensor ,仅参数名不一致。 | +| dim | axis | 表示对输入 Tensor 运算的轴 ,仅参数名不一致。 | +| dtype | dtype | 表示输入 Tensor 的数据类型 。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlog1py.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlog1py.md new file mode 100644 index 00000000000..975eb13c9a2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlog1py.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.special.xlog1py + +### [torch.special.xlog1py](https://pytorch.org/docs/stable/special.html#torch.special.xlog1py) + +```python +torch.special.xlog1py(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.xlog1py(a, b) + +# Paddle 写法 +y = a * paddle.log1p(b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlogy.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlogy.md new file mode 100644 index 00000000000..1473d9ec4b6 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.special.xlogy.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.special.xlogy + +### [torch.special.xlogy](https://pytorch.org/docs/stable/special.html#torch.special.xlogy) + +```python +torch.special.xlogy(input, other, *, out=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +y = torch.special.xlogy(a, b) + +# Paddle 写法 +y = a * paddle.log(b) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.t.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.t.md new file mode 100644 index 00000000000..7adc9490d58 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.t.md @@ -0,0 +1,21 @@ +## [ 参数完全一致 ] torch.t + +### [torch.t](https://pytorch.org/docs/stable/generated/torch.t.html) + +```python +torch.t(input) +``` + +### [paddle.t](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/t_cn.html) + +```python +paddle.t(input, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | --------------------------- | +| input | input | 要转置的矩阵,维度不大于 2。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_allclose.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_allclose.md new file mode 100644 index 00000000000..60bb3acd66f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_allclose.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.testing.assert_allclose + +### [torch.testing.assert_allclose](https://pytorch.org/docs/stable/testing.html?highlight=torch+testing+assert_allclose#torch.testing.assert_allclose) + +```python +torch.testing.assert_allclose(actual, expected, rtol=None, atol=None, equal_nan=True, msg='') +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.testing.assert_allclose(actual, expected, rtol=rtol, atol=atol, equal_nan=True, msg='error messege') + +# Paddle 写法 +assert paddle.allclose(actual, expected, rtol=rtol, atol=atol, equal_nan=True).item(), 'error messege' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_close.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_close.md new file mode 100644 index 00000000000..2bda0c77c58 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.testing.assert_close.md @@ -0,0 +1,19 @@ +## [ 组合替代实现 ]torch.testing.assert_close + +### [torch.testing.assert_close](https://pytorch.org/docs/stable/testing.html?highlight=assert_close#torch.testing.assert_close) + +```python +torch.testing.assert_close(actual, expected, *, allow_subclasses=True, rtol=None, atol=None, equal_nan=False, check_device=True, check_dtype=True, check_layout=True, check_stride=False, msg=None) +``` + +Paddle 无此 API,需要组合实现。 + +### 转写示例 + +```python +# PyTorch 写法 +torch.testing.assert_close(actual, expected, rtol=rtol, atol=atol, equal_nan=True, msg='error messege') + +# Paddle 写法 +assert paddle.allclose(actual, expected, rtol=rtol, atol=atol, equal_nan=True).item(), 'error messege' +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.where.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.where.md new file mode 100644 index 00000000000..cbb97e65b47 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/others/torch.where.md @@ -0,0 +1,35 @@ +## [ torch 参数更多 ] torch.where + +### [torch.where](https://pytorch.org/docs/stable/generated/torch.where.html) + +```python +torch.where(condition, input, other, *, out=None) +``` + +### [paddle.where](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/where_cn.html) + +```python +paddle.where(condition, x, y, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| condition | condition | 判断条件。 | +| input | x | 当 condition 为 true 时,选择 input 元素,仅参数名不一致。 | +| other | y | 当 condition 为 false 时,选择 other 中元素,仅参数名不一致。 | +| out | - | 表示输出的 Tensor,Paddle 无此参数,需要转写。 | + +### 转写示例 + +#### out:指定输出 + +```python +# PyTorch 写法 +torch.where(x > 0, x, y, out=z) + +# Paddle 写法 +paddle.assign(paddle.where(x > 0, x, y), z) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/pytorch_api_mapping_format_cn.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/pytorch_api_mapping_format_cn.md new file mode 100644 index 00000000000..bd6f94d3fd4 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/pytorch_api_mapping_format_cn.md @@ -0,0 +1,475 @@ +> 提交代码前请参考[官网](https://www.paddlepaddle.org.cn/documentation/docs/zh/dev_guides/code_contributing_path_cn.html)安装 `pre-commit`,规范化代码格式。 + +请严格根据此格式规范来新增《API 映射关系》,不符合规范的文档将不予合入,具体如下: + +# API 映射关系 - 格式规范 + +### [分类名称] api 全称 + +为了文档整体的一致性,我们统一了 API 映射关系的分类名称,共分为 7 大类: +> 注:第 1~3 类均为 API 层面一对一映射,根据参数层面的映射关系将其细分为三类。 + +* 第 1 类又分为五种情况:`无参数`、`参数完全一致`、`仅参数名不一致`、`仅 paddle 参数更多`、`仅参数默认值不一致`。 +> 注:分类优先级依次递增,即如果同时 `参数名不一致` + `仅 paddle 参数更多`,则写成后者 `仅 paddle 参数更多` 。 + +* 第 2 类为 `torch 参数更多`。如果 torch 和 paddle 都支持更多参数,统一写成`torch 参数更多`。 + +* 第 3 类又分为三种情况:`输入参数类型不一致`、`输入参数用法不一致`、`返回参数类型不一致`。 +> 注意:这里的**不一致**都是从 torch 的角度来看,如果 paddle 可涵盖 torch,即 torch 是 paddle 的功能子集,则认定为一致(例如:torch 参数仅支持 list,paddle 参数支持 list/tuple),反之才认定为不一致。 + +* 第 4 类为 `组合替代实现` ,表示该 API 没有可直接对应的 API,需要通过多个 API 组合实现。 + +* 第 5 类为 `涉及上下文修改` ,表示涉及到上下文的分析,需要修改其他位置的代码。 +> 举例:所有的 `torch.optim.lr_scheduler.*`、`torch.nn.init.*`、`torch.nn.utils.clip*` 都为该类。此类 API 由于两者在设计上具有较大的差异,需要对上下文进行分析,涉及到上下文代码的联动修改。 + +* 第 6 类为 `可删除` 。表示可直接删除该 API,则无需写差异分析文档,仅标注即可 + +* 第 7 类为 `功能缺失` ,表示 Paddle 当前无对应 API,则无需写差异分析文档,仅标注即可。 + +> 注意: +> 1. 分类优先级依次递增,即如果同时 `第 2 类:torch 参数更多` 与 `第 3 类:参数不一致` ,则写成后者 `第 3 类:参数不一致` 。 +> 2. 所有的 Paddle API 无需关注 `name` 参数,直接忽略即可。 +> 3. 将类成员 API 映射为非类成员 API,则无需对比第一个参数。例如将 `torch.Tensor.outer(vec2)` 映射为 `paddle.outer(x, y)`,则忽略 paddle 的第一个参数,从 torch 的 `vec2` 和 paddle 的 `y` 开始对比。 + +### [pytorch api 全称] (pytorch api 链接) + +```python +PyTorch API 签名 +``` + +### [paddle api 全称] (paddle api 链接) + +```python +Paddle API 签名 +``` + +**一句话总结**。整体概述总结两个 API 的差异。例如 `第 3 类:参数不一致` ,需要简述下有哪些不一致的地方。在描写参数时,需要用 \` ` 来加深其底色。 + +### 参数映射 + +参数映射表的左边是`PyTorch` 对应参数,右边是`Paddle`对应参数,表格参数顺序按 `PyTorch` 参数顺序来。 + +* 如果 `无参数`,则没有参数映射这一栏。 + +* 如果 `参数完全一致`,无需转写示例。 + +* 如果 `仅参数名不一致`,无需转写示例,需要在备注栏里对该参数加一句 `仅参数名不一致`。 + +* 如果 `仅 paddle 参数更多`,无需转写示例,需要在备注栏加一句 `PyTorch 无此参数,(Paddle 应如何设置此参数)` 。如果默认无影响,则写 `PyTorch 无此参数,Paddle 保持默认即可`。 + +* 如果 `仅参数默认值不一致`,无需转写示例,需要在备注栏里加一句 `与 PyTorch 默认值不同,(Paddle 应如何设置此参数)` 。 + +* 如果 `torch 参数更多`,对每个 torch 多的参数都需要转写示例,需要在备注栏里加一句 `Paddle 无此参数,需要转写` ;如确实无法转写,需要在备注里写 `Paddle 无此参数,暂无转写方式` ;若可直接删除,则需要写 `Paddle 无此参数,一般对网络训练结果影响不大,可直接删除` 。 + +* 如果 `参数不一致`,对每个不一致的参数都需要转写示例,需要在备注栏里写 `(说明不一致的用法),需要转写`;如确实无法转写,需要在备注里写 `(说明不一致的用法),暂无转写方式`。 + +* 每个备注都需要`以句号结尾`。 + +### 转写示例 + +**除第 1 类 API 映射关系较为简单,无需写转写示例,其他类 API 都需要写转写示例,否则需说明:Paddle 暂无转写方式。** + +转写示例需要写得精简和一目了然。一般情形下只需写两行代码,无需打印各种结果,并且要保证转写前后的输出结果是一致的。另外需要先描述下待写的是该 torch api 的哪个参数及其功能。 + +#### 参数名 1:参数功能 1 +```python +# PyTorch 写法 +torch.xxx() + +# Paddle 写法 +paddle.xxx() +``` + +#### 参数名 2:参数功能 2 +```python +# PyTorch 写法 +torch.xxx() + +# Paddle 写法 +paddle.xxx() +``` + +-------------- + +# API 映射关系 - 模板 + +## 模板 1 + +### [ 无参数 ] torch.Tensor.t + +### [torch.Tensor.t](https://pytorch.org/docs/stable/generated/torch.Tensor.t.html#torch.Tensor.t) + +```python +torch.Tensor.t() +``` + +### [paddle.Tensor.t](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/Tensor_cn.html#t-name-none) + +```python +paddle.Tensor.t() +``` + +两者功能一致,无参数。 + +## 模板 2 + +### [ 参数完全一致 ] torch.Tensor.clip + +### [torch.Tensor.clip](https://pytorch.org/docs/stable/generated/torch.Tensor.clip.html?highlight=clip#torch.Tensor.clip) + +```python +torch.Tensor.clip(min=None, max=None) +``` + +### [paddle.Tensor.clip](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/Tensor_cn.html#clip-min-none-max-none-name-none) + +```python +paddle.Tensor.clip(min=None, max=None, name=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|---------|--------------| -------------------------------------------------- | +| min | min | 裁剪的最小值,输入中小于该值的元素将由该元素代替。 | +| max | max | 裁剪的最大值,输入中大于该值的元素将由该元素代替。 | + + +## 模板 3 + +### [ 仅参数名不一致 ] torch.dist + +### [torch.dist](https://pytorch.org/docs/stable/generated/torch.dist.html?highlight=dist#torch.dist)(仅作为示例) + +```python +torch.dist(input, + other, + p=2) +``` + +### [paddle.dist](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/dist_cn.html#dist)(仅作为示例) + +```python +paddle.dist(x, + y, + p=2) +``` + +两者功能一致且参数用法一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| --------- | ----------- | ------------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| other | y | 表示输入的 Tensor ,仅参数名不一致。 | +| dim | axis | 表示进行运算的轴,仅参数名不一致。 | +| dtype | dtype | 表示数据类型。 | +| size | shape | 表示输出形状大小。 | +| n | num_rows | 生成 2-D Tensor 的行数,仅参数名不一致。 | +| m | num_columns | 生成 2-D Tensor 的列数, 仅参数名不一致。 | +| start_dim | start_axis | 表示 flatten 展开的起始维度。 | +| end_dim | stop_axis | 表示 flatten 展开的结束维度。 | +| ndarray | data | 表示需要转换的数据, PyTorch 只能传入 numpy.ndarray , Paddle 可以传入 scalar 、 list 、 tuple 、 numpy.ndarray 、 paddle.Tensor 。 | + + +## 模板 4 + +### [ 仅 paddle 参数更多 ] torch.ZeroPad2d + +### [torch.nn.ZeroPad2d](https://pytorch.org/docs/stable/generated/torch.nn.ZeroPad2d.html?highlight=zeropad#torch.nn.ZeroPad2d)(仅作为示例) + +```python +torch.nn.ZeroPad2d(padding) +``` + +### [paddle.nn.ZeroPad2D](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/ZeroPad2D_cn.html)(仅作为示例) + +```python +paddle.nn.ZeroPad2D(padding, + data_format='NCHW', + name=None) +``` + +Paddle 相比 PyTorch 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------- | ------------- | ------------------------------------------------------------ | +| - | axis | 指定进行运算的轴, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | keepdim | 是否在输出 Tensor 中保留减小的维度, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | dtype | 输出 Tensor 的数据类型, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | dtype | 表示数据类型, PyTorch 无此参数, Paddle 保持默认即可。 | +| - | place | 表示 Tensor 存放位置, PyTorch 无此参数, Paddle 需设置为 paddle.CPUPlace()。 | +| - | stop_gradient | 表示是否阻断梯度传导, PyTorch 无此参数, Paddle 保持默认即可。 | + + +## 模板 5 + +## [ 仅参数默认值不一致 ] torch.linalg.svd + +### [torch.linalg.svd](https://pytorch.org/docs/stable/generated/torch.linalg.svd.html?highlight=svd#torch.linalg.svd) + +```python +torch.linalg.svd(A, full_matrices=True) +``` + +### [paddle.linalg.svd](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/linalg/svd_cn.html) + +```python +paddle.linalg.svd(x, full_matrices=False, name=None) +``` + +两者功能一致且参数用法一致,仅参数默认值不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| A | x | 输入 Tensor,仅参数名不一致。 | +| full_matrices | full_matrices | 是否计算完整的 U 和 V 矩阵,PyTorch 为 True,Paddle 为 False,Paddle 需设置为与 PyTorch 一致。 | + + +## 模板 6 + +### [ torch 参数更多 ] torch.abs + +### [torch.abs](https://pytorch.org/docs/stable/generated/torch.abs.html?highlight=abs#torch.abs)(仅作为示例) + +```python +torch.abs(input, + *, + out=None) +``` + +### [paddle.abs](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/abs_cn.html#abs)(仅作为示例) + +```python +paddle.abs(x, + name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------------- | ------ | ------------------------------------------------------------ | +| input | x | 表示输入的 Tensor ,仅参数名不一致。 | +| out | - | 表示输出的 Tensor ,Paddle 无此参数,需要转写。 | +| *size | shape | 表示输出形状大小, PyTorch 是多个元素,Paddle 是列表或元组,需要转写。 | +| layout | - | 表示布局方式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| device | - | 表示 Tensor 存放设备位置,Paddle 无此参数,需要转写。 | +| requires_grad | - | 表示是否计算梯度, Paddle 无此参数,需要转写。 | +| memory_format | - | 表示内存格式, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memeory | - | 表示是否使用锁页内存, Paddle 无此参数,需要转写。 | +| generator | - | 用于采样的伪随机数生成器, Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| size_average | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| reduce | - | PyTorch 已弃用, Paddle 无此参数,需要转写。 | +| async_op | - | 是否异步操作,Paddle 无此参数,暂无转写方式。 | +| antialias | - | 是否使用 anti-aliasing,Paddle 无此参数,暂无转写方式。 | + +### 转写示例 +#### size:输出形状大小 +```python +# PyTorch 写法 +torch.empty(3, 5) + +# Paddle 写法 +paddle.empty([3, 5]) +``` + +#### out:指定输出 +```python +# PyTorch 写法 +torch.abs([-3, -5], out=y) + +# Paddle 写法 +paddle.assign(paddle.abs([-3, -5]), y) +``` + +#### device: Tensor 的设备 +```python +# PyTorch 写法 +torch.zeros_like(x, device=torch.device('cpu')) + +# Paddle 写法 +y = paddle.zeros_like(x) +y.cpu() +``` + +#### requires_grad:是否求梯度 +```python +# PyTorch 写法 +x = torch.zeros_like(x, requires_grad=True) + +# Paddle 写法 +x = paddle.zeros_like(x) +x.stop_gradient = False +``` +#### pin_memory:是否分配到固定内存上 +```python +# PyTorch 写法 +x = torch.empty_like((2, 3), pin_memory=True) + +# Paddle 写法 +x = paddle.empty_like([2, 3]).pin_memory() +``` + +#### size_average:做 reduce 的方式 +```python +# PyTorch 的 size_average、reduce 参数转为 Paddle 的 reduction 参数 +if size_average is None: + size_average = True +if reduce is None: + reduce = True + +if size_average and reduce: + reduction = 'mean' +elif reduce: + reduction = 'sum' +else: + reduction = 'none' +``` + + +## 模板 7 + +### [ 输入参数用法不一致 ] torch.transpose + +### [torch.transpose](https://pytorch.org/docs/stable/generated/torch.transpose.html?highlight=transpose#torch.transpose)(仅作为示例) + +```python +torch.transpose(input, + dim0, + dim1) +``` + +### [paddle.transpose](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/transpose_cn.html#transpose)(仅作为示例) + +```python +paddle.transpose(x, + perm, + name=None) +``` + +PyTorch 的 `tensors` 参数与 Paddle 的 `inputs` 参数用法不同,具体如下: + +### 参数映射 + +| PyTorch | Paddle | 备注 | +| ------- | ------------- | ------------------------------------------------------------ | +|*tensors | inputs | 一组输入 Tensor,PyTorch 的 tensors 为可变参数,Paddle 的 inputs 为 list(Tensor) 或 tuple(Tensor) 用法,需要转写。 | +| 返回值 | 返回值 | 返回参数类型不一致, PyTorch 返回 torch.ByteTensor,Paddle 返回 GeneratorState 对象,暂无转写方式。 | + + +### 转写示例 +#### *tensors: 一组输入 Tensor,可变参数用法 +```python +# PyTorch 写法 +torch.broadcast_tensors(x, y) + +# Paddle 写法 +paddle.broadcast_tensors([x, y]) +``` + +#### affine:是否进行反射变换 + +```python +affine=False 时,表示不更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24, affine=False) + +# Paddle 写法 +weight_attr = paddle.ParamAttr(learning_rate=0.0) +bias_attr = paddle.ParamAttr(learning_rate=0.0) +m = paddle.nn.BatchNorm1D(24, weight_attr=weight_attr, bias_attr=bias_attr) + +affine=True 时,表示更新: + +# PyTorch 写法 +m = torch.nn.BatchNorm1D(24) + +# Paddle 写法 +m = paddle.nn.BatchNorm1D(24) +``` + +## 模板 8 + +### [ 组合替代实现 ] torch.addcmul + +### [torch.addcmul](https://pytorch.org/docs/master/generated/torch.addcmul.html#torch.addcmul) + +```python +torch.addcmul(input, tensor1, tensor2, *, value=1, out=None) +``` + +用于实现矩阵 `tensor1` 与矩阵 `tensor2` 相乘,再加上输入 `input` ,公式为: + +$ out = input + value * tensor1 * tensor2 $ + +PaddlePaddle 目前无对应 API,可使用如下代码组合替代实现: + +### 转写示例 + +```python +# PyTorch 写法 +torch.addcmul(input, tensor1, tensor2, value=value) + +# Paddle 写法 +paddle.add(input, value * tensor1 * tensor2) +``` + +## 模板 9 + +### [ 涉及上下文修改 ] torch.nn.utils.clip_grad_value_ + +### [torch.nn.utils.clip_grad_value_](https://pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_value_.html?highlight=clip_grad_value_#torch.nn.utils.clip_grad_value_)(仅作为示例) + +```python +torch.nn.utils.clip_grad_value_(parameters, + clip_value) +``` + +### [paddle.nn.ClipGradByValue](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/nn/ClipGradByValue_cn.html#clipgradbyvalue)(仅作为示例) + +```python +paddle.nn.ClipGradByValue(max, + min=None) +``` + +其中 PyTorch 与 Paddle 对该 API 的设计思路与⽤法不同,需要分析上下⽂并联动修改: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------- | ------------ | ---- | +| parameters | - | 表示要操作的 Tensor, PyTorch 属于原位操作, PaddlePaddle ⽆此参数,需要实例化之后在 optimizer 中设置才可以使⽤。需要上下⽂分析与联动修改。| +| clip_value | max | 表示裁剪梯度的范围,范围为 [-clip_value, clip_vale] ; PaddlePaddle 的 max 参数可实现该参数功能,直接设置为与 clip_value 一致。| +| - | min | 表示裁剪梯度的最⼩值, PyTorch ⽆此参数, Paddle 保持默认即可。 | + +### 转写示例 + +```python +# torch ⽤法 +net = Model() +sgd = torch.optim.SGD(net.parameters(), lr=0.1) +for i in range(10): + loss = net(x) + loss.backward() + torch.nn.utils.clip_grad_value_(net.parameters(), 1.) + sgd.step() + +# paddle ⽤法 +net = Model() +sgd = paddle.optim.SGD(net.parameters(), lr=0.1, +grad_clip=paddle.nn.ClipGradByValue(), 1.) +for i in range(10): + loss = net(x) + loss.backward() + sgd.step() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.addmm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.addmm.md new file mode 100644 index 00000000000..c941c08896b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.addmm.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ] torch.sparse.addmm + +### [torch.sparse.addmm](https://pytorch.org/docs/stable/generated/torch.sparse.addmm.html?highlight=addmm#torch.sparse.addmm) + +```python +# PyTorch 文档有误,测试 PyTorch 第一个参数名为 input +torch.sparse.addmm(input, mat1, mat2, beta=1.0, alpha=1.0) +``` + +### [paddle.sparse.addmm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/addmm_cn.html) + +```python +paddle.sparse.addmm(input, x, y, beta=1.0, alpha=1.0, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +|PyTorch | PaddlePaddle | 备注 | +|--------| ------------- | --------------------------------------------------------------------------------------| +|input | input| 输入 Tensor。| +|mat1 | x |输入 Tensor,仅参数名不一致。| +|mat2|y| 输入 Tensor,仅参数名不一致。| +|beta|beta| input 的系数,默认 1.0。两者完全一致| +|alpha|alpha| x * y 的系数,默认 1.0。两者完全一致| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.mm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.mm.md new file mode 100644 index 00000000000..e7c20476c4e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.mm.md @@ -0,0 +1,23 @@ +## [ 仅参数名不一致 ] torch.sparse.mm + +### [torch.sparse.mm](https://pytorch.org/docs/stable/generated/torch.sparse.mm.html?highlight=torch+sparse+mm#torch.sparse.mm) + +```python +# PyTorch 文档有误,测试 PyTorch 参数名为 sparse, dense +torch.sparse.mm(sparse, dense) +``` + +### [paddle.sparse.matmul](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/matmul_cn.html) + +```python +paddle.sparse.matmul(x, y, name=None) +``` + +两者功能一致,仅参数名不一致,具体如下: + +### 参数映射 + + |PyTorch | PaddlePaddle | 备注| + |--------| ------------- | ------| + |sparse | x| 输入的 Tensor,仅参数名不一致。| + |dense | y |输入的第二个 Tensor,仅参数名不一致。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.softmax.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.softmax.md new file mode 100644 index 00000000000..343f325672e --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.softmax.md @@ -0,0 +1,33 @@ +## [ torch 参数更多 ] torch.sparse.softmax + +### [torch.sparse.softmax](https://pytorch.org/docs/stable/generated/torch.sparse.softmax.html#torch.sparse.softmax) + +```python +torch.sparse.softmax(input, dim, dtype=None) +``` + +### [paddle.sparse.nn.functional.softmax](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/nn/functional/softmax_cn.html) + +```python +paddle.sparse.nn.functional.softmax(x, axis=-1, name=None) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + + |PyTorch | PaddlePaddle | 备注 | + |--------| -------------| --------------------------------------------------------------------------------------| + |input |x | 输入的稀疏 Tensor,仅参数名不一致。| + |dim | axis| 指定对输入 SparseTensor 计算 softmax 的轴,Paddle 的默认值:-1。仅参数名不一致。| + |dtype | - | 指定数据类型,可选项,PyTorch 默认值为 None,Paddle 无此参数,需要转写。| +### 转写示例 +#### dytpe:指定数据类型 +```Python +# PyTorch 写法 +y = torch.sparse.softmax(x, dim=-1, dtype=torch.float32) + +# Paddle 写法 +y = paddle.sparse.cast(x, value_dtype='float32') +y = paddle.sparse.nn.functional.softmax(y) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.sum.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.sum.md new file mode 100644 index 00000000000..5bca5e0c535 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/sparse/torch.sparse.sum.md @@ -0,0 +1,35 @@ +## [ 参数不一致 ] torch.sparse.sum + +### [torch.sparse.sum](https://pytorch.org/docs/stable/generated/torch.sparse.sum.html?highlight=sparse+sum#torch.sparse.sum) + +```python +torch.sparse.sum(input, dim=None, dtype=None) +``` + +### [paddle.sparse.sum](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/sparse/sum_cn.html#sum) + +```python +paddle.sparse.sum(x, axis=None, dtype=None, keepdim=False, name=None) +``` + +输入参数不一致和返回类型不一致,具体如下: + +### 参数映射 + + |PyTorch | PaddlePaddle | 备注| + |--------| ------------- | ------| + |input | x| 输入的 Tensor,仅参数名不一致。| + |dim | axis |输入的第二个 Tensor,仅参数名不一致。| + |dtype | dtype |输出数据的类型。| + |- | keepdim |是否留减少的维度, PyTorch 无此参数, Paddle 保持默认即可。| + |返回值 | 返回值 |当不指定 dim 时,PyTorch 返回 0D Tensor, Paddle 返回 Sparse Tensor。| + +### 转写示例 +#### 返回类型:当不指定 dim 时,PyTorch 返回 0D Tensor, Paddle 返回 Sparse Tensor。 +```Python +# PyTorch 写法 +y = torch.sparse.sum(x) + +# Paddle 写法 +y = paddle.sparse.sum(x).values() +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.parameter.Parameter.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.parameter.Parameter.md new file mode 100644 index 00000000000..4b952c0e438 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.parameter.Parameter.md @@ -0,0 +1,70 @@ +## [ 参数不一致 ]torch.nn.parameter.Parameter +### [torch.nn.parameter.Parameter](https://pytorch.org/docs/stable/generated/torch.nn.parameter.Parameter.html?highlight=torch%20nn%20parameter#torch.nn.parameter.Parameter) + +```python +torch.nn.parameter.Parameter(data=None, + requires_grad=True) +``` + +### [paddle.create_parameter](https://github.com/PaddlePaddle/Paddle/blob/release/2.1/python/paddle/fluid/layers/tensor.py#L77) + +```python +paddle.create_parameter(shape, + dtype, + name=None, + attr=None, + is_bias=False, + default_initializer=None) +``` + +两者功能一致但参数不一致,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| data | - | 参数 Tensor,Paddle 无此参数。 | +| requires_grad | - | ,Paddle 无此参数。 | +| - | shape | 指定输出 Tensor 的形状,PyTorch 无此参数。 | +| - | dtype | 初始化数据类型,PyTorch 无此参数。 | +| - | attr | 指定参数的属性对象,PyTorch 无此参数。 | +| - | is_bias | 当 default_initializer 为空,该值会对选择哪个默认初始化程序产生影响。如果 is_bias 为真,则使用 initializer.Constant(0.0),否则使用 Xavier(),PyTorch 无此参数。 | +| - | default_initializer | 参数的初始化程序,PyTorch 无此参数。 | + +### 功能差异 + +#### 使用方式 +***PyTorch***:通过设置`data`将 Tensor 赋给 Parameter。 +***PaddlePaddle***:有 2 种方式创建 Parameter。方式一:通过设置`attr`将 ParamAttr 赋给 Parameter;方式二:通过设置`shape`(大小)、`dtype`(类型)、`default_initializer`(初始化方式)设置 Parameter。 + +#### 梯度设置 +***PyTorch***:通过设置`requires_grad`确定是否进行梯度反传。 +***PaddlePaddle***:PaddlePaddle 无此功能。 + + +### 代码示例 +``` python +# PyTorch 示例: +import torch +x = torch.zeros(2, 3) +param = torch.nn.parameter.Parameter(x, requires_grad=False) + +# 输出 +# Parameter containing: +# tensor([[0., 0., 0.], +# [0., 0., 0.]]) +``` + +``` python +# PaddlePaddle 示例: +import paddle +x = paddle.zeros([2, 3], dtype="float32") +param = paddle.create_parameter(shape=x.shape, + dtype=str(x.numpy().dtype), + default_initializer=paddle.nn.initializer.Assign(x)) +param.stop_gradient = True + +# 输出 +# Parameter containing: +# Tensor(shape=[2, 3], dtype=float32, place=CPUPlace, stop_gradient=True, +# [[0., 0., 0.], +# [0., 0., 0.]]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_norm_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_norm_.md new file mode 100644 index 00000000000..3111dd555a2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_norm_.md @@ -0,0 +1,29 @@ +## [ 参数完全一致 ]torch.nn.utils.clip_grad_norm_ +### [torch.nn.utils.clip_grad_norm_](https://pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_norm_.html?highlight=clip_grad_norm_#torch.nn.utils.clip_grad_norm_) + +```python +torch.nn.utils.clip_grad_norm_(parameters, + max_norm, + norm_type=2.0, + error_if_nonfinite=False) +``` + +### [paddle.nn.utils.clip_grad_norm_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/clip_grad_norm__cn.html) + +```python +paddle.nn.utils.clip_grad_norm_(parameters, + max_norm, + norm_type=2.0, + error_if_nonfinite=False) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------- | +| parameters | parameters | 需要参与梯度裁剪的一个 Tensor 或者多个 Tensor。 | +| max_norm | max_norm | 梯度的最大范数。 | +| norm_type | norm_type | 所用 p-范数类型。可以是无穷范数的`inf`。 | +| error_if_nonfinite | error_if_nonfinite | 如果为 True,且如果来自:attr:parameters`的梯度的总范数为`nan、inf`或-inf`,则抛出错误。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_value_.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_value_.md new file mode 100644 index 00000000000..de257008c31 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.clip_grad_value_.md @@ -0,0 +1,23 @@ +## [ 参数完全一致 ]torch.nn.utils.clip_grad_value_ +### [torch.nn.utils.clip_grad_value_](https://pytorch.org/docs/stable/generated/torch.nn.utils.clip_grad_value_.html?highlight=clip_grad_value_#torch.nn.utils.clip_grad_value_) + +```python +torch.nn.utils.clip_grad_value_(parameters, + clip_value) +``` + +### [paddle.nn.utils.clip_grad_value_](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/clip_grad_value__cn.html) + +```python +paddle.nn.utils.clip_grad_value_(parameters, + clip_value) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------- | +| parameters | parameters | 需要参与梯度裁剪的一个 Tensor 或者多个 Tensor。 | +| clip_value | clip_value | 裁剪的指定值(非负数)。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.parametrizations.spectral_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.parametrizations.spectral_norm.md new file mode 100644 index 00000000000..b28b5dd9155 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.parametrizations.spectral_norm.md @@ -0,0 +1,25 @@ +## [ 仅参数名不一致 ]torch.nn.utils.parametrizations.spectral_norm + +### [torch.nn.utils.parametrizations.spectral_norm](https://pytorch.org/docs/stable/generated/torch.nn.utils.parametrizations.spectral_norm.html#torch.nn.utils.parametrizations.spectral_norm) + +```python +torch.nn.utils.parametrizations.spectral_norm(module, name='weight', n_power_iterations=1, eps=1e-12, dim=None) +``` + +### [paddle.nn.utils.spectral_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/spectral_norm_cn.html#spectral-norm) + +```python +paddle.nn.utils.spectral_norm(layer, name='weight', n_power_iterations=1, eps=1e-12, dim=None) +``` + +PyTorch 和 Paddle 功能一致,仅参数名不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------------ | ------------------ | ---------------------------------------- | +| module | layer | 要添加权重谱归一化的层,仅参数名不一致。 | +| name | name | 权重参数的名字。 | +| n_power_iterations | n_power_iterations | 将用于计算的 SpectralNorm 幂迭代次数。 | +| eps | eps | 用于保证计算中的数值稳定性。 | +| dim | dim | 重塑为矩阵之前应排列到第一个的维度索引。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.remove_weight_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.remove_weight_norm.md new file mode 100644 index 00000000000..f072155dfce --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.remove_weight_norm.md @@ -0,0 +1,20 @@ +## [ 仅参数名不一致 ]torch.nn.utils.remove_weight_norm +### [torch.nn.utils.remove_weight_norm](https://pytorch.org/docs/stable/generated/torch.nn.utils.remove_weight_norm.html?highlight=nn+utils+remove_weight_norm#torch.nn.utils.remove_weight_norm) + +```python +torch.nn.utils.remove_weight_norm(module, + name='weight') +``` + +### [paddle.nn.utils.remove_weight_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/remove_weight_norm_cn.html#remove-weight-norm) + +```python +paddle.nn.utils.remove_weight_norm(layer, + name='weight') +``` +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| module | layer | 要添加权重归一化的层,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.spectral_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.spectral_norm.md new file mode 100644 index 00000000000..8fe5d7bc42a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.spectral_norm.md @@ -0,0 +1,26 @@ +## [ 仅参数名不一致 ]torch.nn.utils.spectral_norm +### [torch.nn.utils.spectral_norm](https://pytorch.org/docs/stable/generated/torch.nn.utils.spectral_norm.html?highlight=nn+utils+spectral_norm#torch.nn.utils.spectral_norm) + +```python +torch.nn.utils.spectral_norm(module, + name='weight', + n_power_iterations=1, + eps=1e-12, + dim=None) +``` + +### [paddle.nn.utils.spectral_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/spectral_norm_cn.html#spectral-norm) + +```python +paddle.nn.utils.spectral_norm(layer, + name='weight', + n_power_iterations=1, + eps=1e-12, + dim=None) +``` +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| module | layer | 要添加权重谱归一化的层,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.weight_norm.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.weight_norm.md new file mode 100644 index 00000000000..16bf324a62c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.nn.utils.weight_norm.md @@ -0,0 +1,22 @@ +## [ 仅参数名不一致 ]torch.nn.utils.weight_norm +### [torch.nn.utils.weight_norm](https://pytorch.org/docs/stable/generated/torch.nn.utils.weight_norm.html?highlight=nn+utils+weight_norm#torch.nn.utils.weight_norm) + +```python +torch.nn.utils.weight_norm(module, + name='weight', + dim=0) +``` + +### [paddle.nn.utils.weight_norm](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/nn/utils/weight_norm_cn.html#weight-norm) + +```python +paddle.nn.utils.weight_norm(layer, + name='weight', + dim=0) +``` +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| module | layer | 要添加权重归一化的层,参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.md new file mode 100644 index 00000000000..f73da7b8aab --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.md @@ -0,0 +1,20 @@ +## [ 参数完全一致 ]torch.utils.cpp_extension.BuildExtension +### [torch.utils.cpp_extension.BuildExtension](https://pytorch.org/docs/stable/cpp_extension.html?highlight=cpp_extension#torch.utils.cpp_extension.BuildExtension) + +```python +torch.utils.cpp_extension.BuildExtension(*args, **kwargs) +``` + +### [paddle.utils.cpp_extension.BuildExtension]() + +```python +paddle.utils.cpp_extension.BuildExtension(*args, **kwargs) +``` + +参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +|*args | *args | 用于指定 BuildExtension 的其他参数,支持的参数与 setuptools.command.build_ext 一致。 | +| **kwargs | **kwargs | 用于指定 BuildExtension 的其他参数,支持的参数与 setuptools.command.build_ext 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.with_options.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.with_options.md new file mode 100644 index 00000000000..326d360a0af --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.BuildExtension.with_options.md @@ -0,0 +1,18 @@ +## [ 参数完全一致 ]torch.utils.cpp_extension.BuildExtension.with_options +### [torch.utils.cpp_extension.BuildExtension.with_options]() +```python +torch.utils.cpp_extension.BuildExtension.with_options(**options) +``` + +### [paddle.utils.cpp_extension.BuildExtension.with_options]() + +```python +paddle.utils.cpp_extension.BuildExtension.with_options(**options) +``` + +参数完全一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| **options | **options | 用户自定义的选项 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDAExtension.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDAExtension.md new file mode 100644 index 00000000000..3019617f8ef --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDAExtension.md @@ -0,0 +1,27 @@ +## [ torch 参数更多 ]torch.utils.cpp_extension.CUDAExtension +### [torch.utils.cpp_extension.CUDAExtension](https://pytorch.org/docs/stable/cpp_extension.html?highlight=torch+utils+cpp_extension+cudaextension#torch.utils.cpp_extension.CUDAExtension) + +```python +torch.utils.cpp_extension.CUDAExtension(name, + sources, + *args, + **kwargs) +``` + +### [paddle.utils.cpp_extension.CUDAExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CUDAExtension_cn.html) + +```python +paddle.utils.cpp_extension.CUDAExtension(sources, + *args, + **kwargs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| name | - | 参数 name,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| sources | sources | 用于指定自定义 OP 对应的源码文件。 | +|*args | *args | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | +| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDA_HOME.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDA_HOME.md new file mode 100644 index 00000000000..53411dc9e2c --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CUDA_HOME.md @@ -0,0 +1,14 @@ +## [ 无参数 ]torch.utils.cpp_extension.CUDA_HOME +### [torch.utils.cpp_extension.CUDA_HOME]() + +```python +torch.utils.cpp_extension.CUDA_HOME +``` + +### [paddle.utils.cpp_extension.cpp_extension.CUDA_HOME]() + +```python +paddle.utils.cpp_extension.cpp_extension.CUDA_HOME +``` + +无参数,查找本地 cuda 的安装路径。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CppExtension.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CppExtension.md new file mode 100644 index 00000000000..17f204a7e97 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.CppExtension.md @@ -0,0 +1,27 @@ +## [ torch 参数更多 ]torch.utils.cpp_extension.CppExtension +### [torch.utils.cpp_extension.CppExtension](https://pytorch.org/docs/stable/cpp_extension.html?highlight=torch+utils+cpp_extension+cppextension#torch.utils.cpp_extension.CppExtension) + +```python +torch.utils.cpp_extension.CppExtension(name, + sources, + *args, + **kwargs) +``` + +### [paddle.utils.cpp_extension.CppExtension](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/CppExtension_cn.html) + +```python +paddle.utils.cpp_extension.CppExtension(sources, + *args, + **kwargs) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| name | - | 参数 name,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| sources | sources | 用于指定自定义 OP 对应的源码文件。 | +|*args | *args | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | +| **kwargs | **kwargs | 用于指定 Extension 的其他参数,支持的参数与 setuptools.Extension 一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.load.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.load.md new file mode 100644 index 00000000000..349505f2d97 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.cpp_extension.load.md @@ -0,0 +1,48 @@ +## [ torch 参数更多 ]torch.utils.cpp_extension.load +### [torch.utils.cpp_extension.load](https://pytorch.org/docs/stable/cpp_extension.html?highlight=torch+utils+cpp_extension+load#torch.utils.cpp_extension.load) + +```python +torch.utils.cpp_extension.load(name, + sources, + extra_cflags=None, + extra_cuda_cflags=None, + extra_ldflags=None, + extra_include_paths=None, + build_directory=None, + verbose=False, + with_cuda=None, + is_python_module=True, + is_standalone=False, + keep_intermediates=True) +``` + +### [paddle.utils.cpp_extension.load](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/cpp_extension/load_cn.html) + +```python +paddle.utils.cpp_extension.load(name, + sources, + extra_cxx_cflags=None, + extra_cuda_cflags=None, + extra_ldflags=None, + extra_include_paths=None, + build_directory=None, + verbose=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| name | name | 用于指定编译自定义 OP 时,生成的动态链接库的名字。 | +| sources | sources | 用于指定自定义 OP 对应的源码文件。 | +| extra_cflags | extra_cxx_cflags | 用于指定编译 cuda 源文件时额外的编译选项。 | +| extra_cuda_cflags | extra_cuda_cflags | 用于指定编译 cuda 源文件时额外的编译选项。 | +| extra_ldflags |extra_ldflags | 用于指定编译自定义 OP 时额外的链接选项。 | +| extra_include_paths | extra_include_paths | 用于指定编译 cpp 或 cuda 源文件时,额外的头文件搜索目录。 | +| build_directory | build_directory | 用于指定存放生成动态链接库的目录。 | +| verbose | verbose | 用于指定是否需要输出编译过程中的日志信息,默认为 False。 | +| with_cuda | - | 决定是否将 CUDA 头文件和库添加到 build。 Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| is_python_module | - | 默认为 True,将生成的共享库作为 Python 模块导入,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| is_standalone | - | 默认为 False,将构建的扩展作为一个普通的动态库加载到进程中,如果是 True,则构建一个独立的可执行文件,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| +| keep_intermediates | - | 默认为 True,保留中间文件,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。| diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.BatchSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.BatchSampler.md new file mode 100644 index 00000000000..5e83743bcc2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.BatchSampler.md @@ -0,0 +1,40 @@ +## [ 仅 paddle 参数更多 ]torch.utils.data.BatchSampler +### [torch.utils.data.BatchSampler](https://pytorch.org/docs/stable/data.html?highlight=batchsampler#torch.utils.data.BatchSampler) + +```python +torch.utils.data.BatchSampler(sampler, + batch_size, + drop_last) +``` + +### [paddle.io.BatchSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/BatchSampler_cn.html#batchsampler) + +```python +paddle.io.BatchSampler(dataset=None, + sampler=None, + shuffle=Fasle, + batch_size=1, + drop_last=False) +``` + +其中 Paddle 相比 PyTorch 支持更多其他参数,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| --------- | -------------| ---------- | +| sampler | sampler | 底层取样器,PyTorch 可为 Sampler 或 Iterable 数据类型,Paddle 可为 Sampler 数据类型。 | +| - | dataset | 此参数必须是 paddle.io.Dataset 或 paddle.io.IterableDataset 的一个子类实例或实现了 __len__ 的 Python 对象,用于生成样本下标,PyTorch 无此参数,Paddle 保持默认即可。 | +| - | shuffle | 是否需要在生成样本下标时打乱顺序,PyTorch 无此参数,Paddle 保持默认即可。 | + + +### 转写示例 +#### sampler(Iterable):底层取样器 +```python +# 若 sampler 为 Iterable 数据类型,则需要按如下方式转写 +# PyTorch 写法 +torch.utils.data.BatchSampler(sampler=[1., 2., 3., 4.], 3, False) + +# Paddle 写法 +sampler = paddle.io.Sampler([1., 2., 3., 4.]) +paddle.io.BatchSampler(sampler, 3, False) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ChainDataset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ChainDataset.md new file mode 100644 index 00000000000..ad8d382c43d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ChainDataset.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.utils.data.ChainDataset + +### [torch.utils.data.ChainDataset](https://pytorch.org/docs/stable/data.html#torch.utils.data.ChainDataset) + +```python +torch.utils.data.ChainDataset(datasets) +``` + +### [paddle.io.ChainDataset](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/ChainDataset_cn.html) + +```python +paddle.io.ChainDataset(datasets) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | ------------------------------------- | +| datasets | datasets | 待级联的多个数据集 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ConcatDataset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ConcatDataset.md new file mode 100644 index 00000000000..49f30b92891 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.ConcatDataset.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.utils.data.ConcatDataset + +### [torch.utils.data.ConcatDataset](https://pytorch.org/docs/stable/data.html#torch.utils.data.ConcatDataset) + +```python +torch.utils.data.ConcatDataset(datasets) +``` + +### [paddle.io.ConcatDataset](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/ConcatDataset_cn.html) + +```python +paddle.io.ConcatDataset(datasets) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| -------- | ------------ | ------------------ | +| datasets | datasets | 待拼接的数据集序列 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DataLoader.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DataLoader.md new file mode 100644 index 00000000000..d0a714ce0f3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DataLoader.md @@ -0,0 +1,100 @@ +## [ 参数不一致 ]torch.utils.data.DataLoader +### [torch.utils.data.DataLoader](https://pytorch.org/docs/stable/data.html?highlight=dataloader#torch.utils.data.DataLoader) +```python +torch.utils.data.DataLoader(dataset, + batch_size=1, + shuffle=False, + sampler=None, + batch_sampler=None, + num_workers=0, + collate_fn=None, + pin_memory=False, + drop_last=False, + timeout=0, + worker_init_fn=None, + multiprocessing_context=None, + generator=None, + *, + prefetch_factor=2, + persistent_workers=False, + pin_memory_device='') +``` + +### [paddle.io.DataLoader](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/DataLoader_cn.html#dataloader) +```python +paddle.io.DataLoader(dataset, + feed_list=None, + places=None, + return_list=False, + batch_sampler=None, + batch_size=1, + shuffle=False, + drop_last=False, + collate_fn=None, + num_workers=0, + use_buffer_reader=True, + use_shared_memory=False, + timeout=0, + worker_init_fn=None) +``` + + +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| sampler | - | 表示数据集采集器,Paddle 无此参数。 | +| pin_memory | - | 表示数据最开始是属于锁页内存,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| multiprocessing_context | - | ?,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| generator | - | 用于采样的伪随机数生成器,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| prefetch_factor | - | 表示每个 worker 预先加载的数据数量,Paddle 无此参数。 | +| persistent_workers | - | 表示数据集使用一次后,数据加载器将会不会关闭工作进程,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| pin_memory_device | - | 数据加载器是否在返回 Tensor 之前将 Tensor 复制到设备固定存储器中,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| - | feed_list | 表示 feed 变量列表,PyTorch 无此参数。 | +| - | places | 数据需要放置到的 Place 列表,PyTorch 无此参数。 | +| - | return_list | 每个设备上的数据是否以 list 形式返回,PyTorch 无此参数。 | +| - | use_buffer_reader | 表示是否使用缓存读取器,PyTorch 无此参数。 | +| - | use_shared_memory | 表示是否使用共享内存来提升子进程将数据放入进程间队列的速度,PyTorch 无此参数。 | + +### 功能差异 +#### 自定义数据采集器 +***PyTorch***:可通过设置`sampler`自定义数据采集器。 +***PaddlePaddle***:PaddlePaddle 无此功能,可使用如下代码自定义一个 DataLoader 实现该功能。 +```python +class DataLoader(paddle.io.DataLoader): + def __init__(self, + dataset, + batch_size=1, + shuffle=False, + sampler=None, + batch_sampler=None, + num_workers=0, + collate_fn=None, + pin_memory=False, + drop_last=False, + timeout=0, + worker_init_fn=None, + multiprocessing_context=None, + generator=None): + if isinstance(dataset[0], (tuple, list)): + return_list = True + else: + return_list = False + + super().__init__( + dataset, + feed_list=None, + places=None, + return_list=return_list, + batch_sampler=batch_sampler, + batch_size=batch_size, + shuffle=shuffle, + drop_last=drop_last, + collate_fn=collate_fn, + num_workers=num_workers, + use_buffer_reader=True, + use_shared_memory=False, + timeout=timeout, + worker_init_fn=worker_init_fn) + if sampler is not None: + self.batch_sampler.sampler = sampler +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Dataset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Dataset.md new file mode 100644 index 00000000000..6b0ae08c8b3 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Dataset.md @@ -0,0 +1,15 @@ +## [ 无参数 ]torch.utils.data.Dataset + +### [torch.utils.data.Dataset](https://pytorch.org/docs/stable/data.html?highlight=torch%20utils%20data%20dataset#torch.utils.data.Dataset) + +```python +torch.utils.data.Dataset() +``` + +### [paddle.io.Dataset](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/io/Dataset_cn.html#dataset) + +```python +paddle.io.Dataset() +``` + +功能一致,参数完全一致 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DistributedSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DistributedSampler.md new file mode 100644 index 00000000000..94753f863cc --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.DistributedSampler.md @@ -0,0 +1,34 @@ +## [ torch 参数更多 ]torch.utils.data.DistributedSampler +### [torch.utils.data.DistributedSampler](https://pytorch.org/docs/stable/data.html?highlight=distributedsampler#torch.utils.data.distributed.DistributedSampler) + +```python +torch.utils.data.DistributedSampler(dataset, + num_replicas=None, + rank=None, + shuffle=True, + seed=0, + drop_last=False) +``` + +### [paddle.io.DistributedBatchSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/DistributedBatchSampler_cn.html#distributedbatchsampler) + +```python +paddle.io.DistributedBatchSampler(dataset=None, + batch_size, + num_replicas=None, + rank=None, + shuffle=False, + drop_last=False) +``` + +PyTorch 参数更多,具体如下: +### 参数差异 +| PyTorch | PaddlePaddle | 备注 | +| ----- | ---------- | ---------- | +| dataset | dataset | 被采样的数据集。 | +| - | batch_size | 每 mini-batch 中包含的样本数,PyTorch 无此参数,Paddle 需设置为 1。 | +| num_replicas | num_replicas | 分布式训练时的进程个数。 | +| rank | rank | num_replicas 个进程中的进程序号。 | +| shuffle | shuffle | 是否需要在生成样本下标时打乱顺序。与 PyTorch 默认值不同, Paddle 应设置为 `True`。 | +| seed | - | 如果 shuffle=True,则使用随机种子对采样器进行随机排序,此数字在分布式组中的所有进程中应相同,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| drop_last | drop_last | 是否需要丢弃最后无法凑整一个 mini-batch 的样本。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.IterableDataset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.IterableDataset.md new file mode 100644 index 00000000000..c0f7894e9c2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.IterableDataset.md @@ -0,0 +1,15 @@ +## [无参数]torch.utils.data.IterableDataset + +### [torch.utils.data.IterableDataset](https://pytorch.org/docs/stable/data.html#torch.utils.data.IterableDataset) + +```python +torch.utils.data.IterableDataset() +``` + +### [paddle.io.IterableDataset](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/IterableDataset_cn.html#iterabledataset) + +```python +paddle.io.IterableDataset() +``` + +无参数,二者都为可迭代数据集的基类。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.RandomSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.RandomSampler.md new file mode 100644 index 00000000000..36902daceb2 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.RandomSampler.md @@ -0,0 +1,24 @@ +## [ 参数完全一致 ] torch.utils.data.RandomSampler + +### [torch.utils.data.RandomSampler](https://pytorch.org/docs/stable/data.html#torch.utils.data.RandomSampler) + +```python +torch.utils.data.RandomSampler(data_source, replacement=False, num_samples=None, generator=None) +``` + +### [paddle.io.RandomSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/RandomSampler_cn.html#paddle.io.RandomSampler) + +```python +paddle.io.RandomSampler(data_source, replacement=False, num_samples=None, generator=None) +``` + +两者参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------------------------------------- | +| data_source | data_source | Dataset 或 IterableDataset 的一个子类实例或实现了 `__len__` 的 Python 对象。 | +| replacement | replacement | 如果为 False 则会采样整个数据集。 | +| num_samples | num_samples | 按此参数采集对应的样本数。 | +| generator | generator | 指定采样 data_source 的采样器。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Sampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Sampler.md new file mode 100644 index 00000000000..bdb5019b13f --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Sampler.md @@ -0,0 +1,21 @@ +## [参数完全一致]torch.utils.data.Sampler + +### [torch.utils.data.Sampler](https://pytorch.org/docs/stable/data.html#torch.utils.data.Sampler) + +```python +torch.utils.data.Sampler(data_source) +``` + +### [paddle.io.Sampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/Sampler_cn.html) + +```python +paddle.io.Sampler(data_source) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------- | +| data_source | data_source | Dataset 或者 IterableDataset 的子类实现。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Subset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Subset.md new file mode 100644 index 00000000000..3290a99b5f0 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.Subset.md @@ -0,0 +1,22 @@ +## [参数完全一致]torch.utils.data.Subset + +### [torch.utils.data.Subset](https://pytorch.org/docs/stable/data.html#torch.utils.data.Subset) + +```python +torch.utils.data.Subset(dataset, indices) +``` + +### [paddle.io.Subset](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/Subset_cn.html) + +```python +paddle.io.Subset(dataset, indices) +``` + +paddle 参数和 torch 参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ---------- | ----------- | ------------------------------------- | +| dataset | dataset | 原数据集 | +| indices | indices | 用于提取子集的原数据集合指标数组 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.SubsetRandomSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.SubsetRandomSampler.md new file mode 100644 index 00000000000..cfb38f58e94 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.SubsetRandomSampler.md @@ -0,0 +1,22 @@ +## [ torch 参数更多 ] torch.utils.data.SubsetRandomSampler + +### [torch.utils.data.SubsetRandomSampler](https://pytorch.org/docs/stable/data.html#torch.utils.data.SubsetRandomSampler) + +```python +torch.utils.data.SubsetRandomSampler(indices, generator=None) +``` + +### [paddle.io.SubsetRandomSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/SubsetRandomSampler_cn.html#paddle.io.SubsetRandomSampler) + +```python +paddle.io.SubsetRandomSampler(indices) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------------------------------------- | +| indices | indices | 子集在原数据集中的索引序列,需要是 list 或者 tuple 类型。 | +| generator | - | Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.TensorDataset.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.TensorDataset.md new file mode 100644 index 00000000000..d7ef2b93e7a --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.TensorDataset.md @@ -0,0 +1,33 @@ +## [参数用法不一致]torch.utils.data.TensorDataset + +### [torch.utils.data.TensorDataset](https://pytorch.org/docs/stable/data.html#torch.utils.data.TensorDataset) + +```python +torch.utils.data.TensorDataset(*tensors) +``` + +### [paddle.io.TensorDataset](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/TensorDataset_cn.html) + +```python +paddle.io.TensorDataset(tensors) +``` + +paddle 参数和 torch 参数用法不一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +|----------|--------------|------------------------------------------------| +| *tensors | tensors | 输入的 Tensor, PyTorch 是可变参数用法, Paddle 是列表或元组,需要转写 | + +### 转写示例 + +#### tensors:输入的 Tensor + +```python +# PyTorch 写法 +torch.utils.data.TensorDataset(tensor1, tensor2, tensor3) + +# Paddle 写法 +paddle.io.TensorDataset([tensor1, tensor2, tensor3]) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md new file mode 100644 index 00000000000..b64daa8a6ef --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.WeightedRandomSampler.md @@ -0,0 +1,29 @@ +## [参数完全一致] torch.utils.data.WeightedRandomSampler + +### [torch.utils.data.WeightedRandomSampler](https://pytorch.org/docs/stable/data.html#torch.utils.data.WeightedRandomSampler) + +```python +torch.utils.data.WeightedRandomSampler(weights, + num_samples, + replacement=True, + generator=None) +``` + +### [paddle.io.WeightedRandomSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/WeightedRandomSampler_cn.html#paddle.io.WeightedRandomSampler) + +```python +paddle.io.WeightedRandomSampler(weights, + num_samples, + replacement=True) +``` + +两者参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ----------- | ------------ | -------------------------------------------------------------------- | +| weights | weights | 权重序列,需要时 numpy 数组, paddle.Tensor, list 或者 tuple 类型。 | +| num_samples | num_samples | 采样样本数。 | +| replacement | replacement | 是否采用有放回的采样。 | +| generator | - | Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data._utils.collate.default_collate.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data._utils.collate.default_collate.md new file mode 100644 index 00000000000..723afbf9ecd --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data._utils.collate.default_collate.md @@ -0,0 +1,43 @@ +## [ 参数不一致 ]torch.utils.data._utils.collate.default_collate +### [torch.utils.data._utils.collate.default_collate](https://pytorch.org/docs/stable/data.html?highlight=default_collate#torch.utils.data.default_collate) + +```python +torch.utils.data._utils.collate.default_collate(batch) +``` + +### [paddle.io.dataloader.collate.default_collate_fn]() + +```python +paddle.io.dataloader.collate.default_collate_fn(batch) +``` + +返回参数类型不一致,需要转写。具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| batch | batch | 输入的用于组 batch 的数据。 | +| 返回值 | 返回值 | 返回参数类型不一致,当 batch 的元素为 numpy.ndarray 或 number 时, PyTorch 默认返回 torch.tensor, Paddle 默认返回 numpy.ndarray。 | + + + +### 转写示例 +#### 当 batch 的元素为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data._utils.collate.default_collate(batch) + +# Paddle 写法 +y = paddle.to_tensor(paddle.io.dataloader.collate.default_collate_fn(batch)) +``` + +#### 当 batch 的元素为字典且字典的 value 为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data._utils.collate.default_collate(batch) + +# Paddle 写法 +y = paddle.io.dataloader.collate.default_collate_fn(batch) +for k, v in y.items(): + y[k] = paddle.to_tensor(v) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.dataloader.default_collate.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.dataloader.default_collate.md new file mode 100644 index 00000000000..aa3ec3ddc31 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.dataloader.default_collate.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ]torch.utils.data.dataloader.default_collate +### [torch.utils.data.dataloader.default_collate](https://pytorch.org/docs/stable/data.html?highlight=default_collate#torch.utils.data.default_collate) + +```python +torch.utils.data.dataloader.default_collate(batch) +``` + +### [paddle.io.dataloader.collate.default_collate_fn]() + +```python +paddle.io.dataloader.collate.default_collate_fn(batch) +``` + +返回参数类型不一致,需要转写。具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| batch | batch | 输入的用于组 batch 的数据。 | +| 返回值 | 返回值 | 返回参数类型不一致,当 batch 的元素为 numpy.ndarray 或 number 时, PyTorch 默认返回 torch.tensor, Paddle 默认返回 numpy.ndarray。 | + + +### 转写示例 +#### 当 batch 的元素为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data.dataloader.default_collate(batch) + +# Paddle 写法 +y = paddle.to_tensor(paddle.io.dataloader.collate.default_collate_fn(batch)) +``` + +#### 当 batch 的元素为字典且字典的 value 为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data.dataloader.default_collate(batch) + +# Paddle 写法 +y = paddle.io.dataloader.collate.default_collate_fn(batch) +for k, v in y.items(): + y[k] = paddle.to_tensor(v) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.default_collate.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.default_collate.md new file mode 100644 index 00000000000..59849d92b35 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.default_collate.md @@ -0,0 +1,42 @@ +## [ 参数不一致 ]torch.utils.data.default_collate +### [torch.utils.data.default_collate](https://pytorch.org/docs/stable/data.html?highlight=default_collate#torch.utils.data.default_collate) + +```python +torch.utils.data.default_collate(batch) +``` + +### [paddle.io.dataloader.collate.default_collate_fn]() + +```python +paddle.io.dataloader.collate.default_collate_fn(batch) +``` + +返回参数类型不一致,需要转写。具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| batch | batch | 输入的用于组 batch 的数据。 | +| 返回值 | 返回值 | 返回参数类型不一致,当 batch 的元素为 numpy.ndarray 或 number 时, PyTorch 默认返回 torch.tensor, Paddle 默认返回 numpy.ndarray。 | + + +### 转写示例 +#### 当 batch 的元素为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data.default_collate(batch) + +# Paddle 写法 +y = paddle.to_tensor(paddle.io.dataloader.collate.default_collate_fn(batch)) +``` + +#### 当 batch 的元素为字典且字典的 value 为 numpy.ndarray 或 number 时 +```python +# PyTorch 写法 +y = torch.utils.data.default_collate(batch) + +# Paddle 写法 +y = paddle.io.dataloader.collate.default_collate_fn(batch) +for k, v in y.items(): + y[k] = paddle.to_tensor(v) +``` diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.distributed.DistributedSampler.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.distributed.DistributedSampler.md new file mode 100644 index 00000000000..c61e9c4418d --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.distributed.DistributedSampler.md @@ -0,0 +1,37 @@ +## [ torch 参数更多 ]torch.utils.data.distributed.DistributedSampler + +### [torch.utils.data.distributed.DistributedSampler](https://pytorch.org/docs/stable/data.html?highlight=distributedsampler#torch.utils.data.distributed.DistributedSampler) + +```python +torch.utils.data.distributed.DistributedSampler(dataset, + num_replicas=None, + rank=None, + shuffle=True, + seed=0, + drop_last=False) +``` + +### [paddle.io.DistributedBatchSampler](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/DistributedBatchSampler_cn.html#distributedbatchsampler) + +```python +paddle.io.DistributedBatchSampler(dataset=None, + batch_size, + num_replicas=None, + rank=None, + shuffle=False, + drop_last=False) +``` + +PyTorch 相比 Paddle 支持更多其他参数,具体如下: + +### 参数差异 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ---------- | +| dataset | dataset | 所用的数据集。 | +| num_replicas | num_replicas | 进程数量。 | +| rank | rank | num_replicas 个进程中的进程序号。 | +| shuffle | shuffle | 是否打乱。PyTorch 默认值为 True,Paddle 默认值为 False。Paddle 需设置为与 PyTorch 一致。 | +| seed | - | 如果 shuffle=True,则使用随机种子对采样器进行随机排序,此数字在分布式组中的所有进程中应相同,Paddle 无此参数,一般对网络训练结果影响不大,可直接删除。 | +| drop_last | drop_last | 是否需要丢弃最后无法凑整一个 mini-batch 的样本。 | +| - | batch_size | 每 mini-batch 中包含的样本数,PyTorch 无此参数,Paddle 需设置为 1。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.get_worker_info.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.get_worker_info.md new file mode 100644 index 00000000000..14c581f12cf --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.get_worker_info.md @@ -0,0 +1,15 @@ +## [无参数]torch.utils.data.get_worker_info + +### [torch.utils.data.get_worker_info](https://pytorch.org/docs/stable/data.html#torch.utils.data.get_worker_info) + +```python +torch.utils.data.get_worker_info() +``` + +### [paddle.io.get_worker_info](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/get_worker_info_cn.html#get-worker-info) + +```python +paddle.io.get_worker_info() +``` + +两者功能一致,无参数。 diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md new file mode 100644 index 00000000000..9baa9243a7b --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.data.random_split.md @@ -0,0 +1,26 @@ +## [ 参数完全一致 ]torch.utils.data.random_split +### [torch.utils.data.random_split](https://pytorch.org/docs/stable/data.html?highlight=torch+utils+data+random_split#torch.utils.data.random_split) + +```python +torch.utils.data.random_split(dataset, + lengths, + generator=) +``` + +### [paddle.io.random_split](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/io/random_split_cn.html) + +```python +paddle.io.random_split(dataset, + lengths, + generator=None) +``` + +两者功能一致,参数完全一致,具体如下: + +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ |---------------------------------------------------------------------| +| dataset | dataset | 表示可迭代数据集。 | +| lengths | lengths | 可为子集合长度列表,列表总和为原数组长度。也可为子集合所占比例列表,列表总和为 1.0。 | +| generator | generator | 指定采样 data_source 的采样器。默认值为 None。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.from_dlpack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.from_dlpack.md new file mode 100644 index 00000000000..6058d9b2dd8 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.from_dlpack.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.utils.dlpack.from_dlpack +### [torch.utils.dlpack.from_dlpack](https://pytorch.org/docs/stable/dlpack.html?highlight=torch+utils+dlpack+from_dlpack#torch.utils.dlpack.from_dlpack) + +```python +torch.utils.dlpack.from_dlpack(ext_tensor) +``` + +### [paddle.utils.dlpack.from_dlpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/dlpack/from_dlpack_cn.html) + +```python +paddle.utils.dlpack.from_dlpack(dlpack) +``` + +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| ext_tensor | dlpack | DLPack,即带有 dltensor 的 PyCapsule 对象,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.to_dlpack.md b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.to_dlpack.md new file mode 100644 index 00000000000..70798832ea5 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/api_difference/utils/torch.utils.dlpack.to_dlpack.md @@ -0,0 +1,19 @@ +## [ 仅参数名不一致 ]torch.utils.dlpack.to_dlpack +### [torch.utils.dlpack.to_dlpack](https://pytorch.org/docs/stable/dlpack.html?highlight=torch+utils+dlpack+to_dlpack#torch.utils.dlpack.to_dlpack) + +```python +torch.utils.dlpack.to_dlpack(tensor) +``` + +### [paddle.utils.dlpack.to_dlpack](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/utils/dlpack/to_dlpack_cn.html) + +```python +paddle.utils.dlpack.to_dlpack(x) +``` + +两者功能一致,参数名不一致,具体如下: +### 参数映射 + +| PyTorch | PaddlePaddle | 备注 | +| ------------- | ------------ | ------------------------------------------------------ | +| tensor | x | Paddle Tensor,仅参数名不一致。 | diff --git a/docs/guides/model_convert/convert_from_pytorch/apply_reference_from_api_difference.py b/docs/guides/model_convert/convert_from_pytorch/apply_reference_from_api_difference.py new file mode 100644 index 00000000000..ea4c0676832 --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/apply_reference_from_api_difference.py @@ -0,0 +1,244 @@ +import os +import re +import sys + +script_path = os.path.abspath(__file__) +script_dir = os.path.dirname(__file__) +sys.path.append(script_dir) +print(script_dir) + +from validate_mapping_in_api_difference import ( + get_meta_from_diff_file, + process_mapping_index as reference_mapping_item, +) + + +def mapping_type_to_description(mapping_type): + mapping_type_1 = [ + "无参数", + "参数完全一致", + "仅参数名不一致", + "仅 paddle 参数更多", + "仅参数默认值不一致", + ] + + if mapping_type in mapping_type_1: + return "功能一致," + mapping_type, True + + mapping_type_2 = ["torch 参数更多"] + if mapping_type in mapping_type_2: + return "功能一致," + mapping_type, True + + mapping_type_3 = [ + "返回参数类型不一致", + "参数不一致", + "参数用法不一致", + ] + if mapping_type in mapping_type_3: + return "功能一致," + mapping_type, True + + mapping_type_4 = ["组合替代实现"] + if mapping_type in mapping_type_4: + return "组合替代实现", True + + mapping_type_5 = ["涉及上下文修改"] + if mapping_type in mapping_type_5: + return "功能一致," + mapping_type, True + + mapping_type_6 = ["对应 API 不在主框架"] + if mapping_type in mapping_type_6: + return "对应 API 不在主框架【占位】", False + + mapping_type_7 = ["功能缺失"] + if mapping_type in mapping_type_7: + return "功能缺失", False + + mapping_type_delete = ["可删除"] + if mapping_type in mapping_type_delete: + return "无对应 API,可以直接删除,对网络一般无影响", False + + raise ValueError( + f"Unexpected pyTorch-PaddlePaddle api mapping type {mapping_type}, please check " + ) + return "【未知类型】", False + + +REFERENCE_PATTERN = re.compile( + r"^\| *REFERENCE-MAPPING-ITEM\( *(?P[^,]+) *, *(?P.+) *\) *\|$" +) +NOT_IMPLEMENTED_PATTERN = re.compile( + r"^\| *NOT-IMPLEMENTED-ITEM\( *(?P[^,]+) *, *(?P.+) *\) *\|$" +) + + +DOCS_REPO_BASEURL = "https://github.com/PaddlePaddle/docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/" + + +def docs_url_to_relative_page(url): + if not url.startswith(DOCS_REPO_BASEURL): + return url + + md_path = url[len(DOCS_REPO_BASEURL) :] + if md_path.endswith(".md"): + return md_path[:-3] + ".html" + return md_path + + +def apply_reference_to_row(line, metadata_dict, table_row_idx, line_idx): + reference_match = REFERENCE_PATTERN.match(line) + not_implemented_match = NOT_IMPLEMENTED_PATTERN.match(line) + + if reference_match: + torch_api = reference_match["torch_api"].strip("`").replace(r"\_", "_") + diff_url = reference_match["diff_url"] + + diff_page_url = docs_url_to_relative_page(diff_url) + + row_idx_s = str(table_row_idx) + + if torch_api not in metadata_dict: + raise Exception( + f"Cannot find torch_api: {torch_api} in line {line_idx}" + ) + + reference_item = metadata_dict.get(torch_api, None) + torch_api_url = reference_item["torch_api_url"] + torch_api_column = f"[`{torch_api}`]({torch_api_url})" + + mapping_type = reference_item["mapping_type"] + mapping_type_column = mapping_type + + _mapping_type_desc, show_diff_url = mapping_type_to_description( + mapping_type + ) + mapping_url_column = "" + if show_diff_url: + mapping_url_column = f"[详细对比]({diff_page_url})" + + if "paddle_api" not in reference_item: + if mapping_type not in ["组合替代实现", "可删除", "功能缺失"]: + print( + f"Cannot find paddle_api for torch_api: {torch_api} in line {line_idx}" + ) + paddle_api_column = "" + else: + paddle_api = reference_item["paddle_api"] + paddle_api_url = reference_item["paddle_api_url"] + paddle_api_column = f"[`{paddle_api}`]({paddle_api_url})" + + content = [ + row_idx_s, + torch_api_column, + paddle_api_column, + mapping_type_column, + mapping_url_column, + ] + + output = "| " + " | ".join(content) + " |\n" + return output + elif not_implemented_match: + torch_api = ( + not_implemented_match["torch_api"].strip("`").replace(r"\_", "_") + ) + torch_api_url = not_implemented_match["torch_api_url"].strip() + + row_idx_s = str(table_row_idx) + + torch_api_column = f"[`{torch_api}`]({torch_api_url})" + + paddle_api_column = "" + mapping_column = "功能缺失" + mapping_url_column = "" + + content = [ + row_idx_s, + torch_api_column, + paddle_api_column, + mapping_column, + mapping_url_column, + ] + + output = "| " + " | ".join(content) + " |\n" + return output + else: + raise ValueError( + f"found manual-maintaining row at line [{line_idx}]: {line}" + ) + # return line + + +def reference_mapping_item_processer(line, line_idx, state, output, context): + if not line.startswith("|"): + output.append(line) + return True + + metadata_dict = context.get("metadata_dict", {}) + + if state == 0: + # check column names in common process + output.append(line) + return True + elif state == 1: + # check seperator of table to ignore in common process + output.append(line) + return True + elif state == 2: + # check seperator of table to process in common process + output.append(line) + return True + elif state == 5: + # check content of table to ignore in common process + output.append(line) + return True + elif state == 6: + # check content of table to process in common process + referenced_row = apply_reference_to_row( + line, metadata_dict, context["table_row_idx"], line_idx + 1 + ) + + output.append(referenced_row) + return True + + print(state) + return False + + +if __name__ == "__main__": + # convert from pytorch basedir + cfp_basedir = os.path.dirname(__file__) + # pytorch_api_mapping_cn + mapping_index_file = os.path.join(cfp_basedir, "pytorch_api_mapping_cn.md") + + api_difference_basedir = os.path.join(cfp_basedir, "api_difference") + + mapping_file_pattern = re.compile(r"^torch\.(?P.+)\.md$") + # get all diff files (torch.*.md) + diff_files = sorted( + [ + os.path.join(path, filename) + for path, _, file_list in os.walk(api_difference_basedir) + for filename in file_list + if mapping_file_pattern.match(filename) + ] + ) + + metas = sorted( + [get_meta_from_diff_file(f) for f in diff_files], + key=lambda x: x["torch_api"], + ) + + meta_dict = {m["torch_api"].replace(r"\_", "_"): m for m in metas} + + reference_context = { + "metadata_dict": meta_dict, + "ret_code": 0, + "output": [], + } + ret_code = reference_mapping_item( + mapping_index_file, reference_mapping_item_processer, reference_context + ) + + with open(mapping_index_file, "w", encoding="utf-8") as f: + f.writelines(reference_context["output"]) + + # 映射关系文件的保存流程移动至 `validate_mapping_in_api_difference.py` diff --git a/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py b/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py new file mode 100644 index 00000000000..2773b576eee --- /dev/null +++ b/docs/guides/model_convert/convert_from_pytorch/validate_mapping_in_api_difference.py @@ -0,0 +1,557 @@ +import json +import os +import re +import typing +from enum import IntEnum +from typing import TypedDict + +mapping_type_set = { + # type 1 + "无参数", + "参数完全一致", + "仅参数名不一致", + "仅 paddle 参数更多", + "仅参数默认值不一致", + # type 2 + "torch 参数更多", + # type 3 + "返回参数类型不一致", + "参数不一致", + "参数用法不一致", + # type 4 + "组合替代实现", + # type 5 + "涉及上下文修改", + # type 6 + "对应 API 不在主框架", + # type 7 + "功能缺失", + # delete + "可删除", +} + + +class DiffMeta(TypedDict): + torch_api: str + torch_api_url: typing.Optional[str] + torch_signature: typing.Optional[str] + paddle_api: typing.Optional[str] + paddle_api_url: typing.Optional[str] + paddle_signature: typing.Optional[str] + mapping_type: str + source_file: str + + +class ParserState(IntEnum): + wait_for_title = 0 + + wait_for_torch_api = 1 + wf_torch_code_begin = 2 + wf_torch_code = 3 + wf_torch_code_end = 4 + + wait_for_paddle_api = 5 + wf_paddle_code_begin = 6 + wf_paddle_code = 7 + wf_paddle_code_end = 8 + + end = 9 + + +def unescape_api(api): + return api.replace(r"\_", "_") + + +def reformat_signature(code): + lines = [l for l in code.split("\n") if len(l.strip()) > 0] + assert len(lines) > 0, "code have no lines." + buffer = "".join([l.strip() for l in lines]) + + first_par_pos = buffer.find("(") + + m = re.match(r"^\s*(?P[^\( ]+)(.*?)$", buffer) + assert m is not None, f'code first line "{buffer}" not match api pattern.' + api_name = m.group("api_name") + + if first_par_pos < 0: + # 要是没括号,可能是特殊情况,比如 property + return {"api_name": api_name} + + last_par_pos = buffer.rfind(")") + assert ( + last_par_pos > first_par_pos + ), f'code first line "{buffer}" not match api pattern.' + args_buffer = buffer[first_par_pos + 1 : last_par_pos] + + args = [] + args_buffer = args_buffer.strip() + arg_pattern = re.compile( + r"^(?P[^\=]+)(\=(?P[^,]+))?$" + ) + + arg_buffer_list = [ + l.strip() for l in args_buffer.split(",") if len(l.strip()) > 0 + ] + for arg_buffer in arg_buffer_list: + m = arg_pattern.match(arg_buffer) + assert m is not None, f'code arg "{arg_buffer}" not match arg pattern.' + arg_name = m.group("arg_name") + arg_default = m.group("arg_default") + args.append({"arg_name": arg_name, "arg_default": arg_default}) + + return {"api_name": api_name, "args": args} + + +def get_meta_from_diff_file(filepath): + meta_data: DiffMeta = {"source_file": filepath} + state = ParserState.wait_for_title + title_pattern = re.compile(r"^## +\[(?P[^\]]+)\] *(?P.+)$") + torch_pattern = re.compile( + r"^### +\[ *(?Ptorch.[^\]]+)\](?P\([^\)]*\))?$" + ) + paddle_pattern = re.compile( + r"^### +\[ *(?Ppaddle.[^\]]+)\](\((?P[^\)]*)\))?$" + ) + code_begin_pattern = re.compile(r"^```python$") + code_pattern = re.compile(r"^(?P(paddle|torch)[^\( ]+)(.*?)$") + code_end_pattern = re.compile(r"^```$") + + signature_cache = None + + with open(filepath, "r") as f: + for line in f.readlines(): + # 现在需要考虑内容信息了 + # if not line.startswith("##"): + # continue + + if state == ParserState.wait_for_title: + title_match = title_pattern.match(line) + if title_match: + mapping_type = title_match["type"].strip() + torch_api = unescape_api(title_match["torch_api"].strip()) + + meta_data["torch_api"] = unescape_api(torch_api) + meta_data["mapping_type"] = mapping_type + state = ParserState.wait_for_torch_api + else: + raise Exception(f"Cannot parse title: {line} in {filepath}") + elif state == ParserState.wait_for_torch_api: + torch_match = torch_pattern.match(line) + + if torch_match: + torch_api = torch_match["torch_api"].strip() + torch_url = torch_match["url"] if torch_match["url"] else "" + real_url = torch_url.lstrip("(").rstrip(")") + if meta_data["torch_api"] != unescape_api(torch_api): + raise Exception( + f"torch api not match: {line} != {meta_data['torch_api']} in {filepath}" + ) + meta_data["torch_api_url"] = real_url + state = ParserState.wf_torch_code_begin + elif state == ParserState.wait_for_paddle_api: + paddle_match = paddle_pattern.match(line) + + if paddle_match: + paddle_api = paddle_match["paddle_api"].strip() + paddle_url = paddle_match["url"].strip() + meta_data["paddle_api"] = unescape_api(paddle_api) + meta_data["paddle_api_url"] = paddle_url + state = ParserState.wf_paddle_code_begin + elif state in [ + ParserState.wf_torch_code_begin, + ParserState.wf_paddle_code_begin, + ]: + cb_match = code_begin_pattern.match(line) + + if cb_match: + if state == ParserState.wf_torch_code_begin: + state = ParserState.wf_torch_code + elif state == ParserState.wf_paddle_code_begin: + state = ParserState.wf_paddle_code + else: + raise ValueError( + f"Unexpected state {state} when process {filepath} line: {line}" + ) + elif state in [ + ParserState.wf_torch_code, + ParserState.wf_paddle_code, + ]: + code_match = code_pattern.match(line) + + if code_match: + api_name = code_match["api_name"].strip() + if state == ParserState.wf_torch_code: + if api_name != meta_data["torch_api"]: + raise ValueError( + f"Unexpected api code {api_name} != {meta_data['torch_api']} when process {filepath} line: {line}" + ) + else: + state = ParserState.wf_torch_code_end + signature_cache = line + elif state == ParserState.wf_paddle_code: + if api_name != meta_data["paddle_api"]: + raise ValueError( + f"Unexpected api code {api_name} != {meta_data['paddle_api']} when process {filepath} line: {line}" + ) + else: + state = ParserState.wf_paddle_code_end + signature_cache = line + else: + # 如果写注释,就先不管了 + if line[0] != "#": + raise ValueError( + f"Api code must appear after ```, but not found correct signature when process {filepath} line: {line}." + ) + elif state in [ + ParserState.wf_torch_code_end, + ParserState.wf_paddle_code_end, + ]: + ce_match = code_end_pattern.match(line) + + if ce_match: + try: + signature_info = reformat_signature(signature_cache) + signature_cache = None + except AssertionError as e: + raise Exception( + f"Cannot parse signature code in {filepath}" + ) from e + + if state == ParserState.wf_torch_code_end: + meta_data["torch_signature"] = signature_info + state = ParserState.wait_for_paddle_api + elif state == ParserState.wf_paddle_code_end: + meta_data["paddle_signature"] = signature_info + state = ParserState.end + else: + raise ValueError( + f"Unexpected state {state} when process {filepath} line: {line}" + ) + else: + # not match, append line to cache + if state == ParserState.wf_torch_code_end: + signature_cache += line + elif state == ParserState.wf_paddle_code_end: + signature_cache += line + else: + raise ValueError( + f"Unexpected state {state} when process {filepath} line: {line}" + ) + elif state == ParserState.end: + break + else: + raise ValueError( + f"Unexpected state {state} when process {filepath} line: {line}" + ) + + # print(state) + + # 允许的终止状态,解析完了 paddle_api 或者只有 torch_api + # 这些映射类型必须要有对应的 paddle_api + if mapping_type in [ + "无参数", + "参数完全一致", + "仅参数名不一致", + "仅 paddle 参数更多", + "仅参数默认值不一致", + # type 2 + "torch 参数更多", + # type 3 + "返回参数类型不一致", + "参数不一致", + "参数用法不一致", + ]: + if state != ParserState.end: + raise Exception( + f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" + ) + else: + if state not in [ParserState.end, ParserState.wait_for_paddle_api]: + raise Exception( + f"Unexpected End State at {state} in parsing file: {filepath}, current meta: {meta_data}" + ) + + return meta_data + + +# torch api must starts with "torch." +TABLE_COLUMN_TORCH_API_PATTERN = re.compile( + r"^\[ *(?Ptorch\.[^\]]+) *\](?P\([^\)]*\))$" +) + +# paddle api must starts with "paddle" +TABLE_COLUMN_PADDLE_API_PATTERN = re.compile( + r"^\[ *(?Ppaddle[^\]]+) *\](?P\([^\)]*\))$" +) + +TABLE_COLUMN_MAPPING_PATTERN = re.compile( + r"^(?P[^\[]*)(\[(?P[^\]]+)\]\((?P[^\)]+)\))?" +) + +MAPPING_DIFF_SOURCE_PATTERN = re.compile( + r"^https://github.com/PaddlePaddle/((docs/tree/develop/docs/guides/model_convert/convert_from_pytorch/api_difference/)|(X2Paddle/tree/develop/docs/pytorch_project_convertor/API_docs/))" +) + + +def validate_mapping_table_row(columns, row_idx, line_idx): + idx_s, torch_api_s, paddle_api_s, mapping_s = columns + + idx = int(idx_s) + if row_idx != idx: + raise Exception( + f"Table row index [{row_idx}] != {idx} at line {line_idx}." + ) + + torch_api_match = TABLE_COLUMN_TORCH_API_PATTERN.match(torch_api_s) + if torch_api_match: + torch_api = torch_api_match["torch_api"] + torch_api_url = torch_api_match["url"][1:-1] # remove '(' and ')' + else: + raise Exception( + f"Table row torch api not match: {torch_api_s} at line {line_idx}." + ) + + paddle_api_match = TABLE_COLUMN_PADDLE_API_PATTERN.match(paddle_api_s) + if len(paddle_api_s) > 0: + if paddle_api_match: + paddle_api = paddle_api_match["paddle_api"] + paddle_api_url = paddle_api_match["url"][1:-1] # remove '(' and ')' + else: + raise Exception( + f"Table row paddle api not match: {paddle_api_s} at line {line_idx}." + ) + else: + paddle_api = None + paddle_api_url = None + + mapping_type_match = TABLE_COLUMN_MAPPING_PATTERN.match(mapping_s) + if mapping_type_match: + mapping_type = mapping_type_match["type"].strip() + mapping_diff_name = mapping_type_match["diff_name"] + diff_url = mapping_type_match["diff_url"] + + if mapping_diff_name != "差异对比" and mapping_diff_name is not None: + print( + f"Table row mapping diff name not match: {mapping_diff_name} at line {line_idx}." + ) + + if diff_url is not None and not MAPPING_DIFF_SOURCE_PATTERN.match( + diff_url + ): + raise Exception( + f"Table row mapping diff url invalid: {diff_url} at line {line_idx}." + ) + mapping_diff_url = diff_url + else: + raise Exception( + f"Table row mapping type not match: {mapping_s} at line {line_idx}." + ) + + return { + "torch_api": torch_api, + "torch_api_url": torch_api_url, + "paddle_api": paddle_api, + "paddle_api_url": paddle_api_url, + "mapping_type": mapping_type, + "mapping_diff_name": mapping_diff_name, + "mapping_diff_url": mapping_diff_url, + "line_idx": line_idx, + } + + +def collect_mapping_item_processor(item, line_idx, state, output, context): + if state == 6: + table_row_idx = context["table_row_idx"] + columns = context["columns"] + item = validate_mapping_table_row(columns, table_row_idx, line_idx + 1) + output.append(item) + return True + + return False + + +def process_mapping_index(index_path, item_processer, context={}): + if not os.path.exists(index_path): + raise Exception(f"Cannot find pytorch_api_mapping_cn.md: {index_path}") + + with open(index_path, "r", encoding="utf-8") as f: + lines = f.readlines() + + state = 0 + # -1: error + # 0: wait for table header + + # 1: wait for ignore table seperator + # 2: wait for expect table content + + # 5: wait for ignore table content + # 6: wait for expect table content + + column_names = [] + column_count = -1 + table_seperator_pattern = re.compile(r"^ *\|(?P *-+ *\|)+ *$") + + expect_column_names = [ + "序号", + "Pytorch 最新 release", + "Paddle develop", + "映射关系分类", + "备注", + ] + + context["table_row_idx"] = context.get("table_row_idx", -1) + output = context.get("output", []) + + for i, line in enumerate(lines): + if state < 0: + break + + content = line.strip() + if not content.startswith("|"): + output.append(line) + state = 0 + continue + + columns = [c.strip() for c in content.split("|")] + if len(columns) <= 2: + raise Exception( + f"Table column count must > 0, but found {len(columns) - 2} at line {i+1}: {line}" + ) + columns = columns[1:-1] + + if state == 0: + column_names.clear() + column_names.extend([c.strip() for c in columns]) + column_count = len(column_names) + + if not item_processer(line, i, state, output, context): + break + + if column_names == expect_column_names: + state = 2 + context["table_row_idx"] = 1 + # print(f'process mapping table at line {i+1}.') + else: + state = 1 + print(f"ignore table with {column_names} at line {i+1}.") + + elif state == 1: + if ( + not table_seperator_pattern.match(line) + or len(columns) != column_count + ): + raise Exception( + f"Table seperator not match at line {i+1}: {line}" + ) + if not item_processer(line, i, state, output, context): + break + state = 5 + elif state == 2: + if ( + not table_seperator_pattern.match(line) + or len(columns) != column_count + ): + raise Exception( + f"Table seperator not match at line {i+1}: {line}" + ) + if not item_processer(line, i, state, output, context): + break + state = 6 + elif state == 5: + # if len(columns) != column_count: + # raise Exception( + # f"Table content not match at line {i+1}: {line}" + # ) + if not item_processer(line, i, state, output, context): + break + # state = 5 + elif state == 6: + # if len(columns) != column_count: + # raise Exception( + # f"Table content not match at line {i+1}: {line}" + # ) + try: + if not item_processer(line, i, state, output, context): + break + context["table_row_idx"] += 1 + except Exception as e: + print(e) + print(f"Error at line {i+1}: {line}") + ret_code = 1 + + # state = 6 + else: + ret_code = 2 + raise Exception( + f"Unexpected State at {state} in processing file: {index_path}" + ) + + if state == 5 or state == 6: + state = 0 + + if state != 0: + raise Exception( + f"Unexpected End State at {state} in parsing file: {index_path}" + ) + + ret_code = context.get("ret_code", 0xCC) + if ret_code != 0: + return ret_code + + context["output"] = output + + return 0 + + +if __name__ == "__main__": + # convert from pytorch basedir + cfp_basedir = os.path.dirname(__file__) + # pytorch_api_mapping_cn + mapping_index_file = os.path.join(cfp_basedir, "pytorch_api_mapping_cn.md") + + if not os.path.exists(mapping_index_file): + raise Exception(f"Cannot find mapping index file: {mapping_index_file}") + + index_data = process_mapping_index( + mapping_index_file, + collect_mapping_item_processor, + { + "ret_code": 0, + }, + ) + # index_data_dict = {i['torch_api'].replace('\_', '_'): i for i in index_data} + + api_difference_basedir = os.path.join(cfp_basedir, "api_difference") + + mapping_file_pattern = re.compile(r"^torch\.(?P.+)\.md$") + # get all diff files (torch.*.md) + diff_files = sorted( + [ + os.path.join(path, filename) + for path, _, file_list in os.walk(api_difference_basedir) + for filename in file_list + if mapping_file_pattern.match(filename) + ] + ) + print(f"{len(diff_files)} mapping documents found.") + + metas = sorted( + [get_meta_from_diff_file(f) for f in diff_files], + key=lambda x: x["torch_api"], + ) + print(f"extracted {len(metas)} mapping metas data.") + + for m in metas: + if m["mapping_type"] not in mapping_type_set: + print(m) + raise Exception( + f"Unknown mapping type: {m['mapping_type']} in {m['source_file']}" + ) + + meta_dict = {m["torch_api"].replace(r"\_", "_"): m for m in metas} + + # 该文件用于 PaConvert 的文档对齐工作 + api_diff_output_path = os.path.join(cfp_basedir, "docs_mappings.json") + + with open(api_diff_output_path, "w", encoding="utf-8") as f: + json.dump(metas, f, ensure_ascii=False, indent=4) diff --git a/docs/guides/model_convert/load_old_format_model_cn.rst b/docs/guides/model_convert/load_old_format_model_cn.rst new file mode 100644 index 00000000000..4320e04c4f6 --- /dev/null +++ b/docs/guides/model_convert/load_old_format_model_cn.rst @@ -0,0 +1,271 @@ +.. _cn_guides_load_old_format_model: + + +兼容载入旧格式模型 +==================== + +如果你是从飞桨框架 1.x 切换到 2.1,曾经使用飞桨框架 1.x 的 fluid 相关接口保存模型或者参数,飞桨框架 2.1 也对这种情况进行了兼容性支持,包括以下几种情况。 + +飞桨 1.x 模型准备及训练示例,该示例为后续所有示例的前序逻辑: + +.. code-block:: python + + import numpy as np + import paddle + import paddle.fluid as fluid + import paddle.nn as nn + import paddle.optimizer as opt + + BATCH_SIZE = 16 + BATCH_NUM = 4 + EPOCH_NUM = 4 + + IMAGE_SIZE = 784 + CLASS_NUM = 10 + + # enable static graph mode + paddle.enable_static() + + # define a random dataset + class RandomDataset(paddle.io.Dataset): + def __init__(self, num_samples): + self.num_samples = num_samples + + def __getitem__(self, idx): + image = np.random.random([IMAGE_SIZE]).astype('float32') + label = np.random.randint(0, CLASS_NUM - 1, (1, )).astype('int64') + return image, label + + def __len__(self): + return self.num_samples + + image = fluid.data(name='image', shape=[None, 784], dtype='float32') + label = fluid.data(name='label', shape=[None, 1], dtype='int64') + pred = fluid.layers.fc(input=image, size=10, act='softmax') + loss = fluid.layers.cross_entropy(input=pred, label=label) + avg_loss = fluid.layers.mean(loss) + + optimizer = fluid.optimizer.SGD(learning_rate=0.001) + optimizer.minimize(avg_loss) + + place = fluid.CPUPlace() + exe = fluid.Executor(place) + exe.run(fluid.default_startup_program()) + + # create data loader + dataset = RandomDataset(BATCH_NUM * BATCH_SIZE) + loader = paddle.io.DataLoader(dataset, + feed_list=[image, label], + places=place, + batch_size=BATCH_SIZE, + shuffle=True, + drop_last=True, + num_workers=2) + + # train model + for data in loader(): + exe.run( + fluid.default_main_program(), + feed=data, + fetch_list=[avg_loss]) + + +1 从 ``paddle.fluid.io.save_inference_model`` 保存结果中载入模型&参数 +---------------------------------------------------------------------------- + +1.1 同时载入模型和参数 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +使用 ``paddle.jit.load`` 配合 ``**configs`` 载入模型和参数。 + +如果你是按照 ``paddle.fluid.io.save_inference_model`` 的默认格式存储的,可以按照如下方式载入(接前述示例): + +.. code-block:: python + + # save default + model_path = "fc.example.model" + fluid.io.save_inference_model( + model_path, ["image"], [pred], exe) + + # enable dynamic mode + paddle.disable_static(place) + + # load + fc = paddle.jit.load(model_path) + + # inference + fc.eval() + x = paddle.randn([1, IMAGE_SIZE], 'float32') + pred = fc(x) + +如果你指定了存储的模型文件名,可以按照以下方式载入(接前述示例): + +.. code-block:: python + + # save with model_filename + model_path = "fc.example.model.with_model_filename" + fluid.io.save_inference_model( + model_path, ["image"], [pred], exe, model_filename="__simplenet__") + + # enable dynamic mode + paddle.disable_static(place) + + # load + fc = paddle.jit.load(model_path, model_filename="__simplenet__") + + # inference + fc.eval() + x = paddle.randn([1, IMAGE_SIZE], 'float32') + pred = fc(x) + +如果你指定了存储的参数文件名,可以按照以下方式载入(接前述示例): + +.. code-block:: python + + # save with params_filename + model_path = "fc.example.model.with_params_filename" + fluid.io.save_inference_model( + model_path, ["image"], [pred], exe, params_filename="__params__") + + # enable dynamic mode + paddle.disable_static(place) + + # load + fc = paddle.jit.load(model_path, params_filename="__params__") + + # inference + fc.eval() + x = paddle.randn([1, IMAGE_SIZE], 'float32') + pred = fc(x) + +1.2 仅载入参数 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +如果你仅需要从 ``paddle.fluid.io.save_inference_model`` 的存储结果中载入参数,以 state_dict 的形式配置到已有代码的模型中,可以使用 ``paddle.load`` 配合 ``**configs`` 载入。 + +如果你是按照 ``paddle.fluid.io.save_inference_model`` 的默认格式存储的,可以按照如下方式载入(接前述示例): + +.. code-block:: python + + model_path = "fc.example.model" + + load_param_dict = paddle.load(model_path) + +如果你指定了存储的模型文件名,可以按照以下方式载入(接前述示例): + +.. code-block:: python + + model_path = "fc.example.model.with_model_filename" + + load_param_dict = paddle.load(model_path, model_filename="__simplenet__") + +如果你指定了存储的参数文件名,可以按照以下方式载入(接前述示例): + +.. code-block:: python + + model_path = "fc.example.model.with_params_filename" + + load_param_dict = paddle.load(model_path, params_filename="__params__") + +.. note:: + 一般预测模型不会存储优化器 Optimizer 的参数,因此此处载入的仅包括模型本身的参数。 + +.. note:: + 由于 ``structured_name`` 是动态图下独有的变量命名方式,因此从静态图存储结果载入的 state_dict 在配置到动态图的 Layer 中时,需要配置 ``Layer.set_state_dict(use_structured_name=False)`` 。 + + +2 从 ``paddle.fluid.save`` 存储结果中载入参数 +---------------------------------------------------------------------------- + + ``paddle.fluid.save`` 的存储格式与 2.x 动态图接口 ``paddle.save`` 存储格式是类似的,同样存储了 dict 格式的参数,因此可以直接使用 ``paddle.load`` 载入 state_dict,但需要注意不能仅传入保存的路径,而要传入保存参数的文件名,示例如下(接前述示例): + +.. code-block:: python + + # save by fluid.save + model_path = "fc.example.model.save" + program = fluid.default_main_program() + fluid.save(program, model_path) + + # enable dynamic mode + paddle.disable_static(place) + + load_param_dict = paddle.load("fc.example.model.save.pdparams") + + +.. note:: + 由于 ``paddle.fluid.save`` 接口原先在静态图模式下的定位是存储训练时参数,或者说存储 Checkpoint,故尽管其同时存储了模型结构,目前也暂不支持从 ``paddle.fluid.save`` 的存储结果中同时载入模型和参数,后续如有需求再考虑支持。 + + +3 从 ``paddle.fluid.io.save_params/save_persistables`` 保存结果中载入参数 +---------------------------------------------------------------------------- + +这两个接口在飞桨 1.x 版本时,已经不再推荐作为存储模型参数的接口使用,故并未继承至飞桨 2.x,之后也不会再推荐使用这两个接口存储参数。 + +对于使用这两个接口存储参数兼容载入的支持,分为两种情况,下面以 ``paddle.fluid.io.save_params`` 接口为例介绍相关使用方法: + + +3.1 使用默认方式存储,各参数分散存储为单独的文件,文件名为参数名 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +这种存储方式仍然可以使用 ``paddle.load`` 接口兼容载入,使用示例如下(接前述示例): + +.. code-block:: python + + # save by fluid.io.save_params + model_path = "fc.example.model.save_params" + fluid.io.save_params(exe, model_path) + + # load + state_dict = paddle.load(model_path) + print(state_dict) + +3.2 指定了参数存储的文件,将所有参数存储至单个文件中 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +将所有参数存储至单个文件中会导致存储结果中丢失 Tensor 名和 Tensor 数据之间的映射关系,因此这部分丢失的信息需要用户传入进行补足。为了确保正确性,这里不仅要传入 Tensor 的 name 列表,同时要传入 Tensor 的 shape 和 dtype 等描述信息,通过检查和存储数据的匹配性确保严格的正确性,这导致载入数据的恢复过程变得比较复杂,仍然需要一些飞桨 1.x 的概念支持。后续如果此项需求较为普遍,飞桨将会考虑将该项功能兼容支持到 ``paddle.load`` 中,但由于信息丢失而导致的使用复杂性仍然是存在的,因此建议你避免仅使用这两个接口存储参数。 + +目前暂时推荐你使用 ``paddle.static.load_program_state`` 接口解决此处的载入问题,需要获取原 Program 中的参数列表传入该方法,使用示例如下(接前述示例): + +.. code-block:: python + + # save by fluid.io.save_params + model_path = "fc.example.model.save_params_with_filename" + fluid.io.save_params(exe, model_path, filename="__params__") + + # load + import os + params_file_path = os.path.join(model_path, "__params__") + var_list = fluid.default_main_program().all_parameters() + state_dict = paddle.io.load_program_state(params_file_path, var_list) + + +4 从 ``paddle.static.save`` 保存结果中载入参数 +---------------------------------------------------------------------------- +``paddle.static.save`` 接口生成三个文件: ``*.pdparams`` 、 ``*.pdopt`` 、 ``*.pdmodel`` ,分别保存了组网的参数、优化器的参数、静态图的 Program。推荐您使用 ``paddle.load`` 分别加载这三个文件,然后使用 ``set_state_dict`` 接口将参数设置到 ``Program`` 中 。如果您已经在代码中定义了 ``Program`` ,您可以不加载 ``*.pdmodel`` 文件;如果您不需要恢复优化器中的参数,您可以不加载 ``*.pdopt`` 文件。使用示例如下: + + +.. code-block:: python + + import os + import paddle + + paddle.enable_static() + x = paddle.static.data( + name="static_x", shape=[None, 224], dtype='float32') + z = paddle.static.nn.fc(x, 10) + z = paddle.static.nn.fc(z, 10, bias_attr=False) + + place = paddle.CPUPlace() + exe = paddle.static.Executor(place) + exe.run(paddle.static.default_startup_program()) + prog = paddle.static.default_main_program() + + path = os.path.join("test_static_save_load", "model") + paddle.static.save(prog, path) + + # load program + program=paddle.load(path + '.pdmodel') + + state_dict_param = paddle.load(path + '.pdparams') + program.set_state_dict(state_dict_param) + + state_dict_opt = paddle.load(path + '.pdopt') + program.set_state_dict(state_dict_opt) diff --git a/docs/guides/model_convert/migration_cn.rst b/docs/guides/model_convert/migration_cn.rst new file mode 100644 index 00000000000..18310749967 --- /dev/null +++ b/docs/guides/model_convert/migration_cn.rst @@ -0,0 +1,215 @@ +.. _cn_guides_migration: + +版本迁移工具 +==================== + +在飞桨框架 2.0 中,Paddle API 的位置、命名、参数、行为,进行了系统性的调整和规范, 将 API 体系从 1.X 版本的 ``paddle.fluid.*`` 迁移到了 ``paddle.*`` 下。``paddle.fluid`` 目录下暂时保留了 1.8 版本 API,主要是兼容性考虑,未来会被删除。 + +使用版本迁移工具自动迁移 Paddle 1.X 的代码到 Paddle 2.0 +------------------------------------ + +飞桨提供了版本迁移工具,该工具按 Paddle 2.0 对于 Paddle 1.X 的变化,能够自动实现以下功能: + +- 按照 :ref:`API 映射表 ` ,将转换工具能否转换这列为 True 的 API 由 Paddle 1.X 转为 Paddle 2.0,为 False 的 API 打印 WARNING,提示手动升级。 +- 因为 Paddle 2.0.0 默认开启动态图,所以删除用于开启动态图上下文的 ``with paddle.fluid.dygraph.guard(place)`` ,并修改该上下文的代码缩进; +- 删除组网 API 中的 ``act`` 参数,并自动添加相关的激活函数; + +目前,版本迁移工具能够处理的 API 数量为 X 个,如果你有代码迁移的需求,使用转换工具能够节省你部分时间,帮助你快速完成代码迁移。 + +.. warning:: + + 版本迁移工具并不能处理所有的情况,对于 API 的处理只能按照 :ref:`API 映射表 ` 中的关系完成 API 的变化。如代码中包含有转换工具能否转换这列为 False 的 API 或不在此表中的 API,在使用本工具后,仍然需要手工来进行检查并做相应的调整。 + +安装 +~~~~ + +版本迁移工具可以通过 pip 的方式安装,方式如下: + +.. code:: ipython3 + + $ pip install paddle_upgrade_tool + +基本用法 +~~~~~~~~ + +paddle_upgrade_tool 可以使用下面的方式,快速使用: + +.. code:: ipython3 + + $ paddle_upgrade_tool --inpath /path/to/model.py + +这将在命令行中,以\ ``diff``\ 的形式,展示 model.py 从 Paddle 1.x 转换为 Paddle 2.0 的变化。如果你确认上述变化没有问题,只需要再执行: + +.. code:: ipython3 + + $ paddle_upgrade_tool --inpath /path/to/model.py --write + +就会原地改写 model.py,将上述变化改写到你的源文件中。 +注意:版本转换工具会默认备份源文件,到~/.paddle_upgrade_tool/下。 + +参数说明如下: + +- –inpath 输入文件路径,可以为单个文件或文件夹。 +- –write 是否原地修改输入的文件,默认值 False,表示不修改。如果为 True,表示对文件进行原地修改。添加此参数也表示对文件进行原地修改。 +- –backup 可选,是否备份源文件,默认值为\ ``~/.paddle_upgrade_tool/``\ ,在此路径下备份源文件。 +- –no-log-file 可选,是否需要输出日志文件,默认值为 False,即输出日志文件。 +- –log-filepath 可选,输出日志的路径,默认值为\ ``report.log``\ ,输出日志文件的路径。 +- –no-confirm 可选,输入文件夹时,是否逐文件确认原地写入,只在\ ``--write``\ 为 True 时有效,默认值为 False,表示需要逐文件确认。 +- –parallel 可选,控制转换文件的并发数,当 \ ``no-confirm`` 为 True 时不生效,默认值:\ ``None``\ 。 +- –log-level 可选,log 级别,可为[‘DEBUG’,‘INFO’,‘WARNING’,‘ERROR’] 默认值:\ ``INFO``\ 。 +- –refactor 可选,debug 时使用。 +- –print-match 可选,debug 时使用。 + +使用教程 +~~~~~~~~ + +开始 +^^^^ + +在使用 paddle_upgrade_tool 前,需要确保已经安装了 Paddle 2.0.0+版本。 + +.. code:: ipython3 + + import paddle + print (paddle.__version__) + +.. parsed-literal:: + + 2.0.0 + + +克隆\ `paddlePaddle/models `__\ 来作为工具的测试。 + +.. code:: ipython3 + + $ git clone https://github.com/PaddlePaddle/models + +.. parsed-literal:: + + Cloning into 'models'... + remote: Enumerating objects: 8, done. + remote: Counting objects: 100% (8/8), done. + remote: Compressing objects: 100% (8/8), done. + remote: Total 35011 (delta 1), reused 0 (delta 0), pack-reused 35003 + Receiving objects: 100% (35011/35011), 356.97 MiB | 1.53 MiB/s, done. + Resolving deltas: 100% (23291/23291), done. + + +查看帮助文档 +^^^^^^^^^^^^ + +你可以直接通过下面的方式,查看帮助文档。 + +.. code:: ipython3 + + $ paddle_upgrade_tool -h + + +.. parsed-literal:: + + usage: paddle_upgrade_tool [-h] [--log-level {DEBUG,INFO,WARNING,ERROR}] + [--no-log-file] [--log-filepath LOG_FILEPATH] -i + INPATH [-b [BACKUP]] [-w] [--no-confirm] + [-p PARALLEL] + [-r {refactor_import,norm_api_alias,args_to_kwargs,refactor_kwargs,api_rename,refactor_with,post_refactor}] + [--print-match] + + optional arguments: + -h, --help show this help message and exit + --log-level {DEBUG,INFO,WARNING,ERROR} + set log level, default is INFO + --no-log-file don't log to file + --log-filepath LOG_FILEPATH + set log file path, default is "report.log" + -i INPATH, --inpath INPATH + the file or directory path you want to upgrade. + -b [BACKUP], --backup [BACKUP] + backup directory, default is the + "~/.paddle_upgrade_tool/". + -w, --write modify files in-place. + --no-confirm write files in-place without confirm, ignored without + --write. + -p PARALLEL, --parallel PARALLEL + specify the maximum number of concurrent processes to + use when refactoring, ignored with --no-confirm. + -r {refactor_import,norm_api_alias,args_to_kwargs,refactor_kwargs,api_rename,refactor_with,post_refactor}, --refactor {refactor_import,norm_api_alias,args_to_kwargs,refactor_kwargs,api_rename,refactor_with,post_refactor} + this is a debug option. Specify refactor you want to + run. If none, all refactors will be run. + --print-match this is a debug option. Print matched code and node + for each file. + +Paddle 1.x 的例子 +^^^^^^^^^^^^^^ + +这里是一个基于 Paddle 1.x 实现的一个 mnist 分类,部分内容如下: + +.. code:: ipython3 + + $ head -n 198 models/dygraph/mnist/train.py | tail -n 20 + + +.. code:: ipython3 + + with fluid.dygraph.guard(place): + if args.ce: + print("ce mode") + seed = 33 + np.random.seed(seed) + fluid.default_startup_program().random_seed = seed + fluid.default_main_program().random_seed = seed + + if args.use_data_parallel: + strategy = fluid.dygraph.parallel.prepare_context() + mnist = MNIST() + adam = AdamOptimizer(learning_rate=0.001, parameter_list=mnist.parameters()) + if args.use_data_parallel: + mnist = fluid.dygraph.parallel.DataParallel(mnist, strategy) + + train_reader = paddle.batch( + paddle.dataset.mnist.train(), batch_size=BATCH_SIZE, drop_last=True) + if args.use_data_parallel: + train_reader = fluid.contrib.reader.distributed_batch_reader( + train_reader) + + +使用 paddle_upgrade_tool 进行转化 +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +paddle_upgrade_tool 支持单文件的转化,你可以通过下方的命令直接转化单独的文件。 + +.. code:: ipython3 + + $ paddle_upgrade_tool --inpath models/dygraph/mnist/train.py + +注意,对于参数的删除及一些特殊情况,迁移工具都会打印 WARNING 信息,需要你仔细核对相关内容。 +如果你觉得上述信息没有问题,可以直接对文件进行原地修改,方式如下: + +.. code:: ipython3 + + $ paddle_upgrade_tool --inpath models/dygraph/mnist/train.py --write + +此时,命令行会弹出下方的提示: + +.. code:: ipython3 + + "models/dygraph/mnist/train.py" will be modified in-place, and it has been backed up to "~/.paddle_upgrade_tool/train.py_backup_2020_09_09_20_35_15_037821". Do you want to continue? [Y/n]: + +输入\ ``y`` +后即开始执行代码迁移。为了高效完成迁移,工具这里采用了原地写入的方式。此外,为了防止特殊情况,工具会备份转换前的代码到 +``~/.paddle_upgrade_tool`` 目录下,如果需要,你可以在备份目录下找到转换前的代码。 + +代码迁移完成后,会生成一个 report.log 文件,记录了迁移的详情。内容如下: + +.. code:: ipython3 + + $ cat report.log + +注意事项 +~~~~~~~~ + +- 本迁移工具不能完成所有 API 的迁移,有少量的 API 需要你手动完成迁移,具体信息可见 WARNING。 + +使用 Paddle 2.0 +~~~~~~~~~~~~~~~~ + +完成迁移后,代码就从 Paddle 1.x 迁移到了 Paddle 2.0,你就可以在 Paddle 2.0 下进行相关的开发。 diff --git a/docs/guides/model_convert/update_cn.md b/docs/guides/model_convert/update_cn.md new file mode 100644 index 00000000000..5e0717d75e0 --- /dev/null +++ b/docs/guides/model_convert/update_cn.md @@ -0,0 +1,560 @@ +# 升级指南 + +## 升级概要 +飞桨 2.0 版本,相对 1.8 版本有重大升级,涉及开发方面的重要变化如下: + + - 动态图功能完善,动态图模式下数据表示概念为`Tensor`,推荐使用动态图模式; + - API 目录体系调整,API 的命名和别名进行了统一规范化,虽然兼容老版 API,但请使用新 API 体系开发; + - 数据处理、组网方式、模型训练、多卡启动、模型保存和推理等开发流程都有了对应优化,请对应查看说明; + +以上变化请仔细阅读本指南。对于已有模型的升级,飞桨还提供了 2.0 转换工具(见附录)提供更自动化的辅助。 +其他一些功能增加方面诸如动态图对量化训练、混合精度的支持、动静转换等方面不在本指南列出,具体可查看[Release Note](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/release_note_cn.html)或对应文档。 + +## 一、动态图 + +### 推荐优先使用动态图模式 +飞桨 2.0 版本将会把动态图作为默认模式(如果还想使用静态图,可通过调用`paddle.enable_static`切换)。 + +```python +import paddle +``` + +### 使用 Tensor 概念表示数据 +静态图模式下,由于组网时使用的数据不能实时访问,Paddle 用`Variable`来表示数据。 +动态图下,从直观性等角度考虑,将数据表示概念统一为`Tensor`。动态图下`Tensor`的创建主要有两种方法: + +1. 通过调用`paddle.to_tensor`函数,将`python scalar/list`,或者`numpy.ndarray`数据转换为 Paddle 的`Tensor`。具体使用方法,请查看官网的 API 文档。 + +```python +import paddle +import numpy as np + +paddle.to_tensor(1) +paddle.to_tensor((1.1, 2.2)) +paddle.to_tensor(np.random.randn(3, 4)) +``` + +2. 通过调用 `paddle.zeros, paddle.ones, paddle.full, paddle.arange, paddle.rand, paddle.randn, paddle.randint, paddle.normal, paddle.uniform` 等函数,创建并返回 Tensor。 + +## 二、API +### API 目录结构 + +为了 API 组织更加简洁和清晰,将原来 padddle.fluid.xxx 的目录体系全新升级为 paddle.xxx,并对子目录的组织进行了系统的条理化优化。同时还增加了高层 API,可以高低搭配使用。paddle.fluid 目录下暂时保留了 1.8 版本 API,主要是兼容性考虑,未来会被删除。 +**基于 2.0 的开发任务,请使用 paddle 目录下的 API,不要再使用 paddle.fluid 目录下的 API。** 如果发现 Paddle 目录下有 API 缺失的情况,推荐使用基础 API 进行组合实现;你也可以通过在 [github](https://github.com/paddlepaddle/paddle) 上提 issue 的方式反馈。 + +**2.0 版本的 API 整体目录结构如下**: + +| 目录 | 功能和包含的 API | +| :--- | --------------- | +| paddle.* | paddle 根目录下保留了常用 API 的别名,当前包括:paddle.tensor、paddle.framework 和 paddle.device 目录下的所有 API | +| paddle.tensor | tensor 操作相关的 API,例如创建 zeros 、矩阵运算 matmul 、变换 concat 、计算 add 、查找 argmax 等。| +| paddle.framework | 框架通用 API 和动态图模式的 API,例如 no_grad 、 save 、 load 等。| +| paddle.device | 设备管理相关 API,比如:set_device, get_device 等 | +| paddle.amp | paddle 自动混合精度策略,包括 auto_cast 、 GradScaler 等。| +| paddle.callbacks | paddle 日志回调类,包括 ModelCheckpoint 、 ProgBarLogger 等。| +| paddle.nn | 组网相关的 API,例如 Linear 、卷积 Conv2D 、循环神经网络 LSTM 、损失函数 CrossEntropyLoss 、激活函数 ReLU 等。 | +| paddle.static | 静态图下基础框架相关 API,比如:Variable, Program, Executor 等 | +| paddle.static.nn | 静态图下组网专用 API,例如全连接层 fc 、控制流 while_loop/cond 。| +| paddle.optimizer | 优化算法相关 API,比如:SGD、Adagrad、Adam 等。| +| paddle.optimizer.lr | 学习率衰减相关 API,例如 NoamDecay 、 StepDecay 、 PiecewiseDecay 等。| +| paddle.metric | 评估指标计算相关的 API,比如:Accuracy, Auc 等。 | +| paddle.io | 数据输入输出相关 API,比如:Dataset, DataLoader 等 | +| paddle.distributed | 分布式相关基础 API | +| paddle.distributed.fleet | 分布式相关高层 API | +| paddle.vision | 视觉领域 API,例如数据集 Cifar10 、数据处理 ColorJitter 、常用基础网络结构 ResNet 等。| +| paddle.text | 目前包括 NLP 领域相关的数据集,如 Imdb 、 Movielens 。| + +### API 别名规则 + +- 为了方便使用,API 会在不同的路径下建立别名: + - 所有 device, framework, tensor 目录下的 API,均在 paddle 根目录建立别名;除少数特殊 API 外,其他 API 在 paddle 根目录下均没有别名。 + - paddle.nn 目录下除 functional 目录以外的所有 API,在 paddle.nn 目录下均有别名;functional 目录中的 API,在 paddle.nn 目录下均没有别名。 +- **推荐优先使用较短的路径的别名**,比如`paddle.add -> paddle.tensor.add`,推荐优先使用`paddle.add` +- 以下为一些特殊的别名关系,推荐使用左边的 API 名称: + - paddle.tanh -> paddle.tensor.tanh -> paddle.nn.functional.tanh + - paddle.remainder -> paddle.mod -> paddle.floor_mod + - paddle.rand -> paddle.uniform + - paddle.randn -> paddle.standard_normal + - Layer.set_state_dict -> Layer.set_dict + +### 常用 API 名称变化 + +- 加、减、乘、除使用全称,不使用简称 +- 对于当前逐元素操作,不加 elementwise 前缀 +- 对于按照某一轴操作,不加 reduce 前缀 +- Conv, Pool, Dropout, BatchNorm, Pad 组网类 API 根据输入数据类型增加 1D, 2D, 3D 后缀 + + | Paddle 1.8 API 名称 | Paddle 2.0 对应的名称| + | --------------- | ------------------------ | + | paddle.fluid.layers.elementwise_add | paddle.add | + | paddle.fluid.layers.elementwise_sub | paddle.subtract | + | paddle.fluid.layers.elementwise_mul | paddle.multiply | + | paddle.fluid.layers.elementwise_div | paddle.divide | + | paddle.fluid.layers.elementwise_max | paddle.maximum | + | paddle.fluid.layers.elementwise_min | paddle.minimum | + | paddle.fluid.layers.reduce_sum | paddle.sum | + | paddle.fluid.layers.reduce_prod | paddle.prod | + | paddle.fluid.layers.reduce_max | paddle.max | + | paddle.fluid.layers.reduce_min | paddle.min | + | paddle.fluid.layers.reduce_all | paddle.all | + | paddle.fluid.layers.reduce_any | paddle.any | + | paddle.fluid.dygraph.Conv2D | paddle.nn.Conv2D | + | paddle.fluid.dygraph.Conv2DTranspose | paddle.nn.Conv2DTranspose | + | paddle.fluid.dygraph.Pool2D | paddle.nn.MaxPool2D, paddle.nn.AvgPool2D | + +## 三、开发流程 +### 数据处理 +数据处理推荐使用**paddle.io 目录下的 Dataset,Sampler, BatchSampler, DataLoader 接口**,不推荐 reader 类接口。一些常用的数据集已经在 paddle.vision.datasets 和 paddle.text.datasets 目录实现,具体参考 API 文档。 + +```python +from paddle.io import Dataset + +class MyDataset(Dataset): + """ + 步骤一:继承 paddle.io.Dataset 类 + """ + def __init__(self, mode='train'): + """ + 步骤二:实现构造函数,定义数据读取方式,划分训练和测试数据集 + """ + super().__init__() + + if mode == 'train': + self.data = [ + ['traindata1', 'label1'], + ['traindata2', 'label2'], + ['traindata3', 'label3'], + ['traindata4', 'label4'], + ] + else: + self.data = [ + ['testdata1', 'label1'], + ['testdata2', 'label2'], + ['testdata3', 'label3'], + ['testdata4', 'label4'], + ] + + def __getitem__(self, index): + """ + 步骤三:实现__getitem__方法,定义指定 index 时如何获取数据,并返回单条数据(训练数据,对应的标签) + """ + data = self.data[index][0] + label = self.data[index][1] + + return data, label + + def __len__(self): + """ + 步骤四:实现__len__方法,返回数据集总数目 + """ + return len(self.data) + +# 测试定义的数据集 +train_dataset = MyDataset(mode='train') +val_dataset = MyDataset(mode='test') + +print('=============train dataset=============') +for data, label in train_dataset: + print(data, label) + +print('=============evaluation dataset=============') +for data, label in val_dataset: + print(data, label) +``` + +### 组网方式 +#### Sequential 组网 + +针对顺序的线性网络结构可以直接使用 Sequential 来快速完成组网,可以减少类的定义等代码编写。 + +```python +import paddle + +# Sequential 形式组网 +mnist = paddle.nn.Sequential( + paddle.nn.Flatten(), + paddle.nn.Linear(784, 512), + paddle.nn.ReLU(), + paddle.nn.Dropout(0.2), + paddle.nn.Linear(512, 10) +) +``` + +#### SubClass 组网 + + 针对一些比较复杂的网络结构,就可以使用 Layer 子类定义的方式来进行模型代码编写,在`__init__`构造函数中进行组网 Layer 的声明,在`forward`中使用声明的 Layer 变量进行前向计算。子类组网方式也可以实现 sublayer 的复用,针对相同的 layer 可以在构造函数中一次性定义,在`forward 中多次调用。 + +```python +import paddle + +# Layer 类继承方式组网 +class Mnist(paddle.nn.Layer): + def __init__(self): + super().__init__() + + self.flatten = paddle.nn.Flatten() + self.linear_1 = paddle.nn.Linear(784, 512) + self.linear_2 = paddle.nn.Linear(512, 10) + self.relu = paddle.nn.ReLU() + self.dropout = paddle.nn.Dropout(0.2) + + def forward(self, inputs): + y = self.flatten(inputs) + y = self.linear_1(y) + y = self.relu(y) + y = self.dropout(y) + y = self.linear_2(y) + + return y + +mnist = Mnist() +``` + +### 模型训练 + +#### 使用高层 API + +增加了`paddle.Model`高层 API,大部分任务可以使用此 API 用于简化训练、评估、预测类代码开发。注意区别 Model 和 Net 概念,Net 是指继承 paddle.nn.Layer 的网络结构;而 Model 是指持有一个 Net 对象,同时指定损失函数、优化算法、评估指标的可训练、评估、预测的实例。具体参考高层 API 的代码示例。 + +```python +import paddle +from paddle.vision.transforms import ToTensor + +train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=ToTensor()) +test_dataset = paddle.vision.datasets.MNIST(mode='test', transform=ToTensor()) +lenet = paddle.vision.models.LeNet() + +# Mnist 继承 paddle.nn.Layer 属于 Net,model 包含了训练功能 +model = paddle.Model(lenet) + +# 设置训练模型所需的 optimizer, loss, metric +model.prepare( + paddle.optimizer.Adam(learning_rate=0.001, parameters=model.parameters()), + paddle.nn.CrossEntropyLoss(), + paddle.metric.Accuracy() + ) + +# 启动训练 +model.fit(train_dataset, epochs=2, batch_size=64, log_freq=200) + +# 启动评估 +model.evaluate(test_dataset, log_freq=20, batch_size=64) +``` + +#### 使用基础 API + +```python +import paddle +from paddle.vision.transforms import ToTensor + +train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=ToTensor()) +test_dataset = paddle.vision.datasets.MNIST(mode='test', transform=ToTensor()) +lenet = paddle.vision.models.LeNet() +loss_fn = paddle.nn.CrossEntropyLoss() + +# 加载训练集 batch_size 设为 64 +train_loader = paddle.io.DataLoader(train_dataset, batch_size=64, shuffle=True) + +def train(): + epochs = 2 + adam = paddle.optimizer.Adam(learning_rate=0.001, parameters=lenet.parameters()) + # 用 Adam 作为优化函数 + for epoch in range(epochs): + for batch_id, data in enumerate(train_loader()): + x_data = data[0] + y_data = data[1] + predicts = lenet(x_data) + acc = paddle.metric.accuracy(predicts, y_data) + loss = loss_fn(predicts, y_data) + loss.backward() + if batch_id % 100 == 0: + print("epoch: {}, batch_id: {}, loss is: {}, acc is: {}".format(epoch, batch_id, loss.numpy(), acc.numpy())) + adam.step() + adam.clear_grad() + +# 启动训练 +train() +``` + +### 单机多卡启动 +2.0 增加`paddle.distributed.spawn`函数来启动单机多卡训练,同时原有的`paddle.distributed.launch`的方式依然保留。 + +#### 方式 1、launch 启动 + +##### 高层 API 场景 + +当调用`paddle.Model`高层来实现训练时,想要启动单机多卡训练非常简单,代码不需要做任何修改,只需要在启动时增加一下参数`-m paddle.distributed.launch`。 + +```bash +# 单机单卡启动,默认使用第 0 号卡 +$ python train.py + +# 单机多卡启动,默认使用当前可见的所有卡 +$ python -m paddle.distributed.launch train.py + +# 单机多卡启动,设置当前使用的第 0 号和第 1 号卡 +$ python -m paddle.distributed.launch --selected_gpus='0,1' train.py + +# 单机多卡启动,设置当前使用第 0 号和第 1 号卡 +$ export CUDA_VISIBLE_DEVICES=0,1 +$ python -m paddle.distributed.launch train.py +``` + +##### 基础 API 场景 + +如果使用基础 API 实现训练,想要启动单机多卡训练,需要对单机单卡的代码进行 3 处修改,具体如下: + +```python +import paddle +from paddle.vision.transforms import ToTensor + +# 第 1 处改动,导入分布式训练所需要的包 +import paddle.distributed as dist + +train_dataset = paddle.vision.datasets.MNIST(mode='train', transform=ToTensor()) +test_dataset = paddle.vision.datasets.MNIST(mode='test', transform=ToTensor()) +lenet = paddle.vision.models.LeNet() +loss_fn = paddle.nn.CrossEntropyLoss() + +# 加载训练集 batch_size 设为 64 +train_loader = paddle.io.DataLoader(train_dataset, batch_size=64, shuffle=True) + +def train(model): + # 第 2 处改动,初始化并行环境 + dist.init_parallel_env() + + # 第 3 处改动,增加 paddle.DataParallel 封装 + lenet = paddle.DataParallel(model) + epochs = 2 + adam = paddle.optimizer.Adam(learning_rate=0.001, parameters=lenet.parameters()) + # 用 Adam 作为优化函数 + for epoch in range(epochs): + for batch_id, data in enumerate(train_loader()): + x_data = data[0] + y_data = data[1] + predicts = lenet(x_data) + acc = paddle.metric.accuracy(predicts, y_data) + loss = loss_fn(predicts, y_data) + loss.backward() + if batch_id % 100 == 0: + print("epoch: {}, batch_id: {}, loss is: {}, acc is: {}".format(epoch, batch_id, loss.numpy(), acc.numpy())) + adam.step() + adam.clear_grad() + +# 启动训练 +train(lenet) +``` + +修改完后保存文件,然后使用跟高层 API 相同的启动方式即可 + +**注意:** 单卡训练不支持调用 ``init_parallel_env``,请使用以下几种方式进行分布式训练。 + +```bash + +# 单机多卡启动,默认使用当前可见的所有卡 +$ python -m paddle.distributed.launch train.py + +# 单机多卡启动,设置当前使用的第 0 号和第 1 号卡 +$ python -m paddle.distributed.launch --selected_gpus '0,1' train.py + +# 单机多卡启动,设置当前使用第 0 号和第 1 号卡 +$ export CUDA_VISIBLE_DEVICES=0,1 +$ python -m paddle.distributed.launch train.py +``` + +#### 方式 2、spawn 启动 + +launch 方式启动训练,以文件为单位启动多进程,需要在启动时调用 ``paddle.distributed.launch`` ,对于进程的管理要求较高。飞桨框架 2.0 版本增加了 ``spawn`` 启动方式,可以更好地控制进程,在日志打印、训练退出时更友好。使用示例如下: + +```python +import paddle +import paddle.nn as nn +import paddle.optimizer as opt +import paddle.distributed as dist + +class LinearNet(nn.Layer): + def __init__(self): + super().__init__() + self._linear1 = nn.Linear(10, 10) + self._linear2 = nn.Linear(10, 1) + + def forward(self, x): + return self._linear2(self._linear1(x)) + +def train(print_result=False): + + # 1. 初始化并行训练环境 + dist.init_parallel_env() + + # 2. 创建并行训练 Layer 和 Optimizer + layer = LinearNet() + dp_layer = paddle.DataParallel(layer) + + loss_fn = nn.MSELoss() + adam = opt.Adam( + learning_rate=0.001, parameters=dp_layer.parameters()) + + # 3. 运行网络 + inputs = paddle.randn([10, 10], 'float32') + outputs = dp_layer(inputs) + labels = paddle.randn([10, 1], 'float32') + loss = loss_fn(outputs, labels) + + if print_result is True: + print("loss:", loss.numpy()) + + loss.backward() + + adam.step() + adam.clear_grad() + +# 使用方式 1:仅传入训练函数 +# 适用场景:训练函数不需要任何参数,并且需要使用所有当前可见的 GPU 设备并行训练 +if __name__ == '__main__': + dist.spawn(train) + +# 使用方式 2:传入训练函数和参数 +# 适用场景:训练函数需要一些参数,并且需要使用所有当前可见的 GPU 设备并行训练 +if __name__ == '__main__': + dist.spawn(train, args=(True,)) + +# 使用方式 3:传入训练函数、参数并指定并行进程数 +# 适用场景:训练函数需要一些参数,并且仅需要使用部分可见的 GPU 设备并行训练,例如: +# 当前机器有 8 张 GPU 卡 {0,1,2,3,4,5,6,7},此时会使用前两张卡 {0,1}; +# 或者当前机器通过配置环境变量 CUDA_VISIBLE_DEVICES=4,5,6,7,仅使 4 张 +# GPU 卡可见,此时会使用可见的前两张卡 {4,5} +if __name__ == '__main__': + dist.spawn(train, args=(True,), nprocs=2) + +# 使用方式 4:传入训练函数、参数、指定进程数并指定当前使用的卡号 +# 使用场景:训练函数需要一些参数,并且仅需要使用部分可见的 GPU 设备并行训练,但是 +# 可能由于权限问题,无权配置当前机器的环境变量,例如:当前机器有 8 张 GPU 卡 +# {0,1,2,3,4,5,6,7},但你无权配置 CUDA_VISIBLE_DEVICES,此时可以通过 +# 指定参数 selected_gpus 选择希望使用的卡,例如 selected_gpus='4,5', +# 可以指定使用第 4 号卡和第 5 号卡 +if __name__ == '__main__': + dist.spawn(train, nprocs=2, selected_gpus='4,5') + +# 使用方式 5:指定多卡通信的起始端口 +# 使用场景:端口建立通信时提示需要重试或者通信建立失败 +# Paddle 默认会通过在当前机器上寻找空闲的端口用于多卡通信,但当机器使用环境 +# 较为复杂时,程序找到的端口可能不够稳定,此时可以自行指定稳定的空闲起始 +# 端口以获得更稳定的训练体验 +if __name__ == '__main__': + dist.spawn(train, nprocs=2, started_port=12345) +``` + +### 模型保存 +Paddle 保存的模型有两种格式,一种是训练格式,保存模型参数和优化器相关的状态,可用于恢复训练;一种是预测格式,保存预测的静态图网络结构以及参数,用于预测部署。 +#### 高层 API 场景 + +高层 API 下用于预测部署的模型保存方法为: + +```python +model = paddle.Model(Mnist()) +# 预测格式,保存的模型可用于预测部署 +model.save('mnist', training=False) +# 保存后可以得到预测部署所需要的模型 +``` + +#### 基础 API 场景 + +动态图训练的模型,可以通过动静转换功能,转换为可部署的静态图模型,具体做法如下: + +```python +import paddle +from paddle.jit import to_static +from paddle.static import InputSpec + +class SimpleNet(paddle.nn.Layer): + def __init__(self): + super().__init__() + self.linear = paddle.nn.Linear(10, 3) + + # 第 1 处改动 + # 通过 InputSpec 指定输入数据的形状,None 表示可变长 + # 通过 to_static 装饰器将动态图转换为静态图 Program + @to_static(input_spec=[InputSpec(shape=[None, 10], name='x'), InputSpec(shape=[3], name='y')]) + def forward(self, x, y): + out = self.linear(x) + out = out + y + return out + + +net = SimpleNet() + +# 第 2 处改动 +# 保存静态图模型,可用于预测部署 +paddle.jit.save(net, './simple_net') +``` +### 推理 +推理库 Paddle Inference 的 API 做了升级,简化了写法,以及去掉了历史上冗余的概念。API 的变化为纯增,原有 API 保持不变,但推荐新的 API 体系,旧 API 在后续版本会逐步删除。 + +#### C++ API + +重要变化: + +- 命名空间从 `paddle` 变更为 `paddle_infer` +- `PaddleTensor`, `PaddleBuf` 等被废弃,`ZeroCopyTensor` 变为默认 Tensor 类型,并更名为 `Tensor` +- 新增 `PredictorPool` 工具类简化多线程 predictor 的创建,后续也会增加更多周边工具 +- `CreatePredictor` (原 `CreatePaddlePredictor`) 的返回值由 `unique_ptr` 变为 `shared_ptr` 以避免 Clone 后析构顺序出错的问题 + +API 变更 + +| 原有命名 | 现有命名 | 行为变化 | +| ---------------------------- | ---------------------------- | ----------------------------- | +| 头文件 `paddle_infer.h` | 无变化 | 包含旧接口,保持向后兼容 | +| 无 | `paddle_inference_api.h` | 新 API,可以与旧接口并存 | +| `CreatePaddlePredictor` | `CreatePredictor` | 返回值变为 shared_ptr | +| `ZeroCopyTensor` | `Tensor` | 无 | +| `AnalysisConfig` | `Config` | 无 | +| `TensorRTConfig` | 废弃 | | +| `PaddleTensor` + `PaddleBuf` | 废弃 | | +| `Predictor::GetInputTensor` | `Predictor::GetInputHandle` | 无 | +| `Predictor::GetOutputTensor` | `Predictor::GetOutputHandle` | 无 | +| | `PredictorPool` | 简化创建多个 predictor 的支持 | + +使用新 C++ API 的流程与之前完全一致,只有命名变化 + +```c++ +#include "paddle_infernce_api.h" +using namespace paddle_infer; + +Config config; +config.SetModel("xxx_model_dir"); + +auto predictor = CreatePredictor(config); + +// Get the handles for the inputs and outputs of the model +auto input0 = predictor->GetInputHandle("X"); +auto output0 = predictor->GetOutputHandle("Out"); + +for (...) { + // Assign data to input0 + MyServiceSetData(input0); + + predictor->Run(); + + // get data from the output0 handle + MyServiceGetData(output0); +} +``` + +#### Python API + +Python API 的变更与 C++ 基本对应,会在 2.0 版发布。 + + +## 附录 +### 2.0 转换工具 +为了降级代码升级的成本,飞桨提供了转换工具,可以帮助将 Paddle 1.8 版本开发的代码,升级为 2.0 的 API。由于相比于 Paddle 1.8 版本,2.0 版本的 API 进行了大量的升级,包括 API 名称,参数名称,行为等。转换工具当前还不能覆盖所有的 API 升级;对于无法转换的 API,转换工具会报错,提示手动升级。 + +https://github.com/PaddlePaddle/paddle_upgrade_tool + +对于转换工具没有覆盖的 API,请查看官网的 API 文档,手动升级代码的 API。 + +### 2.0 文档教程 +以下提供了 2.0 版本的一些示例教程: + +你可以在官网[应用实践](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/practices/index_cn.html)栏目内进行在线浏览,也可以下载在这里提供的源代码: +https://github.com/PaddlePaddle/docs/tree/develop/docs/practices diff --git a/docs/install/FAQ.md b/docs/install/FAQ.md new file mode 100644 index 00000000000..1fab96862f8 --- /dev/null +++ b/docs/install/FAQ.md @@ -0,0 +1,90 @@ + +# **FAQ** + +- 报错“nccl.h 找不到” + + > 请[安装 nccl2](https://developer.nvidia.com/nccl/nccl-download) + + + +- Ubuntu18.04 下 libidn11 找不到? + + > 使用以下指令: + + apt install libidn11 + +- Ubuntu 编译时出现大量的代码段不能识别? + + > 这可能是由于 cmake 版本不匹配造成的,请在 gcc 的安装目录下使用以下指令: + + apt install gcc-4.8 g++-4.8 + cp gcc gcc.bak + cp g++ g++.bak + rm gcc + rm g++ + ln -s gcc-4.8 gcc + ln -s g++-4.8 g++ + +- 遇到 paddlepaddle.whl is not a supported wheel on this platform? + + > 出现这个问题的主要原因是,没有找到和当前系统匹配的 paddlepaddle 安装包。 请检查 Python 版本是否为 2.7 系列。另外最新的 pip 官方源中的安装包默认是 manylinux1 标准, 需要使用最新的 pip (>9.0.0) 才可以安装。您可以执行以下指令更新您的 pip: + + pip install --upgrade pip + 或者 + + python -c "import pip; print(pip.pep425tags.get_supported())" + + > 如果系统支持的是 linux_x86_64 而安装包是 manylinux1_x86_64 ,需要升级 pip 版本到最新; 如果系统支持 manylinux1_x86_64 而安装包 (本地)是 linux_x86_64, 可以重命名这个 whl 包为 manylinux1_x86_64 再安装。 + +- 使用 Docker 编译出现问题? + + > 请参照 GitHub 上[Issue12079](https://github.com/PaddlePaddle/Paddle/issues/12079) + +- 可以用 IDE 吗? + + > 当然可以,因为源码就在本机上。IDE 默认调用 make 之类的程序来编译源码,我们只需要配置 IDE 来调用 Docker 命令编译源码即可。 + 很多 PaddlePaddle 开发者使用 Emacs。他们在自己的 `~/.emacs` 配置文件里加两行 + `global-set-key "\C-cc" 'compile` + `setq compile-command "docker run --rm -it -v $(git rev-parse --show-toplevel):/paddle paddle:dev"` + 就可以按 `Ctrl-C` 和 `c` 键来启动编译了。 + +- 可以并行编译吗? + + > 是的。我们的 Docker image 运行一个 [Bash 脚本](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/paddle_build.sh)。这个脚本调用`make -j$(nproc)` 来启动和 CPU 核一样多的进程来并行编译。 + +- 在 Windows/macOS 上编译很慢? + + > Docker 在 Windows 和 macOS 都可以运行。不过实际上是运行在一个 Linux 虚拟机上。可能需要注意给这个虚拟机多分配一些 CPU 和内存,以保证编译高效。具体做法请参考[issue627](https://github.com/PaddlePaddle/Paddle/issues/627)。 + +- 磁盘不够? + + > 本文中的例子里,`docker run` 命令里都用了 `--rm` 参数,这样保证运行结束之后的 containers 不会保留在磁盘上。可以用 `docker ps -a` 命令看到停止后但是没有删除的 containers。`docker build` 命令有时候会产生一些中间结果,是没有名字的 images,也会占用磁盘。可以参考 [这篇文章](https://zaiste.net/posts/removing_docker_containers) 来清理这些内容。 + +- 在 DockerToolbox 下使用 book 时`http://localhost:8888/`无法打开? + + > 需要将 localhost 替换成虚拟机 ip,一般需要在浏览器中输入:`http://192.168.99.100:8888/` + +- pip install gpu 版本的 PaddlePaddle 后运行出现 SegmentFault 如下: + + @ 0x7f6c8d214436 paddle::platform::EnforceNotMet::EnforceNotMet() + + @ 0x7f6c8dfed666 paddle::platform::GetCUDADeviceCount() + + @ 0x7f6c8d2b93b6 paddle::framework::InitDevices() + + + > 出现这个问题原因主要是由于您的显卡驱动低于对应 CUDA 版本的要求,请保证您的显卡驱动支持所使用的 CUDA 版本 + + + +- macOS 下使用自定义的 openblas 详见 issue: + + > [ISSUE 13217](https://github.com/PaddlePaddle/Paddle/issues/13721) + +- 已经安装 swig 但是仍旧出现 swig 找不到的问题 详见 issue: + + > [ISSUE 13759](https://github.com/PaddlePaddle/Paddle/issues/13759) + +- 出现 “target pattern contain no '%'.”的问题 详见 issue: + + > [ISSUE 13806](https://github.com/PaddlePaddle/Paddle/issues/13806) diff --git a/docs/install/FAQ_en.md b/docs/install/FAQ_en.md new file mode 100644 index 00000000000..c4a5572f3b7 --- /dev/null +++ b/docs/install/FAQ_en.md @@ -0,0 +1,111 @@ +*** + + +# **FAQ** + +- Ubuntu18.04 under libidn11 can not be found? + + > Use the following instructions: + + apt install libidn11 + +- When Ubuntu compiles, a lot of code segments are not recognized? + + > This may be caused by a mismatch in the cmake version. Please use the following command in the gcc installation directory: + + apt install gcc-4.8 g++-4.8 + cp gcc gcc.bak + cp g++ g++.bak + rm gcc + rm g++ + ln -s gcc-4.8 gcc + ln -s g++-4.8 g++ + + + + +- Encountered paddlepaddle*.whl is not a supported wheel on this platform? + + > The main reason for this problem is that there is no paddlepaddle installation package that matches the current system. Please check if the Python version is 2.7 series. In addition, the latest pip official source installation package defaults to the manylinux1 standard, you need to use the latest pip (>9.0.0) to install. You can update your pip by following these instructions: + + pip install --upgrade pip + or + + python -c "import pip; print(pip.pep425tags.get_supported())" + + > If the system supports linux_x86_64 and the installation package is manylinux1_x86_64, you need to upgrade the pip version to the latest; if the system supports manylinux1_x86_64 and the installation package (local) is linux_x86_64, you can rename this whl package to manylinux1_x86_64 and install it again. + +- Is there a problem with Docker compilation? + + > Please refer to [Issue12079](https://github.com/PaddlePaddle/Paddle/issues/12079) on GitHub. + +- What is Docker? + + > If you haven't heard of Docker, you can think of it as a virtualenv-like system, but it virtualises more than the Python runtime environment. + +- Is Docker still a virtual machine? + + > Someone uses a virtual machine to analogize to Docker. It should be emphasized that Docker does not virtualize any hardware. The compiler tools running in the Docker container are actually run directly on the native CPU and operating system. The performance is the same as installing the compiler on the machine. + +- Why use Docker? + + > Installing the tools and configurations in a Docker image standardizes the build environment. This way, if you encounter problems, others can reproduce the problem to help. In addition, for developers accustomed to using Windows and macOS, there is no need to configure a cross-compilation environment using Docker. + +- Can I choose not to use Docker? + + > Of course you can. You can install development tools to the machine in the same way that you install them into Docker image. This document describes the Docker-based development process because it is easier than the other methods. + +- How hard is it to learn Docker? + + > It's not difficult to understand Docker. It takes about ten minutes to read this [article](https://zhuanlan.zhihu.com/p/19902938). + This can save you an hour of installing and configuring various development tools, as well as the need for new installations when switching machines. Don't forget that PaddlePaddle updates may lead to the need for new development tools. Not to mention the benefits of simplifying the recurrence of problems. + +- Can I use an IDE? + + > Of course, because the source code is on the machine. By default, the IDE calls a program like make to compile the source code. We only need to configure the IDE to call the Docker command to compile the source code. + Many PaddlePaddle developers use Emacs. They add two lines to their `~/.emacs` configuration file. + `global-set-key "\C-cc" 'compile` + `setq compile-command "docker run --rm -it -v $(git rev-parse --show- Toplevel): /paddle paddle:dev"` + You can start the compilation by pressing `Ctrl-C` and` c`. + +- Can I compile in parallel? + + > Yes. Our Docker image runs a [Bash script](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/scripts/paddle_build.sh). This script calls `make -j$(nproc)` to start as many processes as the CPU cores to compile in parallel. + +- Docker needs sudo? + + > If you develop with your own computer, you will naturally have admin privileges (sudo). If you are developing from a public computer, you need to ask the administrator to install and configure Docker. In addition, the PaddlePaddle project is working hard to support other container technologies that don't require sudo, such as rkt. + +- Is compiling slow on Windows/macOS? + + > Docker runs on both Windows and macOS. However, it is actually running on a Linux virtual machine. It may be necessary to pay attention to allocate more CPU and memory to this virtual machine to ensure efficient compilation. Please refer to [issue627](https://github.com/PaddlePaddle/Paddle/issues/627) for details. + +- Not enough disk? + + > In the example in this article, the `--rm` parameter is used in the `docker run`command to ensure that containers after the end of the run are not retained on disk. You can use the `docker ps -a` command to see containers that are stopped but not deleted. The `docker build` command sometimes produces some intermediate results, an image with no name, and it also occupies the disk. You can refer to this [article](https://zaiste.net/removing_docker_containers/) to clean up this content. + +- Can't I open `http://localhost:8888/` when using the book under DockerToolbox? + + > You need to replace localhost with virtual machine ip. Generally type this in the browser: `http://192.168.99.100:8888/` + +- After the pip install gpu version of PaddlePaddle runing, the SegmentFault appears as follows: + + @ 0x7f6c8d214436 paddle::platform::EnforceNotMet::EnforceNotMet() + + @ 0x7f6c8dfed666 paddle::platform::GetCUDADeviceCount() + + @ 0x7f6c8d2b93b6 paddle::framework::InitDevices() + + > The main reason for this problem is that your graphics card driver is lower than the corresponding CUDA version. Please ensure that your graphics card driver supports the CUDA version used. + +- Use customized openblas under macOS. See issue for details: + + >[ISSUE 13217](https://github.com/PaddlePaddle/Paddle/issues/13721) + +- Swig has been installed but there is still a problem that swig can't find. See issue for details: + + >[ISSUE 13759](https://github.com/PaddlePaddle/Paddle/issues/13759) + +- The question "target pattern contain no '%'." appears. See issue for details: + + >[ISSUE 13806](https://github.com/PaddlePaddle/Paddle/issues/13806) diff --git a/docs/install/install_script.md b/docs/install/install_script.md new file mode 100644 index 00000000000..72300a97a7e --- /dev/null +++ b/docs/install/install_script.md @@ -0,0 +1,52 @@ +# 辅助安装脚本 + +## 使用方法 + +下载脚本至本地后,使用命令`/bin/bash fast_install.sh`启动脚本 + +### Ubuntu 和 CentOS + +脚本会执行以下几步: + +1. GPU 检测 + + 检测您的机器是否含有我们支持的 GPU,如果有,会安装 GPU 版本的 PaddlePaddle,否则会安装 CPU 版本。 + (PaddlePaddle 目前支持 NVIDIA[官网](https://developer.nvidia.com/cuda-gpus#collapseOne)列出的,算力 7.0 以下的 GPU 和 v100 系列的 GPU) + +2. CUDA,cuDNN 检测 + + 检测您的机器是否安装我们支持的 CUDA,cuDNN,具体地: + + 1. 在`/usr/local/` 及其子目录下寻找 `cuda10.1/cuda10.2/cuda11.0/cuda11.2` 目录下的`version.txt`文件(通常如果您以默认方式安装了 CUDA)。 如果提示未找到 CUDA 请使用命令`find / -name version.txt`找到您所需要的 CUDA 目录下的“version.txt”路径,然后按照提示输入。 + 2. 在`/usr` 及其子目录下寻找文件 `cudnn.h` , 如果您的 cuDNN 未安装在默认路径请使用命令`find / -name cudnn.h`寻找您希望使用的 cuDNN 版本的`cudnn.h`路径并按提示输入 + + 如果未找到相应文件,则会安装 CPU 版本的 PaddlePaddle + +3. 选择数学库 +脚本默认会为您安装支持[MKL](https://software.intel.com/en-us/mkl)数学库的 PaddlePaddle,如果您的机器不支持`MKL`,请选择安装支持[OPENBLAS](https://www.openblas.net)的 PaddlePaddle + +4. 选择 PaddlePaddle 版本 +我们为您提供 2 种版本:开发版和稳定版,推荐您选择测试验证过的稳定版 + +5. 选择 Python 版本 +脚本默认会使用您机器中的 Python,您也可以输入您希望使用的 Python 的路径 + +6. 检查[AVX](https://zh.wikipedia.org/zh-hans/AVX 指令集)指令集 + +7. 使用[Python virtualenv](https://virtualenv.pypa.io/en/latest/) +脚本也支持按您的需求创建 Python 的虚拟环境 + +以上检查完成后就会为您安装对应您系统的 PaddlePaddle 了,安装一般需要 1~2 分钟会根据您的网络来决定,请您耐心等待。 + + +### macOS + +脚本会执行以下几步: + +1. 选择 PaddlePaddle 版本 +我们为您提供 2 种版本:开发版和稳定版,推荐您选择测试验证过的稳定版 + +2. 检查 Python 版本 +由于 macOS 自带的 Python 通常依赖于系统环境,因此我们不支持 macOS 自带的 Python 环境,请重新从 Python.org 安装 Python,然后根据提示输入您希望使用的 Python 的路径 + +3. 检查是否支持[AVX](https://zh.wikipedia.org/zh-hans/AVX 指令集)指令集