pytorch扩展

部署运行你感兴趣的模型镜像

python

__init__.py

导入包时实际导入的是__init__.py,可以通过__init__.py来控制可以使用的包和函数。
__all__关键字可以方便得用来指定要导入的包。

ctypes

cffi的wraper

cffi

pytorch

c文件

需要一个h文件

python文件

build so

ffi.create_extension和build

扩展autograd

需要init forward 和 backward
tensor和variable的函数基本一样
function的属性
Attributes:
saved_tensors: Tuple of Tensors that were saved in the call to
:func:forward.
saved_variables: Tuple of Variables that correspond to the tensors
saved in the call to :func:forward.
needs_input_grad: Tuple of booleans of length :attr:num_inputs,
indicating whether a given input requires gradient. This can be
used to optimize buffers saved for backward, and ignoring gradient
computation in :func:~Function.backward.
num_inputs: Number of inputs given to :func:forward.
num_outputs: Number of tensors returned by :func:forward.
requires_grad: Boolean indicating whether the :func:backward will
ever need to be called.

扩展nn

modules版本

可以保存参数
需要init(用于初始化参数) forward(调用autograd即可)

functional版本

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值