2024年5月28日 星期二

將 HuggingFace 模型轉換為 GGUF

 將 HuggingFace 模型轉換為 GGUF

1.安裝python 3.11.9,不要用python 3.12版

2.安裝git

3.重新開機

4.git clone https://github.com/ggerganov/llama.cpp.git

5.cd llama.cpp 

  pip install -r requirements.txt

6.測試llama.cpp

  python convert.py -h

出現:ImportError: DLL load failed while importing _sentencepiece: 找不到指定的模組。

安裝Microsoft visual c++ 2015 redistributable(x64)

https://www.microsoft.com/en-us/download/confirmation.aspx?id=48145

安裝後在執行一次python convert.py -h

7.將下載 HuggingFace 模型目錄複製到llama.cpp目錄下

python convert.py c:\llama.cpp\INX-TEXT_Bailong-instruct-7B --outfile bailong-instruct-7b-f16.gguf --outtype f16

轉出來大小約13.5G,還是太大

8.Windows使用llama.cpp量化(quantize)前準備

llama.cpp量化(quantize) 前要先做make。


9.下載w64devkit-1.xxx並執行w64devkit.exe。


  https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#build


  https://github.com/skeeto/w64devkit/releases/tag/v1.23.0

下載w64devkit-1.23.0.zip並解壓

10.進入w64devkit目錄並執行w64devkit.exe

11.然後進入llama.cpp目錄 cd /llama.cpp

12.執行make

   會跑一下下,完成後執行exit跳回windos的命令提示字元CMD下

   quantize.exe就會生成在llama.cpp的資料夾下

# 以q4_k_m 為例

# q4_k_m:提供了不同程度的準確性和推理速度,適合需要平衡資源使用的場景。


13.cd llama.cpp 

14.執行.\quantize.exe bailong-instruct-7b-f16.gguf bailong-instruct-7b-q4_k_m.gguf q4_k_m


當中數字是代表量化的 bits 設定;以下是參考他對於不同量化的推薦和說明:


q2_k:特定張量 (Tensor) 采用較高的精度設置,而其他的則保持基礎級別。

q3_k_l、q3_k_m、q3_k_s:這些變體在不同張量上使用不同級別的精度,從而達到性能和效率的平衡。

q4_0:這是最初的量化方案,使用 4 位精度。

q4_1和q4_k_m、q4_k_s:這些提供了不同程度的準確性和推理速度,適合需要平衡資源使用的場景。

q5_0、q5_1、q5_k_m、q5_k_s:這些版本在保證更高準確度的同時,會使用更多的資源並且推理速度較慢。

q6_k和q8_0:這些提供了最高的精度,但是因為高資源消耗和慢速度,可能不適合所有用戶。

如果追求較低成本和保持模型效能的情況推薦使用用 Q5_K_M,如果想更節省 RAM,則可以考慮 Q4_K_M。一般來說,帶有 K_M 的版本會比 K_S 的版本表現更佳。不過不建議使用 Q2_K 或 Q3_* 等版本,因為它們會顯著降低模型的整體性能。


----------------------------------------------------------------------------------------------

如何下載HuggingFace的模組

1.進入HuggingFace想要處理的模組例如INX-TEXT/Bailong-instruct-7B

那就去HuggingFace網頁搜尋INX-TEXT/Bailong-instruct-7B

2.進入後點選Files,在右邊有3個.,點選後出現clone repository,會出現如何下載

3.git lfs install

4.git clone https://huggingface.co/INX-TEXT/Bailong-instruct-7B

會出現要HuggingFace的帳號及密碼,輸入後才可下載--不能使用因為要你的token

4-1.使用download.py,或者一個個去下載


from huggingface_hub import snapshot_download


model_id = "INX-TEXT/Bailong-instruct-7B" # hugginFace's model name

snapshot_download(

    repo_id=model_id, 

    local_dir="INX-TEXT_Bailong-instruct-7B",

    local_dir_use_symlinks=False,

    revision="main",

    use_auth_token="<YOUR_HF_ACCESS_TOKEN>")


YOUR_HF_ACCESS_TOKEN--使用帳號進入後在settings--Access Tokens中去設定

執行 python download.py


5.上傳轉檔及量化後的 GGUF 模型到 Huggingface Repo

避免透過 git pull 來上傳大型的檔案下來寫一個 upload.py


from huggingface_hub import HfApi

import os


api = HfApi()

HF_ACCESS_TOKEN = "<YOUR_HF_WRITE_ACCESS_TOKEN>"

model_id = "NeroUCH/Bailong-instruct-7B-GGUF"


api.create_repo(

    model_id,

    exist_ok=True,

    repo_type="model", # 上傳格式為模型

    use_auth_token=HF_ACCESS_TOKEN,

)

# upload the model to the hub

# upload model name includes the Bailong-instruct-7B in same folder

for file in os.listdir():

    if file.endswith(".gguf"):

        model_name = file.lower()

        api.upload_file(

            repo_id=model_id,

            path_in_repo=model_name,

            path_or_fileobj=f"{os.getcwd()}/{file}",

            repo_type="model", # 上傳格式為模型

            use_auth_token=HF_ACCESS_TOKE)


