diff --git a/cann/7.0.RC1.alpha002/22.03-lts-sp2/Dockerfile b/cann/7.0.RC1.alpha002/22.03-lts-sp2/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..8650c5c47071d8f0d54abb548d15df81165bead4 --- /dev/null +++ b/cann/7.0.RC1.alpha002/22.03-lts-sp2/Dockerfile @@ -0,0 +1,41 @@ +FROM openeuler/openeuler:22.03-lts-sp2 + +ARG CANN_TOOLKIT_URL=https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C13SPC702/Ascend-cann-toolkit_7.0.RC1.alpha002_linux-aarch64.run +ARG CANN_KERNELS_URL=https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/Milan-ASL/Milan-ASL%20V100R001C13SPC702/Ascend-cann-kernels-910b_7.0.RC1.alpha002_linux.run + + +ENV ASCEND_TOOLKIT_HOME=/usr/local/Ascend/ascend-toolkit/latest +ENV LD_LIBRARY_PATH=${ASCEND_TOOLKIT_HOME}/lib64:${ASCEND_TOOLKIT_HOME}/lib64/plugin/opskernel:${ASCEND_TOOLKIT_HOME}/lib64/plugin/nnengine:${ASCEND_TOOLKIT_HOME}/opp/built-in/op_impl/ai_core/tbe/op_tiling:$LD_LIBRARY_PATH +ENV LD_LIBRARY_PATH=/usr/local/Ascend/driver/lib64/common/:/usr/local/Ascend/driver/lib64/driver/:$LD_LIBRARY_PATH +ENV PYTHONPATH=${ASCEND_TOOLKIT_HOME}/python/site-packages:${ASCEND_TOOLKIT_HOME}/opp/built-in/op_impl/ai_core/tbe:$PYTHONPATH +ENV PATH=${ASCEND_TOOLKIT_HOME}/bin:${ASCEND_TOOLKIT_HOME}/compiler/ccec_compiler/bin:$PATH +ENV PATH=/usr/local/miniconda/envs/torch_npu/bin/:/usr/local/miniconda/bin:$PATH +ENV ASCEND_AICPU_PATH=${ASCEND_TOOLKIT_HOME} +ENV ASCEND_OPP_PATH=${ASCEND_TOOLKIT_HOME}/opp +ENV TOOLCHAIN_HOME=${ASCEND_TOOLKIT_HOME}/toolkit +ENV ASCEND_HOME_PATH=${ASCEND_TOOLKIT_HOME} + +RUN yum install -y git wget gcc gcc-c++ make cmake unzip zlib-devel libffi-devel openssl-devel pciutils net-tools sqlite-devel lapack-devel gcc-gfortran python3-devel util-linux patchelf && \ + yum clean all && \ + rm -rf /var/cache/yum + +RUN wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-aarch64.sh -O ~/miniconda.sh && \ + bash ~/miniconda.sh -b -p /usr/local/miniconda && \ + rm -f ~/miniconda.sh + +RUN /usr/local/miniconda/bin/conda init bash && \ + /usr/local/miniconda/bin/conda create --name torch_npu -y python=3.8.11 + +RUN source /root/.bashrc && conda activate torch_npu && \ + pip3 install attrs decorator psutil numpy absl-py cloudpickle scipy synr==0.5.0 protobuf==3.19.0 tornado -i https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip3 cache purge + +RUN wget ${CANN_TOOLKIT_URL} -O ~/Ascend-cann-toolkit.run && \ + chmod +x ~/Ascend-cann-toolkit.run && \ + printf "Y\n" | ~/Ascend-cann-toolkit.run --install && \ + rm -f ~/Ascend-cann-toolkit.run + +RUN wget ${CANN_KERNELS_URL} -O ~/Ascend-cann-kernels.run && \ + chmod +x ~/Ascend-cann-kernels.run && \ + printf "Y\n" | ~/Ascend-cann-kernels.run --install && \ + rm -f ~/Ascend-cann-kernels.run \ No newline at end of file diff --git a/cann/README.md b/cann/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8eaa79d154750d95fa0bd95a56c6b1841ff634ad --- /dev/null +++ b/cann/README.md @@ -0,0 +1,31 @@ +# cann + +# Quick reference + +- The official cann docker image. + +- Maintained by: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative) + +- Where to get help: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative), [openEuler](https://gitee.com/openeuler/community) + +# Build reference + +1. Build images and push: +```shell +docker buildx build -t "openeuler/cann:$TAG" --platform linux/arm64 ./$TAG --push +``` + +We are using `buildx` in here to generate ARM64 images on different host, see more in [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/) + +# How to use this image +Please run container with this image on Ascend platform of ARM64. +```shell +docker run --device $DEVICE --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /usr/local/dcmi:/usr/local/dcmi -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi -v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ -v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info -it openeuler/cann:$TAG +``` + +# Supported tags and respective Dockerfile links + +- cann7.0.RC1.alpha002-oe2203sp2 + +## Operating System +Linux/Unix, ARM64 architecture. diff --git a/cann/meta.yml b/cann/meta.yml new file mode 100644 index 0000000000000000000000000000000000000000..43451cba784d632c455a16adf7f99e66cb3a5771 --- /dev/null +++ b/cann/meta.yml @@ -0,0 +1,4 @@ +# key为镜像的tag,value为构建对应tag镜像的Dockerfile保存路径 + +cann7.0.RC1.alpha002-oe2203sp2: + - cann/7.0.RC1.alpha002/22.03-lts-sp2/Dockerfile diff --git a/llm/README.md b/llm/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a01ea1598dba5235347188ad1c21e6b51c52b6c9 --- /dev/null +++ b/llm/README.md @@ -0,0 +1,32 @@ +# llm + +# Quick reference + +- The official llm docker image. + +- Maintained by: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative) + +- Where to get help: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative), [openEuler](https://gitee.com/openeuler/community) + +# Build reference + +1. Build images and push: +```shell +docker buildx build -t "openeuler/llm:$TAG" --platform linux/arm64 ./$TAG --push +``` + +We are using `buildx` in here to generate ARM64 images on different host, see more in [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/). Note that you may need to configure the proxy for cloning LLMs from huggingface while building. + +# How to use this image +Please run container with this image on Ascend platform of ARM64. +```shell +docker run --device $DEVICE --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /usr/local/dcmi:/usr/local/dcmi -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi -v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ -v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info -it openeuler/llm:$TAG +``` + +# Supported tags and respective Dockerfile links + +- chatglm2_6b-pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2 +- fastchat-pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2 + +## Operating System +Linux/Unix, ARM64 architecture. diff --git a/llm/chatglm2_6b/22.03-lts-sp2/Dockerfile b/llm/chatglm2_6b/22.03-lts-sp2/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c8b443f65283f80666bc551b1d588df859057c41 --- /dev/null +++ b/llm/chatglm2_6b/22.03-lts-sp2/Dockerfile @@ -0,0 +1,8 @@ +FROM openeuler/llm:fastchat-pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2 + +COPY chatglm2-6b.patch ./ +COPY chatglm_inference.sh chatglm_finetune.sh stop_inference.sh /demo/ +RUN chmod +x /demo/*.sh && \ + git clone https://huggingface.co/THUDM/chatglm2-6b && \ + cd chatglm2-6b && \ + git apply ../chatglm2-6b.patch \ No newline at end of file diff --git a/llm/chatglm2_6b/22.03-lts-sp2/chatglm2-6b.patch b/llm/chatglm2_6b/22.03-lts-sp2/chatglm2-6b.patch new file mode 100644 index 0000000000000000000000000000000000000000..c1fb616202007f630732622438d574a5e77d0c73 --- /dev/null +++ b/llm/chatglm2_6b/22.03-lts-sp2/chatglm2-6b.patch @@ -0,0 +1,62 @@ +diff --git a/modeling_chatglm.py b/modeling_chatglm.py +index d3fb395..41e8fb5 100644 +--- a/modeling_chatglm.py ++++ b/modeling_chatglm.py +@@ -29,11 +29,11 @@ from .configuration_chatglm import ChatGLMConfig + + # flags required to enable jit fusion kernels + +-if sys.platform != 'darwin': +- torch._C._jit_set_profiling_mode(False) +- torch._C._jit_set_profiling_executor(False) +- torch._C._jit_override_can_fuse_on_cpu(True) +- torch._C._jit_override_can_fuse_on_gpu(True) ++#if sys.platform != 'darwin': ++# torch._C._jit_set_profiling_mode(False) ++# torch._C._jit_set_profiling_executor(False) ++# torch._C._jit_override_can_fuse_on_cpu(True) ++# torch._C._jit_override_can_fuse_on_gpu(True) + + logger = logging.get_logger(__name__) + +@@ -815,7 +815,9 @@ class ChatGLMModel(ChatGLMPreTrainedModel): + attention_mask], dim=-1) + + if full_attention_mask is None: +- if (attention_mask is not None and not attention_mask.all()) or (past_key_values and seq_length != 1): ++ #print(attention_mask.dtype, attention_mask,type) ++ #if (attention_mask is not None and not attention_mask.all()) or (past_key_values and seq_length != 1): ++ if (attention_mask is not None and not attention_mask.bool().all()) or (past_key_values and seq_length != 1): + full_attention_mask = self.get_masks(input_ids, past_key_values, padding_mask=attention_mask) + + # Rotary positional embeddings +@@ -1019,7 +1021,8 @@ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel): + inputs = inputs.to(self.device) + return inputs + +- @torch.inference_mode() ++ #@torch.inference_mode() ++ @torch.no_grad() + def chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, max_length: int = 8192, num_beams=1, + do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, **kwargs): + if history is None: +@@ -1037,7 +1040,8 @@ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel): + history = history + [(query, response)] + return response, history + +- @torch.inference_mode() ++ #@torch.inference_mode() ++ @torch.no_grad() + def stream_chat(self, tokenizer, query: str, history: List[Tuple[str, str]] = None, past_key_values=None, + max_length: int = 8192, do_sample=True, top_p=0.8, temperature=0.8, logits_processor=None, + return_past_key_values=False, **kwargs): +@@ -1074,7 +1078,8 @@ class ChatGLMForConditionalGeneration(ChatGLMPreTrainedModel): + else: + yield response, new_history + +- @torch.inference_mode() ++ #@torch.inference_mode() ++ @torch.no_grad() + def stream_generate( + self, + input_ids, diff --git a/llm/chatglm2_6b/22.03-lts-sp2/chatglm_finetune.sh b/llm/chatglm2_6b/22.03-lts-sp2/chatglm_finetune.sh new file mode 100644 index 0000000000000000000000000000000000000000..b76c8c69349c38a1cfc6b3ba4c1e27bee5257dcf --- /dev/null +++ b/llm/chatglm2_6b/22.03-lts-sp2/chatglm_finetune.sh @@ -0,0 +1,30 @@ +#!/bin/bash +ports=("21001" "21002" "7860") +for port in "${ports[@]}" +do + info=$(netstat -tunpl | grep ":$port ") + pid=$(echo "$info" | awk '{print $7}' | awk -F'/' '{print $1}') + if [[ -n "$pid" ]]; then + kill "$pid" + fi +done +torchrun --nproc_per_node=4 --master_port=20001 /FastChat/fastchat/train/train.py \ + --model_name_or_path /chatglm2-6b \ + --data_path /demo/openeuler-finetune.json \ + --fp16 True \ + --output_dir output_chatglm \ + --num_train_epochs 5 \ + --per_device_train_batch_size 8 \ + --per_device_eval_batch_size 1 \ + --gradient_accumulation_steps 1 \ + --evaluation_strategy "no" \ + --save_strategy "epoch" \ + --learning_rate 5e-5 \ + --weight_decay 0. \ + --lr_scheduler_type "cosine" \ + --logging_steps 1 \ + --fsdp "full_shard auto_wrap" \ + --model_max_length 512 \ + --gradient_checkpointing True \ + --lazy_preprocess True \ + --trust_remote_code True diff --git a/llm/chatglm2_6b/22.03-lts-sp2/chatglm_inference.sh b/llm/chatglm2_6b/22.03-lts-sp2/chatglm_inference.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f7c52be1ad8f6d1e1dee71940bbf6af1251dfbc --- /dev/null +++ b/llm/chatglm2_6b/22.03-lts-sp2/chatglm_inference.sh @@ -0,0 +1,18 @@ +#!/bin/bash +source activate torch_npu +ports=("21001" "21002" "7860") +for port in "${ports[@]}" +do + info=$(netstat -tunpl | grep ":$port ") + pid=$(echo "$info" | awk '{print $7}' | awk -F'/' '{print $1}') + if [[ -n "$pid" ]]; then + kill "$pid" + fi +done + +cd /FastChat +python -m fastchat.serve.controller --host 0.0.0.0 & +sleep 3 +python -m fastchat.serve.model_worker --model-path /chatglm2-6b/ --device npu --host 0.0.0.0 & +sleep 65 +python -m fastchat.serve.gradio_web_server --host 0.0.0.0 & diff --git a/llm/chatglm2_6b/22.03-lts-sp2/stop_inference.sh b/llm/chatglm2_6b/22.03-lts-sp2/stop_inference.sh new file mode 100644 index 0000000000000000000000000000000000000000..539ad265c866f637fa83f81c2741d5d4df24019e --- /dev/null +++ b/llm/chatglm2_6b/22.03-lts-sp2/stop_inference.sh @@ -0,0 +1,10 @@ +#!/bin/bash +ports=("21001" "21002" "7860") +for port in "${ports[@]}" +do + info=$(netstat -tunpl | grep ":$port ") + pid=$(echo "$info" | awk '{print $7}' | awk -F'/' '{print $1}') + if [[ -n "$pid" ]]; then + kill "$pid" + fi +done diff --git a/llm/fastchat/22.03-lts-sp2/Dockerfile b/llm/fastchat/22.03-lts-sp2/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..e2ed4e190fa27b994ada2c1e9a7f6d241b85e6a1 --- /dev/null +++ b/llm/fastchat/22.03-lts-sp2/Dockerfile @@ -0,0 +1,10 @@ +FROM openeuler/pytorch:pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2 + +COPY fastchat.patch ./ +RUN git clone https://github.com/lm-sys/FastChat.git && \ + cd FastChat && \ + git apply ../fastchat.patch && \ + pip install -e ".[model_worker,webui]" -i https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip install --no-cache-dir transformers==4.32.1 -i https://pypi.tuna.tsinghua.edu.cn/simple && \ + pip install --no-cache-dir accelerate==0.22.0 -i https://pypi.tuna.tsinghua.edu.cn/simple && \ + rm -rf ../fastchat.patch \ No newline at end of file diff --git a/llm/fastchat/22.03-lts-sp2/fastchat.patch b/llm/fastchat/22.03-lts-sp2/fastchat.patch new file mode 100644 index 0000000000000000000000000000000000000000..d9d1af5c842c7cb8088de45bc6e2fe968ef3de33 --- /dev/null +++ b/llm/fastchat/22.03-lts-sp2/fastchat.patch @@ -0,0 +1,27 @@ +diff --git a/fastchat/model/model_chatglm.py b/fastchat/model/model_chatglm.py +index 5d4db62..07d6425 100644 +--- a/fastchat/model/model_chatglm.py ++++ b/fastchat/model/model_chatglm.py +@@ -37,7 +37,8 @@ def process_response(response): + return response + + +-@torch.inference_mode() ++#@torch.inference_mode() ++@torch.no_grad() + def generate_stream_chatglm( + model, + tokenizer, +diff --git a/fastchat/serve/model_worker.py b/fastchat/serve/model_worker.py +index 5e84a42..098c991 100644 +--- a/fastchat/serve/model_worker.py ++++ b/fastchat/serve/model_worker.py +@@ -101,6 +101,8 @@ class ModelWorker(BaseModelWorker): + self.init_heart_beat() + + def generate_stream_gate(self, params): ++ import torch_npu ++ torch_npu.npu.set_device("npu:0") + self.call_ct += 1 + + try: \ No newline at end of file diff --git a/llm/meta.yml b/llm/meta.yml new file mode 100644 index 0000000000000000000000000000000000000000..7cef3906033c256641ce309b65768447e8efb712 --- /dev/null +++ b/llm/meta.yml @@ -0,0 +1,7 @@ +# key为镜像的tag,value为构建对应tag镜像的Dockerfile保存路径 + +fastchat-pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2: + - llm/fastchat/22.03-lts-sp2/Dockerfile + +chatglm2_6b-pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2: + - llm/chatglm2_6b/22.03-lts-sp2/Dockerfile \ No newline at end of file diff --git a/pytorch/2.1.0.a1/22.03-lts-sp2/Dockerfile b/pytorch/2.1.0.a1/22.03-lts-sp2/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..2b8ea03b1f9d61b9f7e05cff04b920090f68770f --- /dev/null +++ b/pytorch/2.1.0.a1/22.03-lts-sp2/Dockerfile @@ -0,0 +1,36 @@ +FROM openeuler/cann:cann7.0.RC1.alpha002-oe2203sp2 + +# Install requirements +RUN pip install --no-cache-dir -i https://repo.huaweicloud.com/repository/pypi/simple \ + cmake \ + ninja \ + protobuf==3.20.0 \ + attrs \ + cython \ + numpy \ + decorator \ + sympy \ + cffi \ + pyyaml \ + pathlib2 \ + psutil \ + scipy \ + requests \ + absl-py \ + prompt_toolkit + +RUN git clone https://github.com/pytorch/pytorch.git && \ + cd pytorch && \ + git reset 5913437a40a6e45ab7e164afb7c6ec930dd40b2f --hard && \ + pip install --no-cache-dir -r ./requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple && \ + export USE_CUDA=0 && \ + export USE_XNNPACK=0 && \ + python3 setup.py develop + +RUN git clone https://github.com/ascend/pytorch.git ascend-pytorch && \ + cd ascend-pytorch && \ + git reset 81ece7b664adc28e698044d0e9091d39a1a6dfa6 --hard && \ + pip install --no-cache-dir pyyaml wheel decorator snippy && \ + bash ci/build.sh --python=3.8 && \ + pip3 install --upgrade dist/torch_npu-2.1.0-cp38-cp38-linux_aarch64.whl && \ + rm -rf ../ascend-pytorch \ No newline at end of file diff --git a/pytorch/README.md b/pytorch/README.md new file mode 100644 index 0000000000000000000000000000000000000000..71108f52ae7d74ad234f3cd1741c0764aae93a59 --- /dev/null +++ b/pytorch/README.md @@ -0,0 +1,31 @@ +# pytorch + +# Quick reference + +- The official pytorch docker image. + +- Maintained by: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative) + +- Where to get help: [openEuler CloudNative SIG](https://gitee.com/openeuler/cloudnative), [openEuler](https://gitee.com/openeuler/community) + +# Build reference + +1. Build images and push: +```shell +docker buildx build -t "openeuler/pytorch:$TAG" --platform linux/arm64 ./$TAG --push +``` + +We are using `buildx` in here to generate ARM64 images on different host, see more in [Docker Buildx](https://docs.docker.com/buildx/working-with-buildx/) + +# How to use this image +Please run container with this image on Ascend platform of ARM64. +```shell +docker run --device $DEVICE --device /dev/davinci_manager --device /dev/devmm_svm --device /dev/hisi_hdc -v /usr/local/dcmi:/usr/local/dcmi -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi -v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ -v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info -it openeuler/pytorch:$TAG +``` + +# Supported tags and respective Dockerfile links + +- pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2 + +## Operating System +Linux/Unix, ARM64 architecture. diff --git a/pytorch/meta.yml b/pytorch/meta.yml new file mode 100644 index 0000000000000000000000000000000000000000..406ad779a21ac4c04a8c073dd18407c432957564 --- /dev/null +++ b/pytorch/meta.yml @@ -0,0 +1,4 @@ +# key为镜像的tag,value为构建对应tag镜像的Dockerfile保存路径 + +pytorch2.1.0.a1-cann7.0.RC1.alpha002-oe2203sp2: + - pytorch/2.1.0.a1/22.03-lts-sp2/Dockerfile