Skip to content

🌐 [translation-sync] Misc changes to jax lectures#66

Merged
mmcky merged 4 commits into
mainfrom
translation-sync-2026-05-14T10-05-25-pr-533
May 14, 2026
Merged

🌐 [translation-sync] Misc changes to jax lectures#66
mmcky merged 4 commits into
mainfrom
translation-sync-2026-05-14T10-05-25-pr-533

Conversation

@mmcky
Copy link
Copy Markdown
Contributor

@mmcky mmcky commented May 14, 2026

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.yml
  • ✏️ lectures/numpy_vs_numba_vs_jax.md
  • ✏️ .translate/state/numpy_vs_numba_vs_jax.md.yml

⚠️ Sections Pending Earlier Translation PR

The 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-resync to recover.

  • lectures/jax_intro.md: Vectorization with \vmap`, Automatic differentiation: a preview`

Details

  • Source Language: en
  • Target Language: zh-cn
  • Model: claude-sonnet-4-6

This PR was created automatically by the translation action.

@github-actions
Copy link
Copy Markdown
Contributor

✅ Translation Quality Review

Verdict: PASS | Model: claude-sonnet-4-6 | Date: 2026-05-14


📝 Translation Quality

Criterion Score
Accuracy 9/10
Fluency 9/10
Terminology 9/10
Formatting 9/10
Overall 9/10

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:

  • With NumPy section (note block): The translation adds extra content not in the original — 'Hold the interpreter until the array operation finishes' uses 'jax.block_until_ready(y)' in the translation but the original uses 'y.block_until_ready()'. The note block text is also expanded with '对于非计时代码,可以删除包含 block_until_ready 的那一行' which has no equivalent in the English source. This addition, while helpful, deviates from the accuracy requirement.

  • NumPy / MATLAB Approach section: '生成通过维护隐藏的全局状态来工作' is slightly awkward. A more natural phrasing would be '生成随机数时通过维护隐藏的全局状态来实现'.

  • Examples -- Pure and Impure section: The impure function explanation '副作用——它修改了全局变量 prices' is slightly inaccurate. The original says 'it modifies the global variable prices' — but prices is a local variable passed in; the side effect is modifying the caller's list. The original English also says 'non-deterministic' should relate to tax_rate, not prices. The translation captures this correctly for the second bullet but the first bullet's characterization could be clearer.

  • Benefits section: '并行化:控制每个独立线程中发生的事情' — the original says 'Control what happens on separate threads' without the word '独立' (independent). While minor, '各个线程' would be more faithful to the source.

  • Summary (numpy_numba_jax): The translation adds a sentence not in the original English: '对于这类顺序运算,在代码清晰度和实现便利性方面,Numba 是明显的赢家。' This conclusion sentence does not appear in the English source and should be removed to maintain accuracy.


🔍 Diff Quality

Check Status
Scope Correct
Position Correct
Structure Preserved
Heading-map Correct
Overall 10/10

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_jax lecture with expanded vectorization discussion (incl. memory considerations) and revised JAX sequential examples.
  • Reworked parts of the jax_intro lecture structure (pure/impure example, RNG explanation, JIT discussion) and removed the vmap section content.
  • Bumped translation state .yml files 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.

Comment thread lectures/numpy_vs_numba_vs_jax.md Outdated
#### 第一次尝试

现在让我们使用 `lax.scan` 创建一个 JAX 版本:
以下是使用 `at[t].set` 语法的解决方案,我们在 {ref}`JAX 讲座中讨论过 <jax_at_workaround>` 这一语法。
Comment thread lectures/jax_intro.md
Comment on lines 759 to 764
```

这个故事的寓意:使用 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 设计的核心,使其在科学计算和机器学习领域尤为强大。

## 练习

@github-actions github-actions Bot force-pushed the translation-sync-2026-05-14T10-05-25-pr-533 branch from 50c41c1 to 86a5c13 Compare May 14, 2026 10:39
@github-actions
Copy link
Copy Markdown
Contributor

♻️ Automatically rebased after #57 was merged.

Overlapping files: lectures/jax_intro.md, lectures/numpy_vs_numba_vs_jax.md

The translation content is preserved; only unchanged sections were updated to match the current main branch. Please re-review if needed.

@mmcky mmcky closed this May 14, 2026
@mmcky mmcky reopened this May 14, 2026
@mmcky mmcky merged commit 8233c0e into main May 14, 2026
2 checks passed
@mmcky mmcky deleted the translation-sync-2026-05-14T10-05-25-pr-533 branch May 14, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants