🌐 [translation-sync] Misc changes to jax lectures#66
Conversation
✅ Translation Quality ReviewVerdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-05-14 📝 Translation Quality
Summary: The translation is of high quality across all modified sections, with accurate technical content, natural Chinese phrasing, and well-preserved formatting. The main concerns are a few minor additions not present in the source (an extra explanatory sentence in the note block and a concluding sentence in the Sequential Summary), one slightly awkward phrasing in the NumPy/MATLAB section, and a minor word choice issue in the Benefits section. These are small issues in an otherwise excellent translation. Technical terminology is consistently and correctly translated throughout all modified sections, including JIT编译, 纯函数, 向量化, 自动微分, etc. The ### Examples -- Pure and Impure section (ADDED) is well-translated with natural Chinese phrasing that accurately conveys the concepts of pure vs impure functions. Mathematical notation and LaTeX expressions are fully preserved across all modified sections. Code blocks, MyST directives, cross-references, and formatting structures are all correctly maintained in the modified sections. The ### Overall recommendations section reads fluently and naturally in Chinese while faithfully conveying the trade-off analysis from the English source. Suggestions:
🔍 Diff Quality
Summary: All translation sync changes are correctly positioned, scoped, and the heading metadata is properly updated to reflect source document restructuring. This review was generated automatically by action-translation review mode. |
There was a problem hiding this comment.
Pull request overview
This automated translation-sync PR updates the zh-cn JAX-related lectures to track upstream content changes, including reorganized explanations and revised code examples, and refreshes translation state metadata.
Changes:
- Updated
numpy_vs_numba_vs_jaxlecture with expanded vectorization discussion (incl. memory considerations) and revised JAX sequential examples. - Reworked parts of the
jax_introlecture structure (pure/impure example, RNG explanation, JIT discussion) and removed thevmapsection content. - Bumped translation state
.ymlfiles to the new source SHA/date and tool version.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
lectures/numpy_vs_numba_vs_jax.md |
Adds/reshapes sections and examples (NumPy vectorization + memory, JAX vmap approach, JAX sequential loop variants). |
lectures/jax_intro.md |
Restructures sections on functional programming, random numbers, and JIT; removes the vmap vectorization section. |
.translate/state/numpy_vs_numba_vs_jax.md.yml |
Updates translation sync metadata (source SHA, synced date, tool version). |
.translate/state/jax_intro.md.yml |
Updates translation sync metadata (source SHA, synced date, tool version). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| #### 第一次尝试 | ||
|
|
||
| 现在让我们使用 `lax.scan` 创建一个 JAX 版本: | ||
| 以下是使用 `at[t].set` 语法的解决方案,我们在 {ref}`JAX 讲座中讨论过 <jax_at_workaround>` 这一语法。 |
| ``` | ||
|
|
||
| 这个故事的寓意:使用 JAX 时请编写纯函数! | ||
|
|
||
| ## 使用 `vmap` 进行向量化 | ||
|
|
||
| JAX 的另一个强大变换是 `jax.vmap`,它能自动将一个针对单个输入编写的函数向量化,使其可以在批量数据上运行。 | ||
|
|
||
| 这避免了手动编写向量化代码或使用显式循环的需要。 | ||
|
|
||
| ### 一个简单的示例 | ||
|
|
||
| 假设我们有一个函数,用于计算一组数字的均值与中位数之差。 | ||
|
|
||
| ```{code-cell} ipython3 | ||
| def mm_diff(x): | ||
| return jnp.mean(x) - jnp.median(x) | ||
| ``` | ||
|
|
||
| 我们可以将其应用于单个向量: | ||
|
|
||
| ```{code-cell} ipython3 | ||
| x = jnp.array([1.0, 2.0, 5.0]) | ||
| mm_diff(x) | ||
| ``` | ||
|
|
||
| 现在假设我们有一个矩阵,想要对每一行计算这些统计量。 | ||
|
|
||
| 不使用 `vmap` 时,我们需要显式循环: | ||
|
|
||
| ```{code-cell} ipython3 | ||
| X = jnp.array([[1.0, 2.0, 5.0], | ||
| [4.0, 5.0, 6.0], | ||
| [1.0, 8.0, 9.0]]) | ||
|
|
||
| for row in X: | ||
| print(mm_diff(row)) | ||
| ``` | ||
|
|
||
| 然而,Python 循环速度较慢,无法被 JAX 高效编译或并行化。 | ||
|
|
||
| 使用 `vmap` 可以将计算保留在加速器上,并与其他 JAX 变换(如 `jit` 和 `grad`)组合使用: | ||
|
|
||
| ```{code-cell} ipython3 | ||
| batch_mm_diff = jax.vmap(mm_diff) | ||
| batch_mm_diff(X) | ||
| ``` | ||
|
|
||
| 函数 `mm_diff` 是针对单个数组编写的,而 `vmap` 自动将其提升为按行作用于矩阵的函数——无需循环,无需重新塑形。 | ||
|
|
||
| ### 组合变换 | ||
|
|
||
| JAX 的优势之一在于各变换可以自然地组合使用。 | ||
|
|
||
| 例如,我们可以对向量化函数进行 JIT 编译: | ||
|
|
||
| ```{code-cell} ipython3 | ||
| fast_batch_mm_diff = jax.jit(jax.vmap(mm_diff)) | ||
| fast_batch_mm_diff(X) | ||
| ``` | ||
|
|
||
| `jit`、`vmap` 以及(我们接下来将看到的)`grad` 的这种组合方式是 JAX 设计的核心,使其在科学计算和机器学习领域尤为强大。 | ||
|
|
||
| ## 练习 | ||
|
|
50c41c1 to
86a5c13
Compare
|
♻️ Automatically rebased after #57 was merged. Overlapping files: The translation content is preserved; only unchanged sections were updated to match the current |
Automated Translation Sync
This PR contains automated translations from QuantEcon/lecture-python-programming.
Source PR
#533 - Misc changes to jax lectures
Files Updated
lectures/jax_intro.md.translate/state/jax_intro.md.ymllectures/numpy_vs_numba_vs_jax.md.translate/state/numpy_vs_numba_vs_jax.md.ymlThe following sections were not modified by this source PR and are missing from the target. They have been omitted from this PR to keep it scoped to the source PR's actual changes. An earlier translation PR should add them. If that PR is abandoned, run
/translate-resyncto recover.lectures/jax_intro.md:Vectorization with \vmap`,Automatic differentiation: a preview`Details
This PR was created automatically by the translation action.