參考:

https://medium.com/@NeroHin/%E5%B0%87-huggingface-%E6%A0%BC%E5%BC%8F%E6%A8%A1%E5%BC%8F%E8%BD%89%E6%8F%9B%E7%82%BA-gguf-%E4%BB%A5inx-text-bailong-instruct-7b-%E7%82%BA%E4%BE%8B-a2cfdd892cbc


https://medium.com/@zhanyanjiework/%E5%B0%87huggingface%E6%A8%A1%E5%9E%8B%E8%BD%89%E6%8F%9B%E7%82%BAgguf%E5%8F%8A%E4%BD%BF%E7%94%A8llama-cpp%E9%80%B2%E8%A1%8C%E9%87%8F%E5%8C%96-%E4%BB%A5taide-b-11-0-0%E6%A8%A1%E5%9E%8B%E7%82%BA%E4%BE%8B-%E9%83%A8%E7%BD%B2lm-studio-366bc4bcb690

2024年5月14日 星期二

安裝 Windows 11 時跳過網路設定

 需要先按下鍵盤的「Shift + F10」、理論上他會開啟一個命令提示字元的視窗。這時候在裡面輸入「oobe\bypassnro」後按下 Enter,系統應該就會重開,重新開始初始化的流程

2024年5月7日 星期二

完全關閉Windows Hyper-V

1. 使用管理員權限開啟CMD或PowerShell

2. 執行以下指令
------------------------------------------
bcdedit /set hypervisorlaunchtype off

------------------------------------------
3. 重開機

參考:https://home.gamer.com.tw/artwork.php?sn=4516067

2024年4月17日 星期三

虛擬機安裝LINUX後出現blk_update_request: I/O error, dev fd0, sector 0...

 問題背景:

行命令netplan apply用配置的ip報錯: blk_update_request: I/O

 error, dev fd0, sector 0



問題分析:

報這個錯,是因 linux了 floppy 軟碟驅動,我的虛機沒軟碟

統啟動時軟碟驅動



方法:

過關閉軟碟塊來



# sudo lsmod | grep -i floppy

# sudo rmmod floppy

# echo "blacklist floppy" | sudo tee /etc/modprobe.d/blacklist-floppy.conf

sudo dpkg-reconfigure initramfs-tools 或 sudo update-initramfs -u -k all

# reboot



確認floppy塊沒用即可。

# lsmod | grep -i floppy


2024年4月11日 星期四

docker 安裝windows系列

在ubuntu 建置docker及compose

安裝KVM

sudo apt install cpu-checker -y

執行 sudo kvm-ok 

順利的話出現

INFO: /dev/kvm exists
KVM acceleration can be used

 1.下載windows鏡像

docker pull dockurr/windows

也可以選擇本地構建:

git clone https://github.com/dockur/windows.git

cd windows

docker build -t dockurr/windows .

2.建立docker-compose.yml

#version: "3" --目前新版本已不適用
services:
  windows:
    image: dockurr/windows
    container_name: windows
    privileged: true
    environment:
      VERSION: "win11"
      BOOT_MODE: "windows_plain"
    devices:
      - /dev/kvm
    cap_add:
      - NET_ADMIN
    ports:
      - 8006:8006
      - 3389:3389/tcp
      - 3389:3389/udp
    stop_grace_period: 2m
    restart: on-failure
    network_mode: bridge
3.執行docker compose up
4.用瀏覽器連 docker主機IP:8006
ValueDescriptionSourceTransferSize
win11Windows 11 ProMicrosoftFast6.4 GB
win10Windows 10 ProMicrosoftFast5.8 GB
ltsc10Windows 10 LTSCMicrosoftFast4.6 GB
win81Windows 8.1 ProMicrosoftFast4.2 GB
win7Windows 7 SP1Bob PonyMedium3.0 GB
vistaWindows Vista SP2Bob PonyMedium3.6 GB
winxpWindows XP SP3Bob PonyMedium0.6 GB
2022Windows Server 2022MicrosoftFast4.7 GB
2019Windows Server 2019MicrosoftFast5.3 GB
2016Windows Server 2016MicrosoftFast6.5 GB
2012Windows Server 2012 R2MicrosoftFast4.3 GB
2008Windows Server 2008 R2MicrosoftFast3.0 GB
core11Tiny 11 CoreArchive.orgSlow2.1 GB
tiny11Tiny 11Archive.orgSlow3.8 GB
tiny10Tiny 10Archive.orgSlow3.6 GB

參考:https://github.com/dockur/windows
https://soulteary.com/2024/03/11/install-windows-into-a-docker-container.html#%E5%86%99%E5%9C%A8%E5%89%8D%E9%9D%A2




2024年4月3日 星期三

proxmox 出現 an't lock file '/var/lock/qemu-server/lock-107.conf' - got timeout

 1.進入 cd /var/lock/qemu-server

2.將要關閉的guest的conf刪除,例如: rm -rf lock-107.conf

3.停止guest, 例如: qm stop 107