提交 a1564c80 编写于 作者: W wizardforcel

2019-02-22 12:00:30

上级 dfdc4f49
......@@ -128,7 +128,7 @@ hook不应该修改它的输入,但是它可以选择性的返回一个替代当
这个函数返回一个 句柄 (handle).它有一个方法 handle.remove(),可以用这个方法将 hook 从 module 移除.
Example
示例:
```py
>>> v = Variable(torch.Tensor([0, 0, 0]), requires_grad=True)
......@@ -218,7 +218,7 @@ class torch.autograd.profiler.profile(enabled=True)
参数:`enabled (bool, 可选)` – 如果设置为 False ,则没有评价指标. Default: `True`.
Example
示例:
```py
>>> x = Variable(torch.randn(1, 1), requires_grad=True)
......@@ -299,7 +299,7 @@ nvprof --profile-from-start off -o trace_name.prof -- <regular command here>
参数:`enabled (bool, 可选)` – 如果设置为 False ,则没有评价指标. 默认: `True`.
Example
示例:
```py
>>> with torch.cuda.profiler.profile():
......
......@@ -132,7 +132,7 @@ torch.cuda.get_rng_state(device=-1)
参数:`device (int, 可选)` – 设备的 RNG 状态. Default: -1 (i.e., 使用当前设备).
Warning
警告:
函数需要提前初始化 CUDA .
......@@ -154,7 +154,7 @@ torch.cuda.manual_seed(seed)
参数:`seed (int 或 long)` – 所需的种子.
Warning
警告:
如果您正在使用多 GPU 模型,则此功能不足以获得确定性. seef作用于所有 GPUs , 使用 `manual_seed_all()` .
......@@ -173,7 +173,7 @@ torch.cuda.seed()
将用于生成随机数的种子设置为当前 GPU 的随机数. 如果 CUDA 不可用,则调用此函数是安全的. 在那种情况下,会被忽略.
Warning
警告:
如果您正在使用多 GPU 模型, 则此功能不足以获得确定性. seef作用于所有 GPUs , 使用 `seed_all()`.
......@@ -189,7 +189,7 @@ torch.cuda.initial_seed()
返回当前 GPU 的当前随机种子.
Warning
警告:
函数提前初始化 CUDA .
......
......@@ -95,7 +95,7 @@ class torchvision.datasets.CocoCaptions(root, annFile, transform=None, target_tr
Example
示例:
```py
import torchvision.datasets as dset
......
......@@ -93,7 +93,7 @@ dist.init_process_group(init_method='tcp://[ff15:1e18:5d4c:4cf0:d02d:b659:53ba:b
另一个初始化方法使用一个文件系统, 这个文件系统在一个组中的所有机器上共享和可见, 以及一个所需的 `world_size` 参数. URL应该以 `file://` 开头, 并包含一个可以和共享文件系统所有现有目录中的路径相区别的路径, 作为URL. 这个初始化方法也 支持 `group_name` 参数, 它允许你为多个作业使用相同的共享文件路径, 只要它们使用不同的小组名.
Warning
警告:
这种方法假设文件系统支持使用 `fcntl` 进行锁定 -大多数本地系统和NFS都支持它.
......
......@@ -20,7 +20,7 @@ torch.utils.model_zoo.load_url(url, model_dir=None, map_location=None)
Example
示例:
```py
>>> state_dict = torch.utils.model_zoo.load_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth')
......
......@@ -10,7 +10,7 @@ torch.multiprocessing 是本地 [`multiprocessing`](https://docs.python.org/3/li
由于 API 的相似性, 我们没有记录大部分这个包的内容, 我们参考引用原始模块中非常优秀的文档.
Warning
警告:
如果主进程突然退出 (例如, 由于传入的信号) , Python 的多进程有时无法清理其子进程. 这是一个已知的警告, 所以如果你在中断解释器之后发现任何资源泄漏, 这可能意味着这只是发生在你身上.
......@@ -41,7 +41,7 @@ torch.multiprocessing.set_sharing_strategy(new_strategy)
在进程之间共享 CUDA 张量仅在 Python 3 中支持, 使用 `spawn``forkserver` 启动方法. Python 2 中的 [`multiprocessing`](https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing) 只能使用 `fork` 创建子进程, 而中 CUDA 运行时是不支持的.
Warning
警告:
CUDA API 要求输出到其他进程的分配保持有效, 只要它们被它们使用. 您应该注意, 并确保您共享的 CUDA 张量不会超出范围, 在有必要的情况下. 这不应该是共享模型参数的问题, 而是应该小心地传递其他类型的数据. 请注意, 此限制不适用于共享 CPU 内存.
......
......@@ -82,7 +82,7 @@ apply(fn)
返回类型:`Module`
Example
示例:
```py
>>> def init_weights(m):
......@@ -116,8 +116,7 @@ children()
返回一个最近子模块的 iterator(迭代器).
| Yields: | _Module_ – 一个子模块 |
| --- | --- |
Yields: `Module` – 一个子模块
```py
cpu()
......@@ -212,8 +211,7 @@ modules()
返回一个覆盖神经网络中所有模块的 iterator(迭代器).
| Yields: | _Module_ – a module in the network |
| --- | --- |
Yields: `Module` – 网络中的一个模块
注解:
......@@ -238,10 +236,9 @@ named_children()
返回一个 iterator(迭代器), 而不是最接近的子模块, 产生模块的 name 以及模块本身.
| Yields: | _(string, Module)_ – 包含名称和子模块的 Tuple(元组) |
| --- | --- |
Yields: `(string, Module)` – 包含名称和子模块的 Tuple(元组)
Example
示例:
```py
>>> for name, module in model.named_children():
......@@ -256,8 +253,7 @@ named_modules(memo=None, prefix='')
返回一个神经网络中所有模块的 iterator(迭代器), 产生模块的 name 以及模块本身.
| Yields: | _(string, Module)_ – 名字和模块的 Tuple(元组) |
| --- | --- |
Yields: `(string, Module)` – 名字和模块的 Tuple(元组)
注解:
......@@ -282,10 +278,9 @@ named_parameters(memo=None, prefix='')
返回模块参数的迭代器, 产生参数的名称以及参数本身
| Yields: | _(string, Parameter)_ – Tuple 包含名称很参数的 Tuple(元组) |
| --- | --- |
Yields: `(string, Parameter)` – Tuple 包含名称很参数的 Tuple(元组)
Example
示例:
```py
>>> for name, param in self.named_parameters():
......@@ -302,10 +297,9 @@ parameters()
这通常传递给优化器.
| Yields: | _Parameter_ – 模型参数 |
| --- | --- |
Yields: `Parameter` – 模型参数
Example
示例:
```py
>>> for param in model.parameters():
......@@ -351,7 +345,7 @@ Buffers 可以使用指定的 name 作为属性访问.
Example
示例:
```py
>>> self.register_buffer('running_mean', torch.zeros(num_features))
......@@ -432,7 +426,7 @@ state_dict(destination=None, prefix='', keep_vars=False)
返回类型:`dict`
Example
示例:
```py
>>> module.state_dict().keys()
......@@ -3220,7 +3214,7 @@ class torch.nn.Embedding(num_embeddings, embedding_dim, padding_idx=None, max_no
* 输入:LongTensor `(N, W)`, N = mini-batch, W = 每个 mini-batch 中用来提取的索引数
* 输出:`(N, W, embedding_dim)`
Notes
注解:
请注意, 只支持有限数量的优化器. 稀疏梯度: 当前是 (`cuda``cpu`) 版本的 `optim.SGD`, 和 (`cpu`) 版本的 `optim.Adagrad`.
......@@ -4220,23 +4214,23 @@ batch size 应该大于 GPUs 的数量.同时也应该是 GPU 数量的整数倍
创建这个类需要分布式包已经在 process group 模式下被初始化 (引用 [`torch.distributed.init_process_group()`](distributed.html#torch.distributed.init_process_group "torch.distributed.init_process_group")).
Warning
警告:
这个模块只能和``gloo``后端一起工作.
Warning
警告:
构造器, 转发方法和输出(或者这个模块的输出功能)的区分是分布式同步点.考虑到不同的 进程可能会执行不同的代码.
Warning
警告:
该模块假设所有参数在创建时都在模型中注册.之后不应该添加或删除参数.同样适用于缓冲区.
Warning
警告:
这个模块假定所有的缓冲区和梯度都是密集的.
Warning
警告:
这个模块不能用于 : func: `torch.autograd.grad` (即只有在参数的 `.grad` 属性中 累积梯度才能使用).
......@@ -4327,7 +4321,7 @@ torch.nn.utils.remove_weight_norm(module, name='weight')
Example
示例:
```py
>>> m = weight_norm(nn.Linear(20, 40))
......
......@@ -16,7 +16,7 @@
只有 Python 3 支持使用 `spawn``forkserver` 启动方法在进程中共享 CUDA 向量. [`multiprocessing`](https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing) 在 Python 2 使用 `fork` 只能创建子进程, 但是在 CUDA 运行时不被支持.
Warning
警告:
CUDA API 要求被导出到其他进程的分配只要被使用, 就要一直保持有效. 您应该小心, 确保您共享的CUDA张量只要有必要就不要超出范围. 这不是共享模型参数的问题, 但传递其他类型的数据应该小心. 注意, 此限制不适用于共享 CPU 内存.
......@@ -40,7 +40,7 @@ CUDA API 要求被导出到其他进程的分配只要被使用, 就要一直保
我们建议使用 [`multiprocessing.Queue`](https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Queue) 来在进程之间传输各种 PyTorch 对象. 例如, 当使用 `fork` 启动方法, 有可能会继承共享内存中的张量和存储量. 但这是非常容易出错的, 应谨慎使用, 最好是成为深度用户以后, 再使用这个方法. 队列虽然有时是一个较不优雅的解决方案, 但基本上能在所有情况下都正常工作.
Warning
警告:
当使用全局的声明时, 你应该注意, 因为它们没有被 `if __name__ == '__main__'` 限制. 如果使用与 `fork` 不同的启动方法, 它们将在所有子进程中被执行.
......
......@@ -262,11 +262,11 @@ class torch.optim.LBFGS(params, lr=1, max_iter=20, max_eval=None, tolerance_grad
实现 L-BFGS 算法.
Warning
警告:
这个 optimizer 不支持为每个参数单独设置选项以及不支持参数组(只能有一个).
Warning
警告:
目前所有的参数不得不都在同一设备上. 这在将来会得到改进.
......@@ -337,7 +337,7 @@ Nesterov 动量基于 [On the importance of initialization and momentum in deep
Args: * params (iterable): 待优化的迭代参数或者是定义了参数组的 dict * lr (float): 学习率 * momentum (float, 可选): 动量因子 (默认值: 0) * weight_decay (float, 可选): 权重衰减 (L2 正则化) (默认值: 0) * dampening (float, 可选): 动量的抑制因子 (默认值: 0) * nesterov (bool, 可选): 使用 Nesterov 动量 (默认值: False)
Example
示例:
```py
>>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
......@@ -385,7 +385,7 @@ class torch.optim.lr_scheduler.LambdaLR(optimizer, lr_lambda, last_epoch=-1)
Args: * optimizer (Optimizer): 封装好的优化器. * lr_lambda (function or list): 计算给定整数参数历元的乘法因子的函数, 或者一系列的此类函数, 每组的一个都在 optimizer.param_groups 中. * last_epoch (int): 最后一个 epoch 的索引. 默认值: -1.
Example
示例:
```py
>>> # Assuming optimizer has two groups.
......@@ -407,7 +407,7 @@ class torch.optim.lr_scheduler.StepLR(optimizer, step_size, gamma=0.1, last_epoc
Args: * optimizer (Optimizer): 封装好的优化器. * step_size (int): 学习率衰减周期. * gamma (float): 学习率衰减的乘法因子. 默认值: 0.1. * last_epoch (int): 最后一个 epoch 的索引. 默认值: -1.
Example
示例:
```py
>>> # Assuming optimizer uses lr = 0.5 for all groups
......@@ -435,7 +435,7 @@ Args: * optimizer (Optimizer): 封装好的优化器. * milestones (list): epoch
* `last_epoch (int)`: 最后一个 epoch 的索引. 默认值: -1.
Example
示例:
```py
>>> # Assuming optimizer uses lr = 0.5 for all groups
......@@ -476,7 +476,7 @@ Args: * optimizer (Optimizer): 封装好的优化器.
* `min_lr (float or list)`: 一个列表的标量.所有参数组或每个组的学习率下限. 默认值: 0.
* `eps (float)`: lr 最小的衰减值适应于. 如果新 lr 和旧 lr 之间的差异小于 eps,更新可以忽略. 默认值: 1e-8.
Example
示例:
```py
>>> optimizer = torch.optim.SGD(model.parameters(), lr=0.1, momentum=0.9)
......
......@@ -4,7 +4,7 @@
>
> 校对者:[@Timor](https://github.com/timors)
Warning
警告:
此 API 目前是实验性的 , 可能会在不久的将来发生变化 .
......
......@@ -480,7 +480,7 @@ element_size() → int
返回单个元素的字节大小.
Example
示例:
```py
>>> torch.FloatTensor().element_size()
......@@ -555,7 +555,7 @@ Tensor 也可以扩展到一个很大的维数, 新添加的维度将放在前
参数:`sizes (torch.Size 或 int...)` – 期望扩展的大小
Example
示例:
```py
>>> x = torch.Tensor([[1], [2], [3]])
......@@ -740,7 +740,7 @@ index_add_(dim, index, tensor) → Tensor
Example
示例:
```py
>>> x = torch.Tensor([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
......@@ -769,7 +769,7 @@ index_copy_(dim, index, tensor) → Tensor
Example
示例:
```py
>>> x = torch.Tensor(3, 3)
......@@ -798,7 +798,7 @@ index_fill_(dim, index, val) → Tensor
Example
示例:
```py
>>> x = torch.Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
......@@ -1067,7 +1067,7 @@ narrow(dimension, start, length) → Tensor
Example
示例:
```py
>>> x = torch.Tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
......@@ -1176,7 +1176,7 @@ permute(*dims)
参数:`*dims (int...)` – 按所期望的维数排序
Example
示例:
```py
>>> x = torch.randn(2, 3, 5)
......@@ -1322,7 +1322,7 @@ repeat(*sizes)
参数:`*sizes (torch.Size 或 int...)` – 沿每个维度重复 tensor 的次数
Example
示例:
```py
>>> x = torch.Tensor([1, 2, 3])
......@@ -1346,7 +1346,7 @@ resize_(*sizes)
参数:`*sizes (torch.Size 或 int...)` – 期望的大小
Example
示例:
```py
>>> x = torch.Tensor([[1, 2], [3, 4], [5, 6]])
......@@ -1537,7 +1537,7 @@ size() → torch.Size
返回 tensor 的大小. 返回的值是 [`tuple`](https://docs.python.org/3/library/stdtypes.html#tuple) 的子类.
Example
示例:
```py
>>> torch.Tensor(3, 4, 5).size()
......@@ -1601,7 +1601,7 @@ storage_offset() → int
按照储存元素个数的偏移返回 tensor 在底层存储中的偏移量(不是按照字节计算).
Example
示例:
```py
>>> x = torch.Tensor([1, 2, 3, 4, 5])
......@@ -1623,7 +1623,7 @@ stride(dim) → tuple or int
参数:`dim (int)` – 期望的需要计算步长的维度.
Example
示例:
```py
>>> x = torch.Tensor([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]])
......@@ -1899,7 +1899,7 @@ view(*args) → Tensor
参数:`args (torch.Size 或 int...)` – 期望的大小
Example
示例:
```py
>>> x = torch.randn(4, 4)
......
......@@ -316,7 +316,7 @@ torch.range(start, end, step=1, out=None) → Tensor
返回一个在 `start``end` 并且步长为 `step` 的区间内, 大小为 ![floor((end - start) / step) + 1](img/tex-a8d4b9eb08b29e4455688db33c092ae9.gif) 为一维 Tensor. `step` 是 tensor 中两个值之间的差距. ![x_{i+1} = x_i + step](img/tex-b99fbae9badbed7f3e2e937599966cd4.gif)
Warning
警告:
此功能已被弃用, 以支持 `torch.arange()`.
......@@ -852,7 +852,7 @@ torch.unsqueeze(input, dim, out=None)
Example
示例:
```py
>>> x = torch.Tensor([1, 2, 3, 4])
......
......@@ -15,7 +15,7 @@ class torchvision.transforms.Compose(transforms)
参数:`transforms (Transform 对象列表)` – 要组合的变换列表.
Example
示例:
```py
>>> transforms.Compose([
......@@ -142,7 +142,7 @@ class torchvision.transforms.FiveCrop(size)
参数:`size (sequence 或 int)` – 期望输出的裁剪尺寸. 如果 `size``int` 类型的整数, 而不是像 `(h, w)` 这样类型的序列, 裁剪出来的图像是 `(size, size)` 这样的正方形的..
Example
示例:
```py
>>> transform = Compose([
......@@ -174,7 +174,7 @@ class torchvision.transforms.TenCrop(size, vertical_flip=False)
Example
示例:
```py
>>> transform = Compose([
......
......@@ -22,7 +22,7 @@ torchvision.utils.make_grid(tensor, nrow=8, padding=2, normalize=False, range=No
Example
示例:
请参阅 [这里](https://gist.github.com/anonymous/bf16430f7750c023141c562f3e9f2a91) 的手册
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册