iT邦幫忙

2025 iThome 鐵人賽

DAY 11
0
生成式 AI

我的 AI 學習之路:30天 Gemma 與 Gemini系列 第 11

我的 AI 學習之路:第11天 Gemma 與 Gemini - MAC 本機執行 Gemma

  • 分享至 

  • xImage
  •  

MAC 本機執行 Gemma

前面都是使用雲端的環境來跑Gemma,但會想用Gemma就是要本機執行呀

MAC 環境 Jupyter Notebook

python3 -m pip install jupyter --user
jupyter notebook

https://ithelp.ithome.com.tw/upload/images/20250912/20121643tIZJ9NUb3a.png

Hugging Face Login

from huggingface_hub import login
login(token="你的HF_token")
!pip install -U transformers
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model="google/gemma-3-4b-it")
messages = [
    {"role": "user", "content": "gemma 家族 用繁體中文"},
]
pipe(messages)

注意 error

https://ithelp.ithome.com.tw/upload/images/20250912/20121643PihVH2OyRQ.png

結果我的macOS太舊不能執行

總結

在機器學習和深度學習中,BF16 (Brain Float 16) 是一種特殊的張量資料型態,它代表著一種權衡後的設計,旨在加速訓練和推論,同時減少記憶體使用量。

BF16 (Brain Float 16) 是什麼?
BF16 是一種 16 位元的浮點數格式。它的主要特徵是:

  • 1 位元符號位 (sign bit): 決定數字的正負。

  • 8 位元指數位 (exponent bits): 這與標準的 32 位元浮點數 (FP32) 完全相同,這點非常關鍵。

  • 7 位元尾數位 (mantissa bits): 這用於表示數字的精確度,比 FP32 的 23 位元少很多。

macOS 14 (Sonoma) 是蘋果第一個在Metal Performance Shaders (MPS) 這個框架中正式提供 bfloat16 運算支援的作業系統。

為什麼需要 macOS 14?
在 macOS 14 之前,儘管 M 系列晶片在硬體上可能具備處理 bfloat16 的能力,但作業系統的軟體層面並沒有提供相應的 API 和驅動程式來讓應用程式調用這些功能。

好吧,只好來升級macOS了 ---- GO !


上一篇
我的 AI 學習之路:第10天 Gemma 與 Gemini - Google AI Studio 使用 Gemma
下一篇
我的 AI 學習之路:第12天 Gemma 與 Gemini - Gemma 迷因圖
系列文
我的 AI 學習之路:30天 Gemma 與 Gemini12
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言