Skip to content

Commit

Permalink
更新部分翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangzhonglian committed Dec 28, 2023
1 parent 700c40c commit e64fc66
Show file tree
Hide file tree
Showing 20 changed files with 407 additions and 356 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![](docs/img/logo.svg)

<center>PyTorch 是一个针对深度学习, 并且使用 GPU 和 CPU 来优化的 tensor library (张量库)</center>
<center>PyTorch 是一个针对深度学习, 并且使用 GPU 和 CPU 来优化的 tensor library (tensor库)</center>
<br/>
<table>
<tr align="center">
Expand Down Expand Up @@ -50,7 +50,7 @@
## 关于转载

* **最近有很多人联系我们,关于内容授权问题!**
* 开源是指知识应该重在传播和迭代而不是禁止别人转载
* 开源是指知识应该重在传播和迭代(而不是禁止别人转载)
* 不然你TM在GitHub开源,然后又说不让转载,你TM有病吧!
* 禁止商业化,符合协议规范,备注地址来源,**重点: 不需要**发邮件给我们申请

Expand Down
4 changes: 2 additions & 2 deletions docs/2.0/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
>
> 原始地址:<https://pytorch.org/docs/2.0/>
PyTorch 是一个针对深度学习,基于 GPU 和 CPU 的优化张量库
PyTorch 是一个针对深度学习,基于 GPU 和 CPU 的优化tensor库

本文档中描述的功能按发布状态分类:

- *稳定版:* 这些功能将长期维护,并且文档中通常不会有主要性能限制或差距。我们还希望保持向后兼容性尽管可能会发生破坏性更改,但是会提前一个版本会给出通知
- *稳定版:* 这些功能将长期维护,并且文档中通常不会有主要性能限制或差距。我们还希望保持向后兼容性(尽管可能会发生破坏性更改,但是会提前一个版本会给出通知)

- *Beta 版:* 这些功能被标记为 Beta 版,因为 API 可能会根据用户反馈而更改,因为性能需要改进,或者因为操作覆盖范围尚不完整。对于 Beta 版功能,我们承诺将该功能推进到稳定版。但是,我们不承诺向后兼容性。

