Skip to content

docs: add Mac Apple Silicon fine-tuning notes (#187) - #227

Open
Yu-0312 wants to merge 1 commit into
xming521:masterfrom
Yu-0312:docs/issue-187-mac-tuning
Open

docs: add Mac Apple Silicon fine-tuning notes (#187)#227
Yu-0312 wants to merge 1 commit into
xming521:masterfrom
Yu-0312:docs/issue-187-mac-tuning

Conversation

@Yu-0312

@Yu-0312 Yu-0312 commented Aug 22, 2026

Copy link
Copy Markdown

Closes #187. Added notes for Mac (Apple Silicon) users regarding MPS support, flash-attention limitations, and memory tuning recommendations in both English and Chinese READMEs.

Sourcery 摘要

文档:

  • 添加英文和中文 README 指南,介绍如何在 Apple Silicon Mac 上进行微调,包括 MPS 支持、FlashAttention 的限制以及内存调优建议。
Original summary in English

Sourcery 摘要

文档:

  • 添加英文和中文 README 指南,介绍如何在 Apple Silicon Mac 上进行微调,涵盖 MPS 支持、FlashAttention 替代方案以及统一内存调优建议。
Original summary in English

Summary by Sourcery

Documentation:

  • Add English and Chinese README guidance for fine-tuning on Apple Silicon Macs, covering MPS support, FlashAttention alternatives, and unified-memory tuning recommendations.

@sourcery-ai

sourcery-ai Bot commented Aug 22, 2026

Copy link
Copy Markdown
审查者指南(小型 PR 中折叠显示)

审查者指南

为 Mac Apple Silicon 用户添加平台特定的微调说明到英文和中文 README 中,涵盖 MPS 的使用、FlashAttention 的限制以及与内存相关的配置建议。

文件级更改

更改 详细信息 文件
在英文 README 中记录 Mac Apple Silicon 微调注意事项。
  • 在单 GPU 训练部分下方添加 NOTE 块,说明 Mac 上的 MPS 支持以及 PyTorch 的自动检测功能
  • 说明无法在 Mac 上安装 flash-attn,并且不应在 settings.jsonc 中启用依赖 FlashAttention 的选项,同时阐明 LlamaFactory 的回退行为
  • 由于统一内存的限制,建议在 Mac 上降低 per_device_train_batch_size 和 cutoff_len
README.md
在中文 README 中记录 Mac Apple Silicon 微调注意事项。
  • 在单 GPU 训练部分下方添加中文 NOTE 块,说明 Mac 上的 MPS 支持以及 PyTorch 的自动检测功能
  • 用中文说明无法在 Mac 上安装 flash-attn,并且不应在 settings.jsonc 中启用依赖 FlashAttention 的选项,同时阐明 LlamaFactory 的回退行为
  • 由于统一内存的限制,建议在 Mac 上降低 per_device_train_batch_size 和 cutoff_len
README_zh.md

针对关联 Issue 的评估

Issue 目标 已解决 说明
#187 记录在搭载 Apple Silicon 的 Mac 设备上进行微调的指导。
#187 说明影响微调的 Mac 特定注意事项,包括 MPS 支持、FlashAttention 限制和统一内存约束。

提示和命令

与 Sourcery 交互

  • 触发新的审查: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论生成 GitHub Issue: 回复审查评论,请 Sourcery 根据该评论创建 Issue。你也可以使用 @sourcery-ai issue 回复审查评论,以根据该评论创建 Issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以随时(重新)生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中需要生成摘要的位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以随时(重新)生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,此功能会很有用。
  • 驳回所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可驳回所有现有的 Sourcery 审查。如果你想从新的审查开始,这一功能尤其有用——别忘了评论
    @sourcery-ai review 以触发新的审查!

自定义使用体验

访问你的控制面板以:

  • 启用或禁用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds platform-specific fine-tuning notes for Mac Apple Silicon users to both the English and Chinese READMEs, covering MPS usage, FlashAttention limitations, and memory-related configuration guidance.

File-Level Changes

Change Details Files
Document Mac Apple Silicon fine-tuning considerations in the English README.
  • Add a NOTE block under the single-GPU training section describing MPS support on Mac and automatic detection by PyTorch
  • Explain that flash-attn cannot be installed on Mac and that FlashAttention-dependent options should not be enabled in settings.jsonc, clarifying LlamaFactory’s fallback behavior
  • Recommend reducing per_device_train_batch_size and cutoff_len on Mac due to unified memory limits
README.md
Document Mac Apple Silicon fine-tuning considerations in the Chinese README.
  • Add a Chinese NOTE block under the single-GPU training section describing MPS support on Mac and automatic detection by PyTorch
  • Explain in Chinese that flash-attn cannot be installed on Mac and that FlashAttention-dependent options should not be enabled in settings.jsonc, clarifying LlamaFactory’s fallback behavior
  • Recommend in Chinese reducing per_device_train_batch_size and cutoff_len on Mac due to unified memory limits
README_zh.md

Assessment against linked issues

Issue Objective Addressed Explanation
#187 Document guidance for fine-tuning on Mac devices with Apple Silicon.
#187 Explain Mac-specific considerations that affect fine-tuning, including MPS support, FlashAttention limitations, and unified-memory constraints.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

你好——我发现了 2 个问题

AI Agent 提示词
请处理此次代码审查中的评论:

## 个别评论

### 评论 1
<location path="README.md" line_range="152" />
<code_context>
+> [!NOTE]
+> **Mac Device (Apple Silicon) Fine-tuning Notes**:
+> - LlamaFactory supports training using Mac's MPS (Metal Performance Shaders). No additional configuration is needed, PyTorch will automatically recognize the MPS device.
+> - `flash-attn` **cannot be installed** on Mac (FlashAttention only supports NVIDIA GPUs), so make sure not to configure options dependent on FlashAttention in `settings.jsonc` (LlamaFactory will automatically fall back to standard attention or SDPA by default).
+> - Limited by Mac's unified memory, it is recommended to appropriately reduce `per_device_train_batch_size` and `cutoff_len` based on your machine's memory size.
+
</code_context>
<issue_to_address>
**问题(更广泛的影响):** Mac 说明要求避免使用 FlashAttention,但文档中的设置步骤会复制一个模板,而该模板中的 `train_sft_args.flash_attn` 默认值为 `fa2`,训练命令也会将此值传递给 LlamaFactory。因此,用户如果按照设置步骤操作,却没有手动编辑生成的设置,就可能尝试使用不可用的软件包,而不是获得所承诺的标准注意力机制回退。

**触发条件:** Mac 用户复制 `examples/tg.template.jsonc` 或其他提供的模板,并直接运行文档中未修改的训练命令时。

**建议修复:** 告知 Mac 用户移除 `flash_attn`,或将其设置为受支持的非 FlashAttention 模式,并确保模板或设置说明体现这一要求;同时,将前面可选的安装命令明确限定为非 Mac 环境使用。
</issue_to_address>

### 评论 2
<location path="README_zh.md" line_range="150" />
<code_context>
+> **Mac 设备(Apple Silicon)微调注意事项**:
+> - LlamaFactory 支持使用 Mac 的 MPS(Metal Performance Shaders)进行训练,无需额外配置,PyTorch 会自动识别 MPS 设备。
+> - Mac 上**无法安装** `flash-attn`(FlashAttention 仅支持 NVIDIA GPU),因此请确保在 `settings.jsonc` 中不要配置依赖于 FlashAttention 的选项(LlamaFactory 默认会自动回退到普通注意力机制或 SDPA)。
+> - 受限于 Mac 的统一内存,建议根据机型显存大小适当调小 `per_device_train_batch_size``cutoff_len`+
 ### 多卡训练
</code_context>
<issue_to_address>
**问题:** 中文说明建议 Apple Silicon 用户根据 `显存大小`(VRAM)调整设置,但 Apple Silicon 使用的是统一系统内存,而不是独立的显存。这会让用户参考错误的资源指标,并可能导致他们选择超出可用统一内存的批次大小和序列长度。

**触发条件:** 中文 Mac 用户根据设备报告的 GPU/VRAM 数值应用内存调整建议时。

**建议修复:**`显存大小` 替换为 `统一内存大小`,并明确说明相关限制是进程可用的系统总内存,包括其他应用占用的内存。

```suggestion
> - 受限于 Mac 的统一内存,建议根据机型统一内存大小(需考虑其他应用占用)适当调小 `per_device_train_batch_size` 和 `cutoff_len`。
```
</issue_to_address>

Sourcery 对开源项目免费——如果您喜欢我们的审查结果,请考虑分享 ✨
帮助我变得更有用!请对每条评论点击 👍 或 👎,我会利用反馈来改进审查结果。
Original comment in English

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="README.md" line_range="152" />
<code_context>
+> [!NOTE]
+> **Mac Device (Apple Silicon) Fine-tuning Notes**:
+> - LlamaFactory supports training using Mac's MPS (Metal Performance Shaders). No additional configuration is needed, PyTorch will automatically recognize the MPS device.
+> - `flash-attn` **cannot be installed** on Mac (FlashAttention only supports NVIDIA GPUs), so make sure not to configure options dependent on FlashAttention in `settings.jsonc` (LlamaFactory will automatically fall back to standard attention or SDPA by default).
+> - Limited by Mac's unified memory, it is recommended to appropriately reduce `per_device_train_batch_size` and `cutoff_len` based on your machine's memory size.
+
</code_context>
<issue_to_address>
**issue (broader_impact):** The Mac instructions say to avoid FlashAttention, but the documented setup copies a template whose `train_sft_args.flash_attn` defaults to `fa2`, and the training command passes that value to LlamaFactory. A user who follows the setup without manually editing the generated settings can therefore attempt to use the unavailable package instead of receiving the promised standard-attention fallback.

**Triggers:** When a Mac user copies `examples/tg.template.jsonc` or another provided template and runs the documented training command unchanged.

**Suggested fix:** Tell Mac users to remove `flash_attn` or set it to the supported non-FlashAttention mode, and make the templates or setup instructions reflect that requirement; also qualify the earlier optional installation command as non-Mac-only.
</issue_to_address>

### Comment 2
<location path="README_zh.md" line_range="150" />
<code_context>
+> **Mac 设备(Apple Silicon)微调注意事项**:
+> - LlamaFactory 支持使用 Mac 的 MPS(Metal Performance Shaders)进行训练,无需额外配置,PyTorch 会自动识别 MPS 设备。
+> - Mac 上**无法安装** `flash-attn`(FlashAttention 仅支持 NVIDIA GPU),因此请确保在 `settings.jsonc` 中不要配置依赖于 FlashAttention 的选项(LlamaFactory 默认会自动回退到普通注意力机制或 SDPA)。
+> - 受限于 Mac 的统一内存,建议根据机型显存大小适当调小 `per_device_train_batch_size``cutoff_len`+
 ### 多卡训练
</code_context>
<issue_to_address>
**issue:** The Chinese note tells Apple Silicon users to size the settings according to `显存大小` (VRAM), but Apple Silicon exposes unified system memory rather than discrete VRAM. This gives users the wrong resource to measure and can lead them to choose batch and sequence lengths that exceed the available unified memory.

**Triggers:** When a Chinese-language Mac user applies the memory-tuning recommendation using the machine's reported GPU/VRAM value.

**Suggested fix:** Replace `显存大小` with `统一内存大小` and make clear that the total system memory available to the process, including other applications, is the relevant limit.

```suggestion
> - 受限于 Mac 的统一内存,建议根据机型统一内存大小(需考虑其他应用占用)适当调小 `per_device_train_batch_size` 和 `cutoff_len`。
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread README.md Outdated
Comment thread README_zh.md Outdated
@Yu-0312
Yu-0312 force-pushed the docs/issue-187-mac-tuning branch from 202b3cd to 82cd27f Compare August 22, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mac设备微调办法

1 participant