Conversation
✅ Translation Quality ReviewVerdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-04-14 📝 Translation Quality
Summary: The translation is of high quality overall, with accurate technical content, natural Chinese phrasing, and correct formatting. There are a few minor issues: one note block contains an added sentence not present in the source, one summary section contains a concluding sentence not in the original English, and a couple of minor phrasing choices could be improved for naturalness. These are small issues in an otherwise strong translation of the modified sections. Technical terminology is consistently and accurately translated throughout all modified sections, including JIT compilation concepts, functional programming terms, and random number generation concepts. The '示例——纯函数与非纯函数' section (newly added) is well-translated, clearly conveying the distinction between pure and impure functions with natural Chinese phrasing. The '内存问题' section (newly added) accurately translates the memory usage discussion, preserving the technical nuance about eager execution and intermediate arrays. Mathematical formatting, code blocks, MyST directives, and cross-references are all properly preserved across all modified sections. The overall recommendations section reads naturally in Chinese and faithfully represents the trade-off analysis between JAX, NumPy, and Numba. Suggestions:
🔍 Diff Quality
Summary: All changes in both target files correctly mirror the source changes in position, structure, and translation metadata. This review was generated automatically by action-translation review mode. |
There was a problem hiding this comment.
Pull request overview
Automated translation-sync PR updating the zh-cn JAX-related lectures to match upstream content changes, including new/updated sections and refreshed translation sync state.
Changes:
- Update
numpy_vs_numba_vs_jaxlecture content to add/expand sections (e.g., memory discussion, JAX sequential loop approaches) and adjust narrative/code cells. - Update
jax_introlecture structure and headings, especially around functional programming, random numbers, and JIT compilation. - Refresh translation sync state files with new
source-sha/synced-at.
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 new translated sections/headings and revises examples for vectorized + sequential comparisons. |
lectures/jax_intro.md |
Restructures translated headings and rewrites portions of the functional programming / RNG / JIT discussion. |
.translate/state/numpy_vs_numba_vs_jax.md.yml |
Updates upstream source-sha and sync timestamp. |
.translate/state/jax_intro.md.yml |
Updates upstream source-sha and sync timestamp. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -194,8 +235,6 @@ grid = np.linspace(-3, 3, 3_000) | |||
| with qe.Timer(): | |||
| # First run | |||
| z_max_numba = compute_max_numba(grid) | |||
| ``` | ||
|
|
||
| 这个故事的寓意:使用 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 设计的核心,使其在科学计算和机器学习领域尤为强大。 | ||
|
|
||
| ## 练习 | ||
|
|
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.