Expand Down
24 changes: 12 additions & 12 deletions docs/2.0/docs/amp.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
在这些区域中,操作以 autocast 选择的操作特定数据类型运行,以提高性能,同时保持准确性。有关详细信息,请参阅 [Autocast Op 参考](#autocast-op-reference)


当进入启用自动转换的区域时,张量可以是任何类型。使用自动转换时,不应在模型或输入上调用“half()”或“bfloat16()”。
当进入启用自动转换的区域时,tensor可以是任何类型。使用自动转换时,不应在模型或输入上调用“half()”或“bfloat16()”。


[`autocast`](#torch.autocast "torch.autocast") 应仅包装网络的前向传递,包括损失计算。不建议在自动转换下向后传递。向后操作的运行类型与自动转换用于相应前向操作的类型相同。
Expand Down Expand Up @@ -97,7 +97,7 @@ class AutocastModel(nn.Module):
```


在启用自动转换的区域中生成的浮点张量可能是“float16”。返回到禁用自动转换的区域后,将它们与不同数据类型的浮点张量一起使用可能会导致类型不匹配错误。如果是这样,则将自动转换区域中生成的张量转换回“float32”(或其他需要的数据类型)。如果自动转换区域中的张量已经是“float32”,则转换是无操作,并且会产生没有额外的开销。CUDA示例:
在启用自动转换的区域中生成的浮点tensor可能是“float16”。返回到禁用自动转换的区域后,将它们与不同数据类型的浮点tensor一起使用可能会导致类型不匹配错误。如果是这样,则将自动转换区域中生成的tensor转换回“float32”(或其他需要的数据类型)。如果自动转换区域中的tensor已经是“float32”,则转换是无操作,并且会产生没有额外的开销。CUDA示例:


```
Expand Down Expand Up @@ -220,7 +220,7 @@ with torch.autocast(device_type="cuda"):

Parameters

* **device_type** ( [*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)")*, *required* ) – 要使用的设备类型。 可能的值为:“cuda”、“cpu”、“xpu”和“hpu”。 该类型与 [`torch.device`](tensor_attributes.html#torch.device "torch.device") 的 type 属性相同。 因此,您可以使用 Tensor.device.type 获取张量的设备类型
* **device_type** ( [*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.12)")*, *required* ) – 要使用的设备类型。 可能的值为:“cuda”、“cpu”、“xpu”和“hpu”。 该类型与 [`torch.device`](tensor_attributes.html#torch.device "torch.device") 的 type 属性相同。 因此,您可以使用 Tensor.device.type 获取tensor的设备类型
* **enabled** ( [*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)"), *optional* ) – 是否应在该区域启用自动广播。 默认值:`True`
* **dtype** ( *torch_dtype*, *optional* ) – 是否使用 torch.float16 或 torch.bfloat16。
* **cache_enabled** ( [*bool*](https://docs.python.org/3/library/functions.html#bool "(in Python v3.12)"), *optional* ) – 是否应启用自动投射内的权重缓存。 默认值:`True`
Expand All @@ -240,7 +240,7 @@ with torch.autocast(device_type="cuda"):
Parameters


* **cast_inputs** ( [`torch.dtype`](tensor_attributes.html#torch.dtype "torch.dtype") 或 None,optional,default=None) – 如果不是 `None` ,则当 `forward` 运行时在启用自动转换的区域中,将传入的浮点 CUDA 张量转换为目标 dtype(非浮点张量不受影响),然后在禁用自动转换的情况下执行 `forward`。如果 `None` ,则 `forward` 的内部操作以当前自动施放状态执行。
* **cast_inputs** ( [`torch.dtype`](tensor_attributes.html#torch.dtype "torch.dtype") 或 None,optional,default=None) – 如果不是 `None` ,则当 `forward` 运行时在启用自动转换的区域中,将传入的浮点 CUDA tensor转换为目标 dtype(非浮点tensor不受影响),然后在禁用自动转换的情况下执行 `forward`。如果 `None` ,则 `forward` 的内部操作以当前自动施放状态执行。


!!! note "笔记"
Expand Down Expand Up @@ -334,7 +334,7 @@ with torch.autocast(device_type="cuda"):
>> scale( *outputs* ) [[source]](_modules/torch/cuda/amp/grad_scaler.html#GradScaler.scale)[](#torch.cuda.amp.GradScaler.scale "此定义的永久链接")

将张量或张量列表乘以(“缩放”)缩放因子。
将tensor或tensor列表乘以(“缩放”)缩放因子。


返回缩放后的输出。如果未启用 [`GradScaler`](#torch.cuda.amp.GradScaler "torch.cuda.amp.GradScaler") 的此实例,则返回未修改的输出。
Expand Down Expand Up @@ -427,7 +427,7 @@ with torch.autocast(device_type="cuda"):
>> unscale_ ( *optimizer* ) [[source]](_modules/torch/cuda/amp/grad_scaler.html#GradScaler.unscale_)[](#torch.cuda.amp.GradScaler.unscale_ "此定义的永久链接")

将优化器的梯度张量除以比例因子(“取消缩放”)。
将优化器的梯度tensor除以比例因子(“取消缩放”)。


unscale_() 是可选的,适用于需要修改或检查向后传递和 step() 之间的梯度的情况。 如果未显式调用 unscale_(),则梯度将在 step() 期间自动取消缩放。
Expand Down Expand Up @@ -480,7 +480,7 @@ scaler.update()
如果跳过任何优化器步骤,则比例将乘以“backoff_factor”以减少它。如果连续发生“growth_interval”未跳过的迭代,则将比例乘以“growth_factor”来增加它。


传递 `new_scale` 手动设置新的比例值。 ( `new_scale` 不直接使用,它用于填充 GradScaler 的内部尺度张量。因此,如果 `new_scale` 是一个张量,以后对该张量的就地更改不会进一步影响 GradScaler 内部使用的尺度。)
传递 `new_scale` 手动设置新的比例值。 ( `new_scale` 不直接使用,它用于填充 GradScaler 的内部尺度tensor。因此,如果 `new_scale` 是一个tensor,以后对该tensor的就地更改不会进一步影响 GradScaler 内部使用的尺度。)


Parameters
Expand Down Expand Up @@ -508,7 +508,7 @@ scaler.update()
在“float64”或非浮点数据类型中运行的操作不符合条件,并且无论是否启用自动转换都将以这些类型运行。


只有异地操作和张量方法才符合资格。在启用自动转换的区域中允许显式提供“out=...”张量的就地变体和调用,但不会经过自动转换。例如,启用自动投射的区域 `a.addmm(b, c)` 可以自动投射,但 `a.addmm_(b, c)``a.addmm(b, c, out=d)` 不能自动投射。最好性能和稳定性,更喜欢在启用自动施放的区域中进行异地操作。
只有异地操作和tensor方法才符合资格。在启用自动转换的区域中允许显式提供“out=...”tensor的就地变体和调用,但不会经过自动转换。例如,启用自动投射的区域 `a.addmm(b, c)` 可以自动投射,但 `a.addmm_(b, c)``a.addmm(b, c, out=d)` 不能自动投射。最好性能和稳定性,更喜欢在启用自动施放的区域中进行异地操作。


使用显式“dtype=...”参数调用的操作不符合条件,并且将产生尊重“dtype”参数的输出。
Expand All @@ -517,7 +517,7 @@ scaler.update()
### [CUDA Op 特定行为](#id8) [](#cuda-op-specific-behavior "永久链接到此标题")


以下列表描述了启用自动转换的区域中合格操作的行为。这些操作始终会经过自动转换,无论它们是作为 [`torch.nn.Module`]( generated/torch.nn.Module.html#torch 的一部分被调用).nn.Module "torch.nn.Module") ,作为函数,或作为 [`torch.Tensor`](tensors.html#torch.Tensor "torch.Tensor") 方法。如果函数在多个命名空间中公开,则无论命名空间如何,它们都会经历自动转换。
以下列表描述了启用自动转换的区域中合格操作的行为。这些操作始终会经过自动转换,无论它们是作为 [`torch.nn.Module`](generated/torch.nn.Module.html#torch 的一部分被调用).nn.Module "torch.nn.Module") ,作为函数,或作为 [`torch.Tensor`](tensors.html#torch.Tensor "torch.Tensor") 方法。如果函数在多个命名空间中公开,则无论命名空间如何,它们都会经历自动转换。


下面未列出的操作不会经过自动施放。它们按照输入定义的类型运行。但是,如果未列出的操作位于自动转换操作的下游,自动转换仍可能会更改其运行的类型。
Expand Down Expand Up @@ -553,16 +553,16 @@ scaler.update()
#### [首选 `binary_cross_entropy_with_logits` 而不是 `binary_cross_entropy`](#id12)[](#prefer-binary-cross-entropy-with-logits-over-binary -交叉熵"此标题的永久链接")


[`torch.nn.function.binary_cross_entropy()`]( generated/torch.nn.function.binary_cross_entropy.html#torch.nn.function.binary_cross_entropy "torch.nn.function.binary_cross_entropy" 的向后传递)(和 [`torch.nn.BCELoss`]( generated/torch.nn.BCELoss.html#torch.nn.BCELoss "torch.nn.BCELoss") ,它包装它)可以产生无法在`float16` 。在启用自动转换的区域中,前向输入可能是“float16”,这意味着后向梯度必须可以用“float16”表示(将“float16”前向输入自动转换为“float32”没有帮助,因为该转换必须在向后反转)。因此,“binary_cross_entropy”和“BCELoss”在启用自动转换的区域中会引发错误。
[`torch.nn.function.binary_cross_entropy()`](generated/torch.nn.function.binary_cross_entropy.html#torch.nn.function.binary_cross_entropy "torch.nn.function.binary_cross_entropy" 的向后传递)(和 [`torch.nn.BCELoss`](generated/torch.nn.BCELoss.html#torch.nn.BCELoss "torch.nn.BCELoss") ,它包装它)可以产生无法在`float16` 。在启用自动转换的区域中,前向输入可能是“float16”,这意味着后向梯度必须可以用“float16”表示(将“float16”前向输入自动转换为“float32”没有帮助,因为该转换必须在向后反转)。因此,“binary_cross_entropy”和“BCELoss”在启用自动转换的区域中会引发错误。


许多模型在二元交叉熵层之前使用 sigmoid 层。 在这种情况下,使用 [`torch.nn.function.binary_cross_entropy_with_logits()`](generated/torch.nn.functional.binary_cross_entropy_with_logits.html#torch.nn.functional.binary_cross_entropy_with_logits "torch.nn.function.binary_cross_entropy_with_logits")[`torch.nn.BCEWithLogitsLoss`](生成/torch.nn.BCEWithLogitsLoss.html#torch.nn.BCEWithLogitsLoss "torch.nn.BCEWithLogitsLoss") 组合两个层。 `binary_cross_entropy_with_logits``BCEWithLogits` 可以安全地自动转换。
许多模型在二元交叉熵层之前使用 sigmoid 层。 在这种情况下,使用 [`torch.nn.function.binary_cross_entropy_with_logits()`](generated/torch.nn.functional.binary_cross_entropy_with_logits.html#torch.nn.functional.binary_cross_entropy_with_logits "torch.nn.function.binary_cross_entropy_with_logits")[`torch.nn.BCEWithLogitsLoss`](generated/torch.nn.BCEWithLogitsLoss.html#torch.nn.BCEWithLogitsLoss "torch.nn.BCEWithLogitsLoss") 组合两个层。 `binary_cross_entropy_with_logits``BCEWithLogits` 可以安全地自动转换。


### [CPU Op 特定行为](#id13) [](#cpu-op-specific-behavior "永久链接到此标题")


以下列表描述了启用自动转换的区域中合格操作的行为。这些操作始终会经过自动转换,无论它们是作为 [`torch.nn.Module`]( generated/torch.nn.Module.html#torch 的一部分被调用).nn.Module "torch.nn.Module") ,作为函数,或作为 [`torch.Tensor`](tensors.html#torch.Tensor "torch.Tensor") 方法。如果函数在多个命名空间中公开,则无论命名空间如何,它们都会经历自动转换。
以下列表描述了启用自动转换的区域中合格操作的行为。这些操作始终会经过自动转换,无论它们是作为 [`torch.nn.Module`](generated/torch.nn.Module.html#torch 的一部分被调用).nn.Module "torch.nn.Module") ,作为函数,或作为 [`torch.Tensor`](tensors.html#torch.Tensor "torch.Tensor") 方法。如果函数在多个命名空间中公开,则无论命名空间如何,它们都会经历自动转换。


下面未列出的操作不会经过自动施放。它们按照输入定义的类型运行。但是,如果未列出的操作位于自动转换操作的下游,自动转换仍可能会更改其运行的类型。
Expand Down
6 changes: 3 additions & 3 deletions docs/2.0/docs/cpp_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
## C++ 中的 Tensor 和 Autograd [](#tensor-and-autograd-in-c "此标题的永久链接")


PyTorch Python API 中的大多数张量和 autograd 操作也可以在 C++ API 中使用。这些包括:
PyTorch Python API 中的大多数tensor和 autograd 操作也可以在 C++ API 中使用。这些包括:



* `torch::Tensor` 方法,例如 `add` /`reshape` /`clone` 。有关可用方法的完整列表,请参阅:<https://pytorch.org/cppdocs/api/classat_1_1_tensor.html>
* C++ 张量索引 API,其外观和行为与 Python API 相同。有关其用法的详细信息,请参阅:<https://pytorch.org/cppdocs/notes/tensor_indexing.html>
* 张量 autograd API 和 `torch::autograd` 包对于用 C++ 构建动态神经网络至关重要前端。更多详情请参见:<https://pytorch.org/tutorials/advanced/cpp_autograd.html>
* C++ tensor索引 API,其外观和行为与 Python API 相同。有关其用法的详细信息,请参阅:<https://pytorch.org/cppdocs/notes/tensor_indexing.html>
* tensor autograd API 和 `torch::autograd` 包对于用 C++ 构建动态神经网络至关重要前端。更多详情请参见:<https://pytorch.org/tutorials/advanced/cpp_autograd.html>


## 用 C++ 创作模型 [](#authoring-models-in-c "此标题的永久链接")
Expand Down
2 changes: 1 addition & 1 deletion docs/2.0/docs/cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

| | |
| --- | --- |
| [`current_stream`](generated/torch.cpu.current_stream.html#torch.cpu.current_stream "torch.cpu.current_stream") |返回给定设备当前选择的 [`Stream`]( generated/torch.cpu.Stream.html#torch.cpu.Stream "torch.cpu.Stream")|
| [`current_stream`](generated/torch.cpu.current_stream.html#torch.cpu.current_stream "torch.cpu.current_stream") |返回给定设备当前选择的 [`Stream`](generated/torch.cpu.Stream.html#torch.cpu.Stream "torch.cpu.Stream")|
| [`is_available`](generated/torch.cpu.is_available.html#torch.cpu.is_available "torch.cpu.is_available") |返回一个布尔值,指示 CPU 当前是否可用。 |
| [`synchronize`](generated/torch.cpu.synchronize.html#torch.cpu.synchronize "torch.cpu.synchronize") |等待 CPU 设备上所有流中的所有内核完成。 |
| [`stream`](generated/torch.cpu.stream.html#torch.cpu.stream "torch.cpu.stream") |围绕选择给定流的上下文管理器 StreamContext 的包装。 |
Expand Down
Loading

0 comments on commit e64fc66

Please sign in to comment.