2024年1月31日 星期三

nvidia driver 靜默安裝

 電腦之前安裝過driver(非透過apt安裝,因為apt提供的driver有時會太過老舊,deep learning使用的framework無法使用),每次ubuntu的kernel更新後又需要重新安裝時:


sudo ./NVIDIA-Linux-x86_64-545.29.02.run -s --sanity

2024年1月14日 星期日

Exception: Vocab size mismatch (model has 61952, but XXX/tokenizer.model has 61875). Add the --pad-vocab option and try again.

情境

透過 llama.cpp工具進行gguf轉檔時,在轉檔過程中出這樣的錯誤訊息。


說明

這種錯誤源自於token model跟vocabulary檔案的output不同。通常都是vocabulary會因為客製化fine-tune過程中,使用的corpus不同,造成在進行cutomize token時,vocabulary轉變了。但進行fine-tune的人沒有發現這問題,設定檔就對不起來。

work arround的做法就是增補vocabulary檔案。想要看vocabulary資訊跟tokenize model資訊可以從:

  1. config.json 當中有 "vocab_size"
  2. tokenizer.json 當中有 token model的輸出數量


解決辦法

1. 所有的下載方式都可以沿用原本的做法,透過script進行下載(範例: https://github.com/markliou/tool_scripts/blob/master/python/llama.cpp_tools/down_hf_model_snapshot.py )

2. 修改vocabulary的數量,直接在vocabulary補上padding。這邊涉及json重寫,所以還是用別人寫好的python工具會比較簡單:


from pathlib import Path
from transformers import AutoTokenizer

pad_no = 61952 - 61875 # 這邊放上vocalbulary和token的數量差異
tokenizer_model_name = 'Breeze-7B-Instruct-v0.1' # 這邊放上要轉換的模型
model_path = 'output' new_tokens = [f"<pad{i}>" for i in range(31)] tokenizer = AutoTokenizer.from_pretrained(tokenizer_model_name, trust_remote_code=True) tokenizer.pad_token = tokenizer.eos_token tokenizer.padding_side = "right" tokenizer.add_tokens(new_tokens) tokenizer.save_pretrained(Path(model_path)) tokenizer.save_vocabulary(model_path)

上面的範例就轉了Llama-2-7b-hf的模型,並且把重建好的json放到output的資料夾裡面。接下來檢查一下建立好的json有沒有異常。確認沒有異常後,就是把output裡面所有的東西全部copy到模型的資料夾,上面的範例就是放到 NousResearch/Llama-2-7b-hf 資料夾底下。

3. 接下來就直接使用llama.cpp/convert.py進行轉檔即可。


ref:

https://huggingface.co/NousResearch/Nous-Hermes-Llama2-13b/discussions/1
https://github.com/ggerganov/llama.cpp/discussions/2948

2024年1月8日 星期一

Github 進行 gpg signature verification

問題描述

每次commit 都會透過gpg驗證簽名。linux上的gpg工具已經很完整了,但是windows上的gpg工具不太完整,需要額外設定。

現在設定git已經安裝完畢。


作法

1. 在ubuntu上無需作業。如果是使用windows,就需要下載gpg工具: https://gnupg.org/download/ 


2. 設定windows上的gpg使用位置,位置需要修改到gpg安裝的位置:

 git config --global gpg.program "C:\Program Files (x86)\GnuPG\bin\gpg.exe"


3. 製作gpg key:

gpg --full-generate-key

裡面會有很多問答,就注意name跟email要跟github上面的帳號符合就可以了。


4. 把gpg public key放到github上。先看看gpg的資訊:

$ gpg --list-secret-keys --keyid-format=long

/Users/hubot/.gnupg/secring.gpg

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

sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]

uid                          Hubot <hubot@example.com>

ssb   4096R/4BB6D45482678BE3 2016-03-10


上面顯示的結果是key ID為3AA5C34371567BD2的gpg。接下來就列出該gpg的public key:

gpg --armor --export 3AA5C34371567BD2

這邊會產生以 -----BEGIN PGP PUBLIC KEY BLOCK----- 並以 ---END PGP PUBLIC KEY BLOCK----- 結尾的字串。整段貼到github上:

settings > ssh and gpg keys > gpg keys > new gpg key 

( 可參考: https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account )


到這邊,github端就設定完成。


5. client端首先要進行gpg key unset。git看起來有"預設"模式,如果加密的長度跟加密方法跟預設不同就有可能無法讀取。所以最好就重跑一次unset:

git config --global --unset gpg.format

接下來把設定git會使用的gpg key,後面的ID取法就跟上面透過gpg --list-secret-keys --keyid-format=long指令取得的結果一樣,依照上面的例子就是:

git config --global user.signingkey 3AA5C34371567BD2


6. 設定每次都認證:

git config --global commit.gpgsign true


Ref:

https://stackoverflow.com/questions/36810467/git-commit-signing-failed-secret-key-not-available

https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key

https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key

讓putty使用windows ssh建立的key進行遠端連線

 情境

1. windows可以透過內建的ssh建立credential,但是格式跟putty的不太一樣

2.不想要產生太多private key,讓putty可以使用windows ssh建立出來的private key進行認證


作法

1. 安裝putty,打開puttygen。假設目前已經都用windows ssh把key產生出來(作法可參閱參考資料1.)

2. 第二個column (Actions)的第二個選項"load an existing private key file",點下"Load"按鈕。找到pub檔。但預設就是找ppk,所以要自行把搜尋檔案的選項改為 *.*。.pub的位置大概是在: C:\Users\<USERNAME>\.ssh\id_rsa

3. 點下Save private key按鈕,將檔名存成自己喜歡的檔名。

4. 依照免密碼登錄的方式,把windows open ssh的public key存放到Server端。將putty打開,把server資訊load進後,到: SSH >Auth>Credential。把private key file for authentication的位置輸入方才產生的檔案。然後回到Session中Save。


Refs:
1. https://learn.microsoft.com/zh-tw/windows-server/administration/openssh/openssh_keymanagement
2. https://gcore.com/docs/cloud/ssh-keys/convert-an-ssh-key-from-pem-to-ppk





2024年1月5日 星期五

透過linux指令確認DNS text


到DNS server設定好text屬性後,


1.使用dig指令:

dig yourdomainname.com TXT

  只要文字的話:

dig +short -t txt yourdomainname.com 


2.使用host指令:

host -t txt yourdomainname.com



ref:

https://www.servercake.blog/check-txt-record-linux-terminal/

iscsi 連線問題筆記

如果要進行umount但是出現target buzy sudo fuser -km 掛載點 sudo umount 掛載點 iSCSI重啟 sudo open-iscsi restart  掛載lun iscsiadm -m discovery -t sendtargets -p...