paulwong

2024年6月29日 #

国内网络环境安装docker+container toolkit

操作系统为centos 9.

先安装驱动程序

https://www.nvidia.cn/drivers/lookup/ 中查找对应的驱动程序下载到本地,再运行
#切换成文字界面
sudo systemctl set-default multi-user.target
sudo reboot

sh NVIDIA
-Linux-x86_64-550.107.02.run

#切换成图形界面
sudo systemctl set-default graphical.target
sudo reboot

安装docker:

yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

yum install -y yum-utils
yum-config-manager --add-repo https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
sed -i 's+https://download.docker.com+https://mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

sudo nvidia-ctk runtime configure --runtime=docker

改镜像地址:

[paul@paul-pc ~]$ cat /etc/docker/daemon.json
{  
    
"registry-mirrors"[
        "http://xxx.xxx.xxx"
    ]
,
    
"runtimes": {
        
"nvidia": {
            
"args"[],
            
"path""nvidia-container-runtime"
        }
    }
}

安装container-took-kit:

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Rocky&target_version=9&target_type=runfile_local 中找到对应的container-took-kit,下载到本地,再运行
sh cuda_12.6.0_560.28.03_linux.run

验证:

sudo docker run --rm -it --gpus all ubuntu  nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.107.02             Driver Version: 550.107.02     CUDA Version: 12.4     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 2080 Ti     Off |   00000000:01:00.0  On |                  N/A |
| 62%   36C    P8              4W /  260W |     256MiB /  22528MiB |      1%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
|   1  NVIDIA GeForce RTX 2080 Ti     Off |   00000000:02:00.0 Off |                  N/A |
| 64%   35C    P8              5W /  260W |       9MiB /  22528MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+
                                                                                         
+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      2657      G   /usr/libexec/Xorg                              99MiB |
|    0   N/A  N/A      2735      G   /usr/bin/gnome-shell                           38MiB |
|    0   N/A  N/A      3502      G   /usr/lib64/firefox/firefox                    111MiB |
|    1   N/A  N/A      2657      G   /usr/libexec/Xorg                               4MiB |
+-----------------------------------------------------------------------------------------+
参考地址:
https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

posted @ 2024-08-15 10:49 paulwong 阅读(63) | 评论 (0)编辑 收藏

python界面库

python服务器脚本,生成html,无需写js,css,适合AI项目
https://cheat-sheet.streamlit.app

生成文字的代码:
st.text('Fixed width text')
st.markdown('_Markdown_'# see #*
st.caption('Balloons. Hundreds of them')
st.latex(r''' e^{i\pi} + 1 = 0 ''')
st.write('Most objects'# df, err, func, keras!
st.write(['st''is <', 3]) # see *
st.title('My title')
st.header('My header')
st.subheader('My sub')
st.code('for i in range(8): foo()')

# * optional kwarg unsafe_allow_html = True

生成form控件:
st.button('Hit me')
st.data_editor('Edit data', data)
st.checkbox('Check me out')
st.radio('Pick one:', ['nose','ear'])
st.selectbox('Select', [1,2,3])
st.multiselect('Multiselect', [1,2,3])
st.slider('Slide me', min_value=0, max_value=10)
st.select_slider('Slide to select', options=[1,'2'])
st.text_input('Enter some text')
st.number_input('Enter a number')
st.text_area('Area for textual entry')
st.date_input('Date input')
st.time_input('Time entry')
st.file_uploader('File uploader')
st.download_button('On the dl', data)
st.camera_input("一二三,茄子!")
st.color_picker('Pick a color')

用表格显示数据:
st.dataframe(my_dataframe)
st.table(data.iloc[0:10])
st.json({'foo':'bar','fu':'ba'})
st.metric(label="Temp", value="273 K", delta="1.2 K")


显示加载进度条与状态:
# Show a spinner during a process
>>> with st.spinner(text='In progress'):
>>>   time.sleep(3)
>>>   st.success('Done')

# Show and update progress bar
>>> bar = st.progress(50)
>>> time.sleep(3)
>>> bar.progress(100)

st.balloons()
st.snow()
st.toast('Mr Stay-Puft')
st.error('Error message')
st.warning('Warning message')
st.info('Info message')
st.success('Success message')
st.exception(e)


posted @ 2024-08-12 15:19 paulwong 阅读(52) | 评论 (0)编辑 收藏

通过SSH的方式PUSH代码到GIT

这几天要PUSH代码到GITHUB,发现之前用的密码方式被取消了,需改成SSH KEY的方式。

1.生成SSH-KEY

ssh-keygen
#会产生 
~/.ssh/id_rsa 和 ~/.ssh/id_rsa_pub 文件
#如果是从别的地方拷贝过来的id_rsa,需chmod 400 ~/.ssh/id_rsa更改属性

2.在github上新建仓库

https://github.com/paulwong888/python-ai

3.导入公钥到github

打开你的SSH公钥文件,通常位于~/.ssh/id_rsa.pub。复制公钥内容,然后登录到你的GitHub账户,进入Settings > SSH and GPG keys,点击"New SSH key"按钮,粘贴你的公钥,然后点击"Add SSH key"。

4.克隆仓库

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
git clone git@github.com:paulwong888/python-ai

5.导入project到eclipse

上步克隆时已经在本地新建了一个本地仓库,Import->Git->Project from Git->Existing local repository,选择python-ai/.git文件夹
之后的操作和用密码的方式是一样的。

如果是vs code的操作,可参考:https://juejin.cn/post/6993612656410099719

posted @ 2024-07-24 12:31 paulwong 阅读(95) | 评论 (0)编辑 收藏

微调llama3大模型(2) - 使用ollama搭建chatbot

上篇已经合并出了训练好的大模型,现在要搭建起一套CHATBOT,使得这套大模型能有一个WEBUI用起来。

1.设置环境变量,ollama的模型保存路径,/etc/profile

export OLLAMA_MODELS=/root/autodl-tmp/models/ollama

2.克隆ollama代码

curl -fsSL https://ollama.com/install.sh | sh

3.启动ollama

ollama serve

4.建立ollama镜像的配置文件,Modelfile

# set the base model
FROM /root/.ollama/llamafactory-export/saves/llama3-8b/lora/docker-commnad-nlp/export

# set custom parameter values
PARAMETER temperature 
1
PARAMETER num_keep 
24
PARAMETER stop <|start_header_id|>
PARAMETER stop <|end_header_id|>
PARAMETER stop <|eot_id|>
PARAMETER stop <|reserved_special_token

# set the model template
TEMPLATE 
"""
{{ if .System }}<|start_header_id|>system<|end_header_id|>
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
{{ .Response }}<|eot_id|>
"""

# set the system message
SYSTEM You are llama3 from Meta
, customized and hosted @ Paul Wong (http://paulwong88.tpddns.cn).

# set Chinese lora support
#ADAPTER /root/.ollama/models/lora/ggml-adapter-model.bin
建立镜像命令,create-ollama-image-docker-command-nlp.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
ollama create llama3-docker-commnad-nlp:paul -f Modelfile

5.运行大模型

llama3-docker-commnad-nlp:paul

posted @ 2024-07-08 19:48 paulwong 阅读(77) | 评论 (0)编辑 收藏

微调llama3大模型(1) - 使用Llama Factory微调llama3大模型

对于象META的开源大模型,如llama3,由于都是用通用数据进行预训练,对想使用其模型的公司来说,可能会不适用,因为这大模型对公司的数据不熟悉,因此引入微调(Fine-Tunning)。
通过喂给大模型大量数据,1万条起步,使得大模型也能对公司的数据熟悉,进而用于各种对话场景。

1.克隆并安装LLAMA FACTORY库,install-llamafactory.sh

BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/../
pwd
git clone --depth 
1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e 
".[torch,metrics,bitsandbytes,modelscope]"

2.设置环境变量

export USE_MODELSCOPE_HUB=1 #使用modelscop模型库,非huggingface的
export CUDA_VISIBLE_DEVICES
=0 #设置使用GPU
export HF_ENDPOINT
=https://hf-mirror.com #设置huggingface的替代地址
export MODELSCOPE_CACHE
=/root/autodl-tmp/models/modelscope #设置modelscope中的大模型保存路径
export LLAMAFACTORY_HOME=/root/autodl-tmp/LLaMA-Factory

3.准备数据

#在data/dataset_info.json中加入此数据

"docker_command_NL": {
    
"hf_hub_url""MattCoddity/dockerNLcommands"
  }
,
在data目录中加入训练数据,MattCoddity/dockerNLcommands.json
数据格式为:
[
  {
    
"input""Give me a list of containers that have the Ubuntu image as their ancestor.",
    
"instruction""translate this sentence in docker command",
    
"output""docker ps --filter 'ancestor=ubuntu'"
  }
,

]

4.训练大模型

训练的参数文件:llama3_lora_sft_docker_command.yaml
### model
#md model id
model_name_or_path: LLM-Research/Meta-Llama-
3-8B-Instruct
#huggingface model id
#model_name_or_path: meta-llama/Meta-Llama-
3-8B-Instruct

### method
stage: sft
do_train: true
finetuning_type: lora
lora_target: all

### dataset
dataset: docker_command_NL
template: llama3
cutoff_len: 
1024
max_samples: 
1000
overwrite_cache: true
preprocessing_num_workers: 
16

### output
output_dir: /root/autodl-tmp/my-test/saves/llama3-8b/lora/sft/docker-commnad-nlp/sft
logging_steps: 
10
save_steps: 
500
plot_loss: true
overwrite_output_dir: true

### train
per_device_train_batch_size: 
4
gradient_accumulation_steps: 
8
learning_rate: 
1.0e-4
num_train_epochs: 
3.0
lr_scheduler_type: cosine
warmup_ratio: 
0.1
bf16: true
ddp_timeout: 
180000000

### eval
val_size: 
0.1
per_device_eval_batch_size: 
1
eval_strategy: steps
eval_steps: 
500
训练命令:lora-train-docker-command.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
cd $LLAMAFACTORY_HOME
pwd
llamafactory-cli train $BIN_PATH/conf/llama3_lora_sft_docker_command.yaml
执行此命令即可开始训练大模型。

5.合并大模型

合并用的参数文件,llama3_lora_export_docker_command.yaml
### model
#md model id
model_name_or_path: LLM-Research/Meta-Llama-
3-8B-Instruct
#huggingface model id
#model_name_or_path: meta-llama/Meta-Llama-
3-8B-Instruct

adapter_name_or_path: /root/autodl-tmp/my-test/saves/llama3-8b/lora/docker-commnad-nlp/sft
template: llama3
export_dir: /root/autodl-tmp/my-test/saves/llama3-8b/lora/docker-commnad-nlp/export
finetuning_type: lora
export_size: 
2
export_device: gpu
export_legacy_format: False
合并命令,lora-export-docker-command.sh
BIN_PATH=$(cd `dirname $0`; pwd)
cd $BIN_PATH/
pwd
llamafactory-cli export conf/llama3_lora_export_docker_command.yaml

posted @ 2024-07-08 18:44 paulwong 阅读(85) | 评论 (0)编辑 收藏

STABLE DIFFUSION(1) - CONTROLNET

CONTROLNET是STABLE DIFFUSION中的一个插件,允许用户指定某张图片上的特征,然后将这些特征应用到新生成的图片上。
特征可以是图片上某人物的姿势,景深等。
其中一些实用的CONTROL TYPE:
1,LINER
STABLE DIFFUSION实现过程,其实就是先生成样图的线稿图,然后再上色。
2,TITLE
STABLE DIFFUSION会根据提供图片的骨架,再生成新的内容
3,SCRIBBLE
通常用于产品工业设计,先画出线稿,STABLE DIFFUSION会根据线稿,再根据提示词内容生成图片

posted @ 2024-06-30 00:38 paulwong 阅读(24) | 评论 (0)编辑 收藏

STABLE DIFFUSION(3) - 面部修复和高清修复

通常面部修复和高清修复要一起搭配使用才好使。

posted @ 2024-06-30 00:04 paulwong 阅读(65) | 评论 (0)编辑 收藏

STABLE DIFFUSION(2) - 采样方法

采样步数越高,则画质超高。一般取值为20,高于20,画质和20的差不多。
采样一般就用EULER A这种。

posted @ 2024-06-29 23:26 paulwong 阅读(46) | 评论 (0)编辑 收藏

STABLE DIFFUSION(1) - 提示词

提示如果不被模型认识,则不会起效果。
如果提示词太多,则排在后面的提示词会被忽略。
越靠前的词,越会被注意。
同类型的提示词之间会被污染。
反向提示词写几个就足够,如nsfw,low quality, lowres,写多反而会被忽略
一层小括号里面的提示词会加权重成1.1倍,两层则是1.21倍。
一层中括号里面的提示词会加权重成0.9倍,两层则是0.81倍。
[super man|iron man]则生成的主题会融合两种特征。

posted @ 2024-06-29 23:18 paulwong 阅读(60) | 评论 (0)编辑 收藏