前面都是使用雲端的環境來跑Gemma,但會想用Gemma就是要本機執行呀
python3 -m pip install jupyter --user
jupyter notebook
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)
在機器學習和深度學習中,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 !