From 1cd162ed4fb5c54ea5cd8e3d220b2e6a5c31946d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:45:30 +0000 Subject: [PATCH 01/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/LICENSE-CODE | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE new file mode 100644 index 0000000000..6eca5dda82 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 DeepSeek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. -- Gitee From ca4488e9bf7f4b9268b4c63a3d44dbb163f9fa80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:46:29 +0000 Subject: [PATCH 02/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/ LICENSE-MODEL. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/ LICENSE-MODEL | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/ LICENSE-MODEL diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ LICENSE-MODEL b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ LICENSE-MODEL new file mode 100644 index 0000000000..8072f462d2 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ LICENSE-MODEL @@ -0,0 +1,91 @@ +DEEPSEEK LICENSE AGREEMENT + +Version 1.0, 23 October 2023 + +Copyright (c) 2023 DeepSeek + +Section I: PREAMBLE + +Large generative models are being widely adopted and used, and have the potential to transform the way individuals conceive and benefit from AI or ML technologies. + +Notwithstanding the current and potential benefits that these artifacts can bring to society at large, there are also concerns about potential misuses of them, either due to their technical limitations or ethical considerations. + +In short, this license strives for both the open and responsible downstream use of the accompanying model. When it comes to the open character, we took inspiration from open source permissive licenses regarding the grant of IP rights. Referring to the downstream responsible use, we added use-based restrictions not permitting the use of the model in very specific scenarios, in order for the licensor to be able to enforce the license in case potential misuses of the Model may occur. At the same time, we strive to promote open and responsible research on generative models for content generation. + +Even though downstream derivative versions of the model could be released under different licensing terms, the latter will always have to include - at minimum - the same use-based restrictions as the ones in the original license (this license). We believe in the intersection between open and responsible AI development; thus, this agreement aims to strike a balance between both in order to enable responsible open-science in the field of AI. + +This License governs the use of the model (and its derivatives) and is informed by the model card associated with the model. + +NOW THEREFORE, You and DeepSeek agree as follows: + +1. Definitions +"License" means the terms and conditions for use, reproduction, and Distribution as defined in this document. +"Data" means a collection of information and/or content extracted from the dataset used with the Model, including to train, pretrain, or otherwise evaluate the Model. The Data is not licensed under this License. +"Output" means the results of operating a Model as embodied in informational content resulting therefrom. +"Model" means any accompanying machine-learning based assemblies (including checkpoints), consisting of learnt weights, parameters (including optimizer states), corresponding to the model architecture as embodied in the Complementary Material, that have been trained or tuned, in whole or in part on the Data, using the Complementary Material. +"Derivatives of the Model" means all modifications to the Model, works based on the Model, or any other model which is created or initialized by transfer of patterns of the weights, parameters, activations or output of the Model, to the other model, in order to cause the other model to perform similarly to the Model, including - but not limited to - distillation methods entailing the use of intermediate data representations or methods based on the generation of synthetic data by the Model for training the other model. +"Complementary Material" means the accompanying source code and scripts used to define, run, load, benchmark or evaluate the Model, and used to prepare data for training or evaluation, if any. This includes any accompanying documentation, tutorials, examples, etc, if any. +"Distribution" means any transmission, reproduction, publication or other sharing of the Model or Derivatives of the Model to a third party, including providing the Model as a hosted service made available by electronic or other remote means - e.g. API-based or web access. +"DeepSeek" (or "we") means Beijing DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd., Hangzhou DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd. and/or any of their affiliates. +"You" (or "Your") means an individual or Legal Entity exercising permissions granted by this License and/or making use of the Model for whichever purpose and in any field of use, including usage of the Model in an end-use application - e.g. chatbot, translator, etc. +"Third Parties" means individuals or legal entities that are not under common control with DeepSeek or You. + +Section II: INTELLECTUAL PROPERTY RIGHTS + +Both copyright and patent grants apply to the Model, Derivatives of the Model and Complementary Material. The Model and Derivatives of the Model are subject to additional terms as described in Section III. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, DeepSeek hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare, publicly display, publicly perform, sublicense, and distribute the Complementary Material, the Model, and Derivatives of the Model. + +3. Grant of Patent License. Subject to the terms and conditions of this License and where and as applicable, DeepSeek hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this paragraph) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Model and the Complementary Material, where such license applies only to those patent claims licensable by DeepSeek that are necessarily infringed by its contribution(s). If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Model and/or Complementary Material constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for the Model and/or works shall terminate as of the date such litigation is asserted or filed. + + +Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION + +4. Distribution and Redistribution. You may host for Third Party remote access purposes (e.g. software-as-a-service), reproduce and distribute copies of the Model or Derivatives of the Model thereof in any medium, with or without modifications, provided that You meet the following conditions: +a. Use-based restrictions as referenced in paragraph 5 MUST be included as an enforceable provision by You in any type of legal agreement (e.g. a license) governing the use and/or distribution of the Model or Derivatives of the Model, and You shall give notice to subsequent users You Distribute to, that the Model or Derivatives of the Model are subject to paragraph 5. This provision does not apply to the use of Complementary Material. +b. You must give any Third Party recipients of the Model or Derivatives of the Model a copy of this License; +c. You must cause any modified files to carry prominent notices stating that You changed the files; +d. You must retain all copyright, patent, trademark, and attribution notices excluding those notices that do not pertain to any part of the Model, Derivatives of the Model. +e. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions - respecting paragraph 4.a. – for use, reproduction, or Distribution of Your modifications, or for any such Derivatives of the Model as a whole, provided Your use, reproduction, and Distribution of the Model otherwise complies with the conditions stated in this License. + +5. Use-based restrictions. The restrictions set forth in Attachment A are considered Use-based restrictions. Therefore You cannot use the Model and the Derivatives of the Model for the specified restricted uses. You may use the Model subject to this License, including only for lawful purposes and in accordance with the License. Use may include creating any content with, finetuning, updating, running, training, evaluating and/or reparametrizing the Model. You shall require all of Your users who use the Model or a Derivative of the Model to comply with the terms of this paragraph (paragraph 5). + +6. The Output You Generate. Except as set forth herein, DeepSeek claims no rights in the Output You generate using the Model. You are accountable for the Output you generate and its subsequent uses. No use of the output can contravene any provision as stated in the License. + +Section IV: OTHER PROVISIONS + +7. Updates and Runtime Restrictions. To the maximum extent permitted by law, DeepSeek reserves the right to restrict (remotely or otherwise) usage of the Model in violation of this License. + +8. Trademarks and related. Nothing in this License permits You to make use of DeepSeek’ trademarks, trade names, logos or to otherwise suggest endorsement or misrepresent the relationship between the parties; and any rights not expressly granted herein are reserved by DeepSeek. + +9. Personal information, IP rights and related. This Model may contain personal information and works with IP rights. You commit to complying with applicable laws and regulations in the handling of personal information and the use of such works. Please note that DeepSeek's license granted to you to use the Model does not imply that you have obtained a legitimate basis for processing the related information or works. As an independent personal information processor and IP rights user, you need to ensure full compliance with relevant legal and regulatory requirements when handling personal information and works with IP rights that may be contained in the Model, and are willing to assume solely any risks and consequences that may arise from that. + +10. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, DeepSeek provides the Model and the Complementary Material on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Model, Derivatives of the Model, and the Complementary Material and assume any risks associated with Your exercise of permissions under this License. + +11. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall DeepSeek be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Model and the Complementary Material (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if DeepSeek has been advised of the possibility of such damages. + +12. Accepting Warranty or Additional Liability. While redistributing the Model, Derivatives of the Model and the Complementary Material thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of DeepSeek, and only if You agree to indemnify, defend, and hold DeepSeek harmless for any liability incurred by, or claims asserted against, DeepSeek by reason of your accepting any such warranty or additional liability. + +13. If any provision of this License is held to be invalid, illegal or unenforceable, the remaining provisions shall be unaffected thereby and remain valid as if such provision had not been set forth herein. + +14. Governing Law and Jurisdiction. This agreement will be governed and construed under PRC laws without regard to choice of law principles, and the UN Convention on Contracts for the International Sale of Goods does not apply to this agreement. The courts located in the domicile of Hangzhou DeepSeek Artificial Intelligence Fundamental Technology Research Co., Ltd. shall have exclusive jurisdiction of any dispute arising out of this agreement. + +END OF TERMS AND CONDITIONS + +Attachment A + +Use Restrictions + +You agree not to use the Model or Derivatives of the Model: + +- In any way that violates any applicable national or international law or regulation or infringes upon the lawful rights and interests of any third party; +- For military use in any way; +- For the purpose of exploiting, harming or attempting to exploit or harm minors in any way; +- To generate or disseminate verifiably false information and/or content with the purpose of harming others; +- To generate or disseminate inappropriate content subject to applicable regulatory requirements; +- To generate or disseminate personal identifiable information without due authorization or for unreasonable use; +- To defame, disparage or otherwise harass others; +- For fully automated decision making that adversely impacts an individual’s legal rights or otherwise creates or modifies a binding, enforceable obligation; +- For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics; +- To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm; +- For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories. -- Gitee From 6c2fe141b86b473363b07cb4bcea01f21a7b14bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:47:19 +0000 Subject: [PATCH 03/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../MultiModal/Janus-Pro-1B-OrangePi/Makefile | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile new file mode 100644 index 0000000000..493ded435b --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile @@ -0,0 +1,99 @@ +print-% : ; @echo $* = $($*) +PROJECT_NAME = Janus +COPYRIGHT = "DeepSeek." +PROJECT_PATH = janus +SHELL = /bin/bash +SOURCE_FOLDERS = janus +PYTHON_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.py" -o -name "*.pyi") inference.py +COMMIT_HASH = $(shell git log -1 --format=%h) +PATH := $(HOME)/go/bin:$(PATH) +PYTHON ?= $(shell command -v python3 || command -v python) +PYTESTOPTS ?= + +.PHONY: default +default: install + +# Tools Installation + +check_pip_install = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(1) --upgrade) +check_pip_install_extra = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(2) --upgrade) + +pylint-install: + $(call check_pip_install_extra,pylint,pylint[spelling]) + $(call check_pip_install,pyenchant) + +flake8-install: + $(call check_pip_install,flake8) + $(call check_pip_install,flake8-bugbear) + $(call check_pip_install,flake8-comprehensions) + $(call check_pip_install,flake8-docstrings) + $(call check_pip_install,flake8-pyi) + $(call check_pip_install,flake8-simplify) + +py-format-install: + $(call check_pip_install,isort) + $(call check_pip_install_extra,black,black[jupyter]) + +ruff-install: + $(call check_pip_install,ruff) + +mypy-install: + $(call check_pip_install,mypy) + +pre-commit-install: + $(call check_pip_install,pre-commit) + $(PYTHON) -m pre_commit install --install-hooks + +go-install: + # requires go >= 1.16 + command -v go || (sudo apt-get install -y golang && sudo ln -sf /usr/lib/go/bin/go /usr/bin/go) + +addlicense-install: go-install + command -v addlicense || go install github.com/google/addlicense@latest + +addlicense: addlicense-install + addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l mit -y 2023-$(shell date +"%Y") -check $(SOURCE_FOLDERS) + +# Python linters + +pylint: pylint-install + $(PYTHON) -m pylint $(PROJECT_PATH) + +flake8: flake8-install + $(PYTHON) -m flake8 --count --show-source --statistics + +py-format: py-format-install + $(PYTHON) -m isort --project $(PROJECT_PATH) --check $(PYTHON_FILES) && \ + $(PYTHON) -m black --check $(PYTHON_FILES) + +black-format: py-format-install + $(PYTHON) -m black --check $(PYTHON_FILES) + +ruff: ruff-install + $(PYTHON) -m ruff check . + +ruff-fix: ruff-install + $(PYTHON) -m ruff check . --fix --exit-non-zero-on-fix + +mypy: mypy-install + $(PYTHON) -m mypy $(PROJECT_PATH) --install-types --non-interactive + +pre-commit: pre-commit-install + $(PYTHON) -m pre_commit run --all-files + +# Utility functions + +lint: ruff flake8 py-format mypy pylint addlicense + +format: py-format-install ruff-install addlicense-install + $(PYTHON) -m isort --project $(PROJECT_PATH) $(PYTHON_FILES) + $(PYTHON) -m black $(PYTHON_FILES) + addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l mit -y 2023-$(shell date +"%Y") $(SOURCE_FOLDERS) inference.py + +clean-py: + find . -type f -name '*.py[co]' -delete + find . -depth -type d -name "__pycache__" -exec rm -r "{}" + + find . -depth -type d -name ".ruff_cache" -exec rm -r "{}" + + find . -depth -type d -name ".mypy_cache" -exec rm -r "{}" + + +clean: clean-py -- Gitee From 0e30aa25a48d92df6ff3f8e7cdb03f9a7c85395f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:48:05 +0000 Subject: [PATCH 04/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../generation_inference.py | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py new file mode 100644 index 0000000000..56921f26c1 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py @@ -0,0 +1,148 @@ +# Copyright (c) 2023-2024 DeepSeek. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import argparse + +import torch +import torch_npu +from torch_npu.contrib import transfer_to_npu +from transformers import AutoModelForCausalLM + +from janus.models import MultiModalityCausalLM, VLChatProcessor +import numpy as np +import os +import PIL.Image + +def parse_arguments(): + parser = argparse.ArgumentParser() + + parser.add_argument( + "--path", + type=str, + default='./deepseek-ai/Janus-Pro', + help="The path of model weights", + ) + + parser.add_argument( + "--device_id", + type=int, + default=0, + help="NPU device id", + ) + + parser.add_argument( + "--type", + type=str, + default='bf16', + choices=['bf16', 'fp16'], + help="bf16 or fp16" + ) + + return parser.parse_args() + +args = parse_arguments() +torch.npu.set_device(args.device_id) +dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 +torch_npu.npu.set_compile_mode(jit_compile=False) +# specify the path to the model +model_path = args.path +vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) +tokenizer = vl_chat_processor.tokenizer + +vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( + model_path, trust_remote_code=True, torch_dtype=dtype, device_map="npu" +) +vl_gpt = vl_gpt.eval() + +conversation = [ + { + "role": "User", + "content": "A close-up high-contrast photo of Sydney Opera House sitting next to Eiffel tower, under a blue night sky of roiling energy, exploding yellow stars, and radiating swirls of blue.", + }, + {"role": "Assistant", "content": ""}, +] + +sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts( + conversations=conversation, + sft_format=vl_chat_processor.sft_format, + system_prompt="", +) +prompt = sft_format + vl_chat_processor.image_start_tag + + +@torch.inference_mode() +def generate( + mmgpt: MultiModalityCausalLM, + vl_chat_processor: VLChatProcessor, + prompt: str, + temperature: float = 1, + parallel_size: int = 1, + cfg_weight: float = 5, + image_token_num_per_image: int = 576, + img_size: int = 384, + patch_size: int = 16, +): + input_ids = vl_chat_processor.tokenizer.encode(prompt) + input_ids = torch.LongTensor(input_ids) + + tokens = torch.zeros((parallel_size*2, len(input_ids)), dtype=torch.int).cuda() + for i in range(parallel_size*2): + tokens[i, :] = input_ids + if i % 2 != 0: + tokens[i, 1:-1] = vl_chat_processor.pad_id + + inputs_embeds = mmgpt.language_model.get_input_embeddings()(tokens) + + generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).cuda() + + for i in range(image_token_num_per_image): + outputs = mmgpt.language_model.model(inputs_embeds=inputs_embeds, use_cache=True, past_key_values=outputs.past_key_values if i != 0 else None) + hidden_states = outputs.last_hidden_state + logits = mmgpt.gen_head(hidden_states[:, -1, :]) + logit_cond = logits[0::2, :] + logit_uncond = logits[1::2, :] + + logits = logit_uncond + cfg_weight * (logit_cond-logit_uncond) + probs = torch.softmax(logits / temperature, dim=-1) + + next_token = torch.multinomial(probs, num_samples=1) + generated_tokens[:, i] = next_token.squeeze(dim=-1) + + next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1) + img_embeds = mmgpt.prepare_gen_img_embeds(next_token) + inputs_embeds = img_embeds.unsqueeze(dim=1) + + dec = mmgpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int), shape=[parallel_size, 8, img_size//patch_size, img_size//patch_size]) + dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1) + + dec = np.clip((dec + 1) / 2 * 255, 0, 255) + + visual_img = np.zeros((parallel_size, img_size, img_size, 3), dtype=np.uint8) + visual_img[:, :, :] = dec + + os.makedirs('generated_samples', exist_ok=True) + for i in range(parallel_size): + save_path = os.path.join('generated_samples', "img_{}.jpg".format(i)) + PIL.Image.fromarray(visual_img[i]).save(save_path) + + +generate( + vl_gpt, + vl_chat_processor, + prompt, +) -- Gitee From 18c065dc43c34507385d3af56b6a747fa57c39e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:48:54 +0000 Subject: [PATCH 05/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/ inference.py | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py new file mode 100644 index 0000000000..ca6109ef79 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py @@ -0,0 +1,101 @@ +# Copyright (c) 2023-2024 DeepSeek. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal in +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +# the Software, and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +import argparse + +import torch +import torch_npu +from torch_npu.contrib import transfer_to_npu +from transformers import AutoModelForCausalLM + +from janus.models import MultiModalityCausalLM, VLChatProcessor +from janus.utils.io import load_pil_images + +def parse_arguments(): + parser = argparse.ArgumentParser() + + parser.add_argument( + "--path", + type=str, + default='./deepseek-ai/Janus-Pro', + help="The path of model weights", + ) + + parser.add_argument( + "--device_id", + type=int, + default=0, + help="NPU device id", + ) + + parser.add_argument( + "--type", + type=str, + default='bf16', + choices=['bf16', 'fp16'], + help="bf16 or fp16" + ) + + return parser.parse_args() + +args = parse_arguments() +torch.npu.set_device(args.device_id) +dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 +torch_npu.npu.set_compile_mode(jit_compile=False) +# specify the path to the model +model_path = args.path +vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) +tokenizer = vl_chat_processor.tokenizer + +vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( + model_path, trust_remote_code=True, torch_dtype=dtype, device_map="npu" +) +vl_gpt = vl_gpt.eval() + +conversation = [ + { + "role": "User", + "content": "\nConvert the formula into latex code.", + "images": ["images/equation.png"], + }, + {"role": "Assistant", "content": ""}, +] + +# load images and prepare for inputs +pil_images = load_pil_images(conversation) +prepare_inputs = vl_chat_processor( + conversations=conversation, images=pil_images, force_batchify=True +).to(vl_gpt.device, dtype=dtype) + +# # run image encoder to get the image embeddings +inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs) + +# # run the model to get the response +outputs = vl_gpt.language_model.generate( + inputs_embeds=inputs_embeds, + attention_mask=prepare_inputs.attention_mask, + pad_token_id=tokenizer.eos_token_id, + bos_token_id=tokenizer.bos_token_id, + eos_token_id=tokenizer.eos_token_id, + max_new_tokens=512, + do_sample=False, + use_cache=True, +) + +answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True) +print(f"{prepare_inputs['sft_format'][0]}", answer) -- Gitee From bdf5647a213b17a940cae78960bdf07f1489c6fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:49:34 +0000 Subject: [PATCH 06/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/ pyproject.toml | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml new file mode 100644 index 0000000000..ee6d7ee3d7 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml @@ -0,0 +1,53 @@ +[build-system] +requires = ["setuptools>=40.6.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "janus" +version = "1.0.0" +description = "Janus" +authors = [{name = "DeepSeek-AI"}] +license = {file = "LICENSE-CODE"} +urls = {homepage = "https://github.com/deepseek-ai/Janus"} +readme = "README.md" +requires-python = ">=3.8" +dependencies = [ + "torch>=2.0.1", + "transformers>=4.38.2", + "timm>=0.9.16", + "accelerate", + "sentencepiece", + "attrdict", + "einops", +] + +[project.optional-dependencies] +gradio = [ + "gradio==3.48.0", + "gradio-client==0.6.1", + "mdtex2html==1.3.0", + "pypinyin==0.50.0", + "tiktoken==0.5.2", + "tqdm==4.64.0", + "colorama==0.4.5", + "Pygments==2.12.0", + "markdown==3.4.1", + "SentencePiece==0.1.96" +] +lint = [ + "isort", + "black[jupyter] >= 22.6.0", + "pylint[spelling] >= 2.15.0", + "flake8", + "flake8-bugbear", + "flake8-comprehensions", + "flake8-docstrings", + "flake8-pyi", + "flake8-simplify", + "ruff", + "pyenchant", + "pre-commit", +] + +[tool.setuptools] +packages = {find = {exclude = ["images"]}} -- Gitee From b08c74a720355b6b2f6bb27e24853341d484e708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 01:50:25 +0000 Subject: [PATCH 07/42] add MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/interactivechat.py | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py new file mode 100644 index 0000000000..7d3ca4aab1 --- /dev/null +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py @@ -0,0 +1,184 @@ +import argparse +import os +import PIL.Image +import torch +import torch_npu +from torch_npu.contrib import transfer_to_npu +import numpy as np +from transformers import AutoModelForCausalLM +from janus.models import MultiModalityCausalLM, VLChatProcessor +import time +import re + +def parse_arguments(): + parser = argparse.ArgumentParser() + + parser.add_argument( + "--path", + type=str, + default='./deepseek-ai/Janus-Pro', + help="The path of model weights", + ) + + parser.add_argument( + "--device_id", + type=int, + default=0, + help="NPU device id", + ) + + parser.add_argument( + "--type", + type=str, + default='bf16', + choices=['bf16', 'fp16'], + help="bf16 or fp16" + ) + + return parser.parse_args() + +args = parse_arguments() +torch.npu.set_device(args.device_id) +dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 +torch_npu.npu.set_compile_mode(jit_compile=False) +# Specify the path to the model +model_path = args.path +vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) +tokenizer = vl_chat_processor.tokenizer + +vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( + model_path, trust_remote_code=True +) +vl_gpt = vl_gpt.to(dtype).to("npu").eval() + + +def create_prompt(user_input: str) -> str: + conversation = [ + { + "role": "User", + "content": user_input, + }, + {"role": "Assistant", "content": ""}, + ] + + sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts( + conversations=conversation, + sft_format=vl_chat_processor.sft_format, + system_prompt="", + ) + prompt = sft_format + vl_chat_processor.image_start_tag + return prompt + + +@torch.inference_mode() +def generate( + mmgpt: MultiModalityCausalLM, + vl_chat_processor: VLChatProcessor, + prompt: str, + short_prompt: str, + parallel_size: int = 16, + temperature: float = 1, + cfg_weight: float = 5, + image_token_num_per_image: int = 576, + img_size: int = 384, + patch_size: int = 16, +): + input_ids = vl_chat_processor.tokenizer.encode(prompt) + input_ids = torch.LongTensor(input_ids) + + tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).cuda() + for i in range(parallel_size * 2): + tokens[i, :] = input_ids + if i % 2 != 0: + tokens[i, 1:-1] = vl_chat_processor.pad_id + + inputs_embeds = mmgpt.language_model.get_input_embeddings()(tokens) + + generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).cuda() + outputs = None # Initialize outputs for use in the loop + + for i in range(image_token_num_per_image): + outputs = mmgpt.language_model.model( + inputs_embeds=inputs_embeds, + use_cache=True, + past_key_values=outputs.past_key_values if i != 0 else None + ) + hidden_states = outputs.last_hidden_state + + logits = mmgpt.gen_head(hidden_states[:, -1, :]) + logit_cond = logits[0::2, :] + logit_uncond = logits[1::2, :] + + logits = logit_uncond + cfg_weight * (logit_cond - logit_uncond) + probs = torch.softmax(logits / temperature, dim=-1) + + next_token = torch.multinomial(probs, num_samples=1) + generated_tokens[:, i] = next_token.squeeze(dim=-1) + + next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1) + img_embeds = mmgpt.prepare_gen_img_embeds(next_token) + inputs_embeds = img_embeds.unsqueeze(dim=1) + + dec = mmgpt.gen_vision_model.decode_code( + generated_tokens.to(dtype=torch.int), + shape=[parallel_size, 8, img_size // patch_size, img_size // patch_size] + ) + dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1) + + dec = np.clip((dec + 1) / 2 * 255, 0, 255) + + visual_img = np.zeros((parallel_size, img_size, img_size, 3), dtype=np.uint8) + visual_img[:, :, :] = dec + + os.makedirs('generated_samples', exist_ok=True) + + # Create a timestamp + timestamp = time.strftime("%Y%m%d-%H%M%S") + + # Sanitize the short_prompt to ensure it's safe for filenames + short_prompt = re.sub(r'\W+', '_', short_prompt)[:50] + + # Save images with timestamp and part of the user prompt in the filename + for i in range(parallel_size): + save_path = os.path.join('generated_samples', f"img_{timestamp}_{short_prompt}_{i}.jpg") + PIL.Image.fromarray(visual_img[i]).save(save_path) + + +def interactive_image_generator(): + print("Welcome to the interactive image generator!") + + # Ask for the number of images at the start of the session + while True: + num_images_input = input("How many images would you like to generate per prompt? (Enter a positive integer): ") + if num_images_input.isdigit() and int(num_images_input) > 0: + parallel_size = int(num_images_input) + break + else: + print("Invalid input. Please enter a positive integer.") + + while True: + user_input = input("Please describe the image you'd like to generate (or type 'exit' to quit): ") + + if user_input.lower() == 'exit': + print("Exiting the image generator. Goodbye!") + break + + prompt = create_prompt(user_input) + + # Create a sanitized version of user_input for the filename + short_prompt = re.sub(r'\W+', '_', user_input)[:50] + + print(f"Generating {parallel_size} image(s) for: '{user_input}'") + generate( + mmgpt=vl_gpt, + vl_chat_processor=vl_chat_processor, + prompt=prompt, + short_prompt=short_prompt, + parallel_size=parallel_size # Pass the user-specified number of images + ) + + print("Image generation complete! Check the 'generated_samples' folder for the output.\n") + + +if __name__ == "__main__": + interactive_image_generator() -- Gitee From dc127bf9708ca3ddc88b8cdd5664d64bd7d44d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:15:04 +0000 Subject: [PATCH 08/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py index 7d3ca4aab1..4c39f6ef84 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py @@ -1,14 +1,17 @@ import argparse import os +import time +import re + import PIL.Image +import numpy as np import torch import torch_npu from torch_npu.contrib import transfer_to_npu -import numpy as np from transformers import AutoModelForCausalLM + from janus.models import MultiModalityCausalLM, VLChatProcessor -import time -import re + def parse_arguments(): parser = argparse.ArgumentParser() -- Gitee From 81220718921a80af35806ce306363b5f034676f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:17:54 +0000 Subject: [PATCH 09/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/generation_inference.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py index 56921f26c1..5afc61abe3 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py @@ -17,16 +17,17 @@ # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import argparse +import os +import PIL.Image +import numpy as np import torch import torch_npu from torch_npu.contrib import transfer_to_npu from transformers import AutoModelForCausalLM from janus.models import MultiModalityCausalLM, VLChatProcessor -import numpy as np -import os -import PIL.Image + def parse_arguments(): parser = argparse.ArgumentParser() -- Gitee From d96483ae269f65a8e2fb8c31a2949c9ca30e36d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:35:01 +0000 Subject: [PATCH 10/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Janus-Pro-1B-OrangePi/interactivechat.py | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py index 4c39f6ef84..96cddf18a5 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py @@ -7,12 +7,22 @@ import PIL.Image import numpy as np import torch import torch_npu +from dataclasses import dataclass from torch_npu.contrib import transfer_to_npu from transformers import AutoModelForCausalLM from janus.models import MultiModalityCausalLM, VLChatProcessor +@dataclass +class GenerateConfig: + parallel_size: int = 16 + temperature: float = 1.0 + cfg_weight: float = 5.0 + image_token_num_per_image: int = 576 + img_size: int = 384 + patch_size: int = 16 + def parse_arguments(): parser = argparse.ArgumentParser() @@ -46,8 +56,8 @@ dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 torch_npu.npu.set_compile_mode(jit_compile=False) # Specify the path to the model model_path = args.path -vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) -tokenizer = vl_chat_processor.tokenizer +vl_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) +tokenizer = vl_processor.tokenizer vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( model_path, trust_remote_code=True @@ -64,12 +74,12 @@ def create_prompt(user_input: str) -> str: {"role": "Assistant", "content": ""}, ] - sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts( + sft_format = vl_processor.apply_sft_template_for_multi_turn_prompts( conversations=conversation, - sft_format=vl_chat_processor.sft_format, + sft_format=vl_processor.sft_format, system_prompt="", ) - prompt = sft_format + vl_chat_processor.image_start_tag + prompt = sft_format + vl_processor.image_start_tag return prompt @@ -79,12 +89,7 @@ def generate( vl_chat_processor: VLChatProcessor, prompt: str, short_prompt: str, - parallel_size: int = 16, - temperature: float = 1, - cfg_weight: float = 5, - image_token_num_per_image: int = 576, - img_size: int = 384, - patch_size: int = 16, + config: GenerateConfig ): input_ids = vl_chat_processor.tokenizer.encode(prompt) input_ids = torch.LongTensor(input_ids) @@ -170,14 +175,16 @@ def interactive_image_generator(): # Create a sanitized version of user_input for the filename short_prompt = re.sub(r'\W+', '_', user_input)[:50] + config = GenerateConfig(parallel_size=parallel_size) print(f"Generating {parallel_size} image(s) for: '{user_input}'") generate( mmgpt=vl_gpt, - vl_chat_processor=vl_chat_processor, + vl_chat_processor=vl_processor, prompt=prompt, short_prompt=short_prompt, - parallel_size=parallel_size # Pass the user-specified number of images + parallel_size=parallel_size, + config=config ) print("Image generation complete! Check the 'generated_samples' folder for the output.\n") -- Gitee From fa043fe80701ce293880801afa36f45a50c0393f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:40:29 +0000 Subject: [PATCH 11/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../generation_inference.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py index 5afc61abe3..323eb5c48b 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py @@ -62,8 +62,8 @@ dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 torch_npu.npu.set_compile_mode(jit_compile=False) # specify the path to the model model_path = args.path -vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) -tokenizer = vl_chat_processor.tokenizer +vl_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) +tokenizer = vl_processor.tokenizer vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( model_path, trust_remote_code=True, torch_dtype=dtype, device_map="npu" @@ -78,12 +78,12 @@ conversation = [ {"role": "Assistant", "content": ""}, ] -sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts( +sft_format = vl_processor.apply_sft_template_for_multi_turn_prompts( conversations=conversation, - sft_format=vl_chat_processor.sft_format, + sft_format=vl_processor.sft_format, system_prompt="", ) -prompt = sft_format + vl_chat_processor.image_start_tag +prompt_tmp = sft_format + vl_processor.image_start_tag @torch.inference_mode() @@ -101,8 +101,8 @@ def generate( input_ids = vl_chat_processor.tokenizer.encode(prompt) input_ids = torch.LongTensor(input_ids) - tokens = torch.zeros((parallel_size*2, len(input_ids)), dtype=torch.int).cuda() - for i in range(parallel_size*2): + tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).cuda() + for i in range(parallel_size * 2): tokens[i, :] = input_ids if i % 2 != 0: tokens[i, 1:-1] = vl_chat_processor.pad_id @@ -118,7 +118,7 @@ def generate( logit_cond = logits[0::2, :] logit_uncond = logits[1::2, :] - logits = logit_uncond + cfg_weight * (logit_cond-logit_uncond) + logits = logit_uncond + cfg_weight * (logit_cond - logit_uncond) probs = torch.softmax(logits / temperature, dim=-1) next_token = torch.multinomial(probs, num_samples=1) @@ -128,7 +128,7 @@ def generate( img_embeds = mmgpt.prepare_gen_img_embeds(next_token) inputs_embeds = img_embeds.unsqueeze(dim=1) - dec = mmgpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int), shape=[parallel_size, 8, img_size//patch_size, img_size//patch_size]) + dec = mmgpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int), shape=[parallel_size, 8, img_size // patch_size, img_size // patch_size]) dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1) dec = np.clip((dec + 1) / 2 * 255, 0, 255) -- Gitee From 6d6054b067724f11e1d4ba2af91cef1b408e5e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:50:54 +0000 Subject: [PATCH 12/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py index 96cddf18a5..284fe98089 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py @@ -2,12 +2,12 @@ import argparse import os import time import re +from dataclasses import dataclass import PIL.Image import numpy as np import torch import torch_npu -from dataclasses import dataclass from torch_npu.contrib import transfer_to_npu from transformers import AutoModelForCausalLM @@ -23,6 +23,7 @@ class GenerateConfig: img_size: int = 384 patch_size: int = 16 + def parse_arguments(): parser = argparse.ArgumentParser() -- Gitee From c004d8a28f1002d74acf07c2a522deff799962ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 02:54:06 +0000 Subject: [PATCH 13/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../generation_inference.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py index 323eb5c48b..cc036fed80 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py @@ -18,6 +18,7 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import argparse import os +from dataclasses import dataclass import PIL.Image import numpy as np @@ -29,6 +30,16 @@ from transformers import AutoModelForCausalLM from janus.models import MultiModalityCausalLM, VLChatProcessor +@dataclass +class GenerateConfig: + temperature: float = 1.0 + parallel_size: int = 1 + cfg_weight: float = 5.0 + image_token_num_per_image: int = 576 + img_size: int = 384 + patch_size: int = 16 + + def parse_arguments(): parser = argparse.ArgumentParser() @@ -91,12 +102,7 @@ def generate( mmgpt: MultiModalityCausalLM, vl_chat_processor: VLChatProcessor, prompt: str, - temperature: float = 1, - parallel_size: int = 1, - cfg_weight: float = 5, - image_token_num_per_image: int = 576, - img_size: int = 384, - patch_size: int = 16, + config: GenerateConfig, ): input_ids = vl_chat_processor.tokenizer.encode(prompt) input_ids = torch.LongTensor(input_ids) -- Gitee From dba2bc9fc73c085dd2b23312b0aa89ea08e6d80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 03:11:35 +0000 Subject: [PATCH 14/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py | 1 - 1 file changed, 1 deletion(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py index cc036fed80..d0ac728df7 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py @@ -97,7 +97,6 @@ sft_format = vl_processor.apply_sft_template_for_multi_turn_prompts( prompt_tmp = sft_format + vl_processor.image_start_tag -@torch.inference_mode() def generate( mmgpt: MultiModalityCausalLM, vl_chat_processor: VLChatProcessor, -- Gitee From 9bdf80ab1bc283698b7924a39437bb436d217e51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Fri, 6 Jun 2025 03:17:29 +0000 Subject: [PATCH 15/42] cleancode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py index 284fe98089..c0fd7ab3c0 100644 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py +++ b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py @@ -84,7 +84,6 @@ def create_prompt(user_input: str) -> str: return prompt -@torch.inference_mode() def generate( mmgpt: MultiModalityCausalLM, vl_chat_processor: VLChatProcessor, -- Gitee From 28d58421697d71089c0149b7a5515938c6f1a07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:23:24 +0000 Subject: [PATCH 16/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/generation=5Finference.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generation_inference.py | 154 ------------------ 1 file changed, 154 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py deleted file mode 100644 index d0ac728df7..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/generation_inference.py +++ /dev/null @@ -1,154 +0,0 @@ -# Copyright (c) 2023-2024 DeepSeek. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import argparse -import os -from dataclasses import dataclass - -import PIL.Image -import numpy as np -import torch -import torch_npu -from torch_npu.contrib import transfer_to_npu -from transformers import AutoModelForCausalLM - -from janus.models import MultiModalityCausalLM, VLChatProcessor - - -@dataclass -class GenerateConfig: - temperature: float = 1.0 - parallel_size: int = 1 - cfg_weight: float = 5.0 - image_token_num_per_image: int = 576 - img_size: int = 384 - patch_size: int = 16 - - -def parse_arguments(): - parser = argparse.ArgumentParser() - - parser.add_argument( - "--path", - type=str, - default='./deepseek-ai/Janus-Pro', - help="The path of model weights", - ) - - parser.add_argument( - "--device_id", - type=int, - default=0, - help="NPU device id", - ) - - parser.add_argument( - "--type", - type=str, - default='bf16', - choices=['bf16', 'fp16'], - help="bf16 or fp16" - ) - - return parser.parse_args() - -args = parse_arguments() -torch.npu.set_device(args.device_id) -dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 -torch_npu.npu.set_compile_mode(jit_compile=False) -# specify the path to the model -model_path = args.path -vl_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) -tokenizer = vl_processor.tokenizer - -vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( - model_path, trust_remote_code=True, torch_dtype=dtype, device_map="npu" -) -vl_gpt = vl_gpt.eval() - -conversation = [ - { - "role": "User", - "content": "A close-up high-contrast photo of Sydney Opera House sitting next to Eiffel tower, under a blue night sky of roiling energy, exploding yellow stars, and radiating swirls of blue.", - }, - {"role": "Assistant", "content": ""}, -] - -sft_format = vl_processor.apply_sft_template_for_multi_turn_prompts( - conversations=conversation, - sft_format=vl_processor.sft_format, - system_prompt="", -) -prompt_tmp = sft_format + vl_processor.image_start_tag - - -def generate( - mmgpt: MultiModalityCausalLM, - vl_chat_processor: VLChatProcessor, - prompt: str, - config: GenerateConfig, -): - input_ids = vl_chat_processor.tokenizer.encode(prompt) - input_ids = torch.LongTensor(input_ids) - - tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).cuda() - for i in range(parallel_size * 2): - tokens[i, :] = input_ids - if i % 2 != 0: - tokens[i, 1:-1] = vl_chat_processor.pad_id - - inputs_embeds = mmgpt.language_model.get_input_embeddings()(tokens) - - generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).cuda() - - for i in range(image_token_num_per_image): - outputs = mmgpt.language_model.model(inputs_embeds=inputs_embeds, use_cache=True, past_key_values=outputs.past_key_values if i != 0 else None) - hidden_states = outputs.last_hidden_state - logits = mmgpt.gen_head(hidden_states[:, -1, :]) - logit_cond = logits[0::2, :] - logit_uncond = logits[1::2, :] - - logits = logit_uncond + cfg_weight * (logit_cond - logit_uncond) - probs = torch.softmax(logits / temperature, dim=-1) - - next_token = torch.multinomial(probs, num_samples=1) - generated_tokens[:, i] = next_token.squeeze(dim=-1) - - next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1) - img_embeds = mmgpt.prepare_gen_img_embeds(next_token) - inputs_embeds = img_embeds.unsqueeze(dim=1) - - dec = mmgpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int), shape=[parallel_size, 8, img_size // patch_size, img_size // patch_size]) - dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1) - - dec = np.clip((dec + 1) / 2 * 255, 0, 255) - - visual_img = np.zeros((parallel_size, img_size, img_size, 3), dtype=np.uint8) - visual_img[:, :, :] = dec - - os.makedirs('generated_samples', exist_ok=True) - for i in range(parallel_size): - save_path = os.path.join('generated_samples', "img_{}.jpg".format(i)) - PIL.Image.fromarray(visual_img[i]).save(save_path) - - -generate( - vl_gpt, - vl_chat_processor, - prompt, -) -- Gitee From bea87355b5a08b765ad1ffcf2cf97bd8d6cbd879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:23:49 +0000 Subject: [PATCH 17/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Janus-Pro-1B-OrangePi/interactivechat.py | 194 ------------------ 1 file changed, 194 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py deleted file mode 100644 index c0fd7ab3c0..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/interactivechat.py +++ /dev/null @@ -1,194 +0,0 @@ -import argparse -import os -import time -import re -from dataclasses import dataclass - -import PIL.Image -import numpy as np -import torch -import torch_npu -from torch_npu.contrib import transfer_to_npu -from transformers import AutoModelForCausalLM - -from janus.models import MultiModalityCausalLM, VLChatProcessor - - -@dataclass -class GenerateConfig: - parallel_size: int = 16 - temperature: float = 1.0 - cfg_weight: float = 5.0 - image_token_num_per_image: int = 576 - img_size: int = 384 - patch_size: int = 16 - - -def parse_arguments(): - parser = argparse.ArgumentParser() - - parser.add_argument( - "--path", - type=str, - default='./deepseek-ai/Janus-Pro', - help="The path of model weights", - ) - - parser.add_argument( - "--device_id", - type=int, - default=0, - help="NPU device id", - ) - - parser.add_argument( - "--type", - type=str, - default='bf16', - choices=['bf16', 'fp16'], - help="bf16 or fp16" - ) - - return parser.parse_args() - -args = parse_arguments() -torch.npu.set_device(args.device_id) -dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 -torch_npu.npu.set_compile_mode(jit_compile=False) -# Specify the path to the model -model_path = args.path -vl_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) -tokenizer = vl_processor.tokenizer - -vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( - model_path, trust_remote_code=True -) -vl_gpt = vl_gpt.to(dtype).to("npu").eval() - - -def create_prompt(user_input: str) -> str: - conversation = [ - { - "role": "User", - "content": user_input, - }, - {"role": "Assistant", "content": ""}, - ] - - sft_format = vl_processor.apply_sft_template_for_multi_turn_prompts( - conversations=conversation, - sft_format=vl_processor.sft_format, - system_prompt="", - ) - prompt = sft_format + vl_processor.image_start_tag - return prompt - - -def generate( - mmgpt: MultiModalityCausalLM, - vl_chat_processor: VLChatProcessor, - prompt: str, - short_prompt: str, - config: GenerateConfig -): - input_ids = vl_chat_processor.tokenizer.encode(prompt) - input_ids = torch.LongTensor(input_ids) - - tokens = torch.zeros((parallel_size * 2, len(input_ids)), dtype=torch.int).cuda() - for i in range(parallel_size * 2): - tokens[i, :] = input_ids - if i % 2 != 0: - tokens[i, 1:-1] = vl_chat_processor.pad_id - - inputs_embeds = mmgpt.language_model.get_input_embeddings()(tokens) - - generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).cuda() - outputs = None # Initialize outputs for use in the loop - - for i in range(image_token_num_per_image): - outputs = mmgpt.language_model.model( - inputs_embeds=inputs_embeds, - use_cache=True, - past_key_values=outputs.past_key_values if i != 0 else None - ) - hidden_states = outputs.last_hidden_state - - logits = mmgpt.gen_head(hidden_states[:, -1, :]) - logit_cond = logits[0::2, :] - logit_uncond = logits[1::2, :] - - logits = logit_uncond + cfg_weight * (logit_cond - logit_uncond) - probs = torch.softmax(logits / temperature, dim=-1) - - next_token = torch.multinomial(probs, num_samples=1) - generated_tokens[:, i] = next_token.squeeze(dim=-1) - - next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1) - img_embeds = mmgpt.prepare_gen_img_embeds(next_token) - inputs_embeds = img_embeds.unsqueeze(dim=1) - - dec = mmgpt.gen_vision_model.decode_code( - generated_tokens.to(dtype=torch.int), - shape=[parallel_size, 8, img_size // patch_size, img_size // patch_size] - ) - dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1) - - dec = np.clip((dec + 1) / 2 * 255, 0, 255) - - visual_img = np.zeros((parallel_size, img_size, img_size, 3), dtype=np.uint8) - visual_img[:, :, :] = dec - - os.makedirs('generated_samples', exist_ok=True) - - # Create a timestamp - timestamp = time.strftime("%Y%m%d-%H%M%S") - - # Sanitize the short_prompt to ensure it's safe for filenames - short_prompt = re.sub(r'\W+', '_', short_prompt)[:50] - - # Save images with timestamp and part of the user prompt in the filename - for i in range(parallel_size): - save_path = os.path.join('generated_samples', f"img_{timestamp}_{short_prompt}_{i}.jpg") - PIL.Image.fromarray(visual_img[i]).save(save_path) - - -def interactive_image_generator(): - print("Welcome to the interactive image generator!") - - # Ask for the number of images at the start of the session - while True: - num_images_input = input("How many images would you like to generate per prompt? (Enter a positive integer): ") - if num_images_input.isdigit() and int(num_images_input) > 0: - parallel_size = int(num_images_input) - break - else: - print("Invalid input. Please enter a positive integer.") - - while True: - user_input = input("Please describe the image you'd like to generate (or type 'exit' to quit): ") - - if user_input.lower() == 'exit': - print("Exiting the image generator. Goodbye!") - break - - prompt = create_prompt(user_input) - - # Create a sanitized version of user_input for the filename - short_prompt = re.sub(r'\W+', '_', user_input)[:50] - config = GenerateConfig(parallel_size=parallel_size) - - print(f"Generating {parallel_size} image(s) for: '{user_input}'") - generate( - mmgpt=vl_gpt, - vl_chat_processor=vl_processor, - prompt=prompt, - short_prompt=short_prompt, - parallel_size=parallel_size, - config=config - ) - - print("Image generation complete! Check the 'generated_samples' folder for the output.\n") - - -if __name__ == "__main__": - interactive_image_generator() -- Gitee From 59e285a7db932855869ba28e5b2c7af90e1b0dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:24:06 +0000 Subject: [PATCH 18/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/=20inference.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Janus-Pro-1B-OrangePi/ inference.py | 101 ------------------ 1 file changed, 101 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py deleted file mode 100644 index ca6109ef79..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ inference.py +++ /dev/null @@ -1,101 +0,0 @@ -# Copyright (c) 2023-2024 DeepSeek. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import argparse - -import torch -import torch_npu -from torch_npu.contrib import transfer_to_npu -from transformers import AutoModelForCausalLM - -from janus.models import MultiModalityCausalLM, VLChatProcessor -from janus.utils.io import load_pil_images - -def parse_arguments(): - parser = argparse.ArgumentParser() - - parser.add_argument( - "--path", - type=str, - default='./deepseek-ai/Janus-Pro', - help="The path of model weights", - ) - - parser.add_argument( - "--device_id", - type=int, - default=0, - help="NPU device id", - ) - - parser.add_argument( - "--type", - type=str, - default='bf16', - choices=['bf16', 'fp16'], - help="bf16 or fp16" - ) - - return parser.parse_args() - -args = parse_arguments() -torch.npu.set_device(args.device_id) -dtype = torch.float16 if args.type == "fp16" else torch.bfloat16 -torch_npu.npu.set_compile_mode(jit_compile=False) -# specify the path to the model -model_path = args.path -vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path) -tokenizer = vl_chat_processor.tokenizer - -vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained( - model_path, trust_remote_code=True, torch_dtype=dtype, device_map="npu" -) -vl_gpt = vl_gpt.eval() - -conversation = [ - { - "role": "User", - "content": "\nConvert the formula into latex code.", - "images": ["images/equation.png"], - }, - {"role": "Assistant", "content": ""}, -] - -# load images and prepare for inputs -pil_images = load_pil_images(conversation) -prepare_inputs = vl_chat_processor( - conversations=conversation, images=pil_images, force_batchify=True -).to(vl_gpt.device, dtype=dtype) - -# # run image encoder to get the image embeddings -inputs_embeds = vl_gpt.prepare_inputs_embeds(**prepare_inputs) - -# # run the model to get the response -outputs = vl_gpt.language_model.generate( - inputs_embeds=inputs_embeds, - attention_mask=prepare_inputs.attention_mask, - pad_token_id=tokenizer.eos_token_id, - bos_token_id=tokenizer.bos_token_id, - eos_token_id=tokenizer.eos_token_id, - max_new_tokens=512, - do_sample=False, - use_cache=True, -) - -answer = tokenizer.decode(outputs[0].cpu().tolist(), skip_special_tokens=True) -print(f"{prepare_inputs['sft_format'][0]}", answer) -- Gitee From f1b509808264ba5bf9706e054e0737dd39915c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:31:03 +0000 Subject: [PATCH 19/42] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Qwen3-0.6B-OrangePi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From 6db5404d6601789b1bbd7d114e16010b520dbef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:36:43 +0000 Subject: [PATCH 20/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep | 0 MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README | 181 ++++++++++++++++++++ 2 files changed, 181 insertions(+) delete mode 100644 MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep create mode 100644 MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README new file mode 100644 index 0000000000..1f798cef23 --- /dev/null +++ b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README @@ -0,0 +1,181 @@ +# Qwen3-0.6B-OrangePi +## 简介 +Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混合专家(MoE)模型的全面套件。基于广泛的训练,Qwen3在推理、指令遵循、代理功能和多语言支持方面取得了很大的进展,主要具有以下功能: + +- **思维模式**(用于复杂的逻辑推理、数学和编码)和**非思维模式**(用于高效、通用的对话)在单个模型内无缝切换,确保跨各种场景的最佳性能。 +- **增强了推理能力**在数学、代码生成和常识逻辑推理方面超过了之前的QwQ(思维模式)和Qwen2.5(非思维模式)。 +- **人类偏好调整**,擅长创意写作、角色扮演、多轮对话和指令跟随,提供更自然、更吸引人、更沉浸式的对话体验。 +- **在代理能力方面的专业知识**,能够在思考模式和非思考模式下与外部工具精确集成,在基于代理的复杂任务中实现开源模型中的领先性能。 +- **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 + +## 约束条件 +* 在20t24g 香橙派aipro上部署Qwen3-0.6B模型 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 由于此硬件为单卡,仅支持TP=1 + +## 权重 + +**权重下载** + +- [Qwen3-0.6B](https://huggingface.co/Qwen/Qwen3-0.6B/tree/main) + +## 新建环境 + +### 1.1 安装CANN +- CANN-kernels[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-kernels-310b_8.1.RC1_linux-aarch64.run) +- CANN-toolkit[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-toolkit_8.1.RC1_linux-aarch64.run) +- 安装顺序:先安装toolkit 再安装kernel + +#### 1.1.1 安装toolkit + +- 下载 + +| cpu | 包名(其中`${version}`为实际版本) | +| ------- | ------------------------------------------------ | +| aarch64 | Ascend-cann-toolkit_${version}_linux-aarch64.run | + +- 安装 + ```bash + # 安装toolkit 以arm为例 + chmod +x Ascend-cann-toolkit_${version}_linux-aarch64.run + ./Ascend-cann-toolkit_${version}_linux-aarch64.run --install + source /usr/local/Ascend/ascend-toolkit/set_env.sh + ``` + +#### 1.1.2 安装kernel + +- 下载 + +| 包名 | +| ------------------------------------------ | +| Ascend-cann-kernels*_${version}_linux.run | + + - 根据芯片型号选择对应的安装包 + +- 安装 + ```bash + chmod +x Ascend-cann-kernels-*_${version}_linux.run + ./Ascend-cann-kernels-*_${version}_linux.run --install + ``` + +#### 1.1.3 安装加速库 +- 下载加速库 + - [下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-nnal_8.1.RC1_linux-aarch64.run)。 + + | 包名(其中`${version}`为实际版本) | + | -------------------------------------------- | + | Ascend-cann-nnal_${version}_linux-aarch64.run | + | ... | + + - 将文件放置在\${working_dir}路径下 + +- 安装 + ```shell + chmod +x Ascend-cann-nnal_*_linux-*.run + ./Ascend-cann-nnal_*_linux-*.run --install --install-path=${working_dir} + source ${working_dir}/nnal/atb/set_env.sh + ``` +- 可以使用`uname -a`指令查看服务器是x86还是aarch架构 +- 可以使用以下指令查看abi是0还是1 + ```shell + python -c "import torch; print(torch.compiled_with_cxx11_abi())" + ``` + - 若输出结果为True表示abi1,False表示abi0 + +### 1.2 安装PytorchAdapter + +先安装torch 再安装torch_npu + +#### 1.2.1 安装torch + +- 下载 + + | 包名 | + | -------------------------------------------- | + | torch-2.1.0-cp310-cp10-linux_aarch64.whl | + | ... | + + - 根据所使用的环境中的python版本以及cpu类型,选择对应版本的torch安装包。 + +- 安装 + ```bash + # 安装torch 2.1.0 的python 3.10 的arm版本为例 + pip install torch-2.1.0-cp310-cp310-linux_aarch64.whl + ``` + +#### 1.2.2 安装torch_npu + +[下载PyTorch Adapter](https://www.hiascend.com/developer/download/community/result?module=pt),安装方法: + +| 包名 | +| --------------------------- | +| pytorch_v2.1.0_py38.tar.gz | +| pytorch_v2.1.0_py39.tar.gz | +| pytorch_v2.1.0_py310.tar.gz | +| ... | + +- 安装选择与torch版本以及python版本一致的npu_torch版本 + +```bash +# 安装 torch_npu,以 torch 2.1.0,python 3.10 的版本为例 +tar -zxvf pytorch_v2.1.0_py310.tar.gz +pip install torch*_aarch64.whl +``` +### 1.3 安装开源软件依赖 +| 默认依赖 | [requirement.txt](./requirements.txt) | +- 开源软件依赖请使用下述命令进行安装: + ```bash + pip install -r ./requirements.txt + ``` + +### 1.4 安装模型仓 +使用编译好的包进行安装 + - 下载编译好的包 + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi0.tar.gz) + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi1.tar.gz) + + | 包名 | + | ------------------------------------------------------------ | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch1.11.0-abi0.tar.gz | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch2.1.0-abi1.tar.gz | + | ... | + + - 将文件放置在\${working_dir}路径下 + - 解压 + ```shell + cd ${working_dir} + mkdir MindIE-LLM + cd MindIE-LLM + tar -zxvf ../Ascend-mindie-atb-models_*_linux-*_torch*-abi*.tar.gz + ``` + - 安装atb_llm whl包 + ``` + cd ${working_dir}/MindIE-LLM + # 首次安装 + pip install atb_llm-0.0.1-py3-none-any.whl + # 更新 + pip install atb_llm-0.0.1-py3-none-any.whl --force-reinstall + ``` + + +## 纯模型推理 + +### 对话测试 +进入llm_model路径 + +```shell +cd $ATB_SPEED_HOME_PATH +``` + +执行对话测试 +-非量化场景 +```shell +python -m examples.run_fa_edge \ + --model_path ${权重路径} \ + --input_text 'What is deep learning?' \ + --max_output_length 20 \ + --is_chat_model \ +``` +## 声明 +- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。 +- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。 \ No newline at end of file -- Gitee From 68fc3097d711dd67f995d37d803e45f212d8d129 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:37:19 +0000 Subject: [PATCH 21/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/{README => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/{README => README.md} (100%) diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md similarity index 100% rename from MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README rename to MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md -- Gitee From e707e2a8f0c4761f7035feae279679810b4836bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:38:43 +0000 Subject: [PATCH 22/42] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Qwen3-1.7B-OrangePi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep diff --git a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From 75a4a03e858b9aa281839c56530987304e7b6908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:39:52 +0000 Subject: [PATCH 23/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0Qwen3-1.7B-OrangePi=20R?= =?UTF-8?q?EADME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep | 0 .../LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md | 181 ++++++++++++++++++ 2 files changed, 181 insertions(+) delete mode 100644 MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep create mode 100644 MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md diff --git a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md new file mode 100644 index 0000000000..c1ffecc9ef --- /dev/null +++ b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md @@ -0,0 +1,181 @@ +# Qwen3-1.7B-OrangePi +## 简介 +Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混合专家(MoE)模型的全面套件。基于广泛的训练,Qwen3在推理、指令遵循、代理功能和多语言支持方面取得了很大的进展,主要具有以下功能: + +- **思维模式**(用于复杂的逻辑推理、数学和编码)和**非思维模式**(用于高效、通用的对话)在单个模型内无缝切换,确保跨各种场景的最佳性能。 +- **增强了推理能力**在数学、代码生成和常识逻辑推理方面超过了之前的QwQ(思维模式)和Qwen2.5(非思维模式)。 +- **人类偏好调整**,擅长创意写作、角色扮演、多轮对话和指令跟随,提供更自然、更吸引人、更沉浸式的对话体验。 +- **在代理能力方面的专业知识**,能够在思考模式和非思考模式下与外部工具精确集成,在基于代理的复杂任务中实现开源模型中的领先性能。 +- **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 + +## 约束条件 +* 在20t24g 香橙派aipro上部署Qwen3-1.7B模型 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 由于此硬件为单卡,仅支持TP=1 + +## 权重 + +**权重下载** + +- [Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B/tree/main) + +## 新建环境 + +### 1.1 安装CANN +- CANN-kernels[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-kernels-310b_8.1.RC1_linux-aarch64.run) +- CANN-toolkit[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-toolkit_8.1.RC1_linux-aarch64.run) +- 安装顺序:先安装toolkit 再安装kernel + +#### 1.1.1 安装toolkit + +- 下载 + +| cpu | 包名(其中`${version}`为实际版本) | +| ------- | ------------------------------------------------ | +| aarch64 | Ascend-cann-toolkit_${version}_linux-aarch64.run | + +- 安装 + ```bash + # 安装toolkit 以arm为例 + chmod +x Ascend-cann-toolkit_${version}_linux-aarch64.run + ./Ascend-cann-toolkit_${version}_linux-aarch64.run --install + source /usr/local/Ascend/ascend-toolkit/set_env.sh + ``` + +#### 1.1.2 安装kernel + +- 下载 + +| 包名 | +| ------------------------------------------ | +| Ascend-cann-kernels*_${version}_linux.run | + + - 根据芯片型号选择对应的安装包 + +- 安装 + ```bash + chmod +x Ascend-cann-kernels-*_${version}_linux.run + ./Ascend-cann-kernels-*_${version}_linux.run --install + ``` + +#### 1.1.3 安装加速库 +- 下载加速库 + - [下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-nnal_8.1.RC1_linux-aarch64.run)。 + + | 包名(其中`${version}`为实际版本) | + | -------------------------------------------- | + | Ascend-cann-nnal_${version}_linux-aarch64.run | + | ... | + + - 将文件放置在\${working_dir}路径下 + +- 安装 + ```shell + chmod +x Ascend-cann-nnal_*_linux-*.run + ./Ascend-cann-nnal_*_linux-*.run --install --install-path=${working_dir} + source ${working_dir}/nnal/atb/set_env.sh + ``` +- 可以使用`uname -a`指令查看服务器是x86还是aarch架构 +- 可以使用以下指令查看abi是0还是1 + ```shell + python -c "import torch; print(torch.compiled_with_cxx11_abi())" + ``` + - 若输出结果为True表示abi1,False表示abi0 + +### 1.2 安装PytorchAdapter + +先安装torch 再安装torch_npu + +#### 1.2.1 安装torch + +- 下载 + + | 包名 | + | -------------------------------------------- | + | torch-2.1.0-cp310-cp10-linux_aarch64.whl | + | ... | + + - 根据所使用的环境中的python版本以及cpu类型,选择对应版本的torch安装包。 + +- 安装 + ```bash + # 安装torch 2.1.0 的python 3.10 的arm版本为例 + pip install torch-2.1.0-cp310-cp310-linux_aarch64.whl + ``` + +#### 1.2.2 安装torch_npu + +[下载PyTorch Adapter](https://www.hiascend.com/developer/download/community/result?module=pt),安装方法: + +| 包名 | +| --------------------------- | +| pytorch_v2.1.0_py38.tar.gz | +| pytorch_v2.1.0_py39.tar.gz | +| pytorch_v2.1.0_py310.tar.gz | +| ... | + +- 安装选择与torch版本以及python版本一致的npu_torch版本 + +```bash +# 安装 torch_npu,以 torch 2.1.0,python 3.10 的版本为例 +tar -zxvf pytorch_v2.1.0_py310.tar.gz +pip install torch*_aarch64.whl +``` +### 1.3 安装开源软件依赖 +| 默认依赖 | [requirement.txt](./requirements.txt) | +- 开源软件依赖请使用下述命令进行安装: + ```bash + pip install -r ./requirements.txt + ``` + +### 1.4 安装模型仓 +使用编译好的包进行安装 + - 下载编译好的包 + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi0.tar.gz) + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi1.tar.gz) + + | 包名 | + | ------------------------------------------------------------ | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch1.11.0-abi0.tar.gz | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch2.1.0-abi1.tar.gz | + | ... | + + - 将文件放置在\${working_dir}路径下 + - 解压 + ```shell + cd ${working_dir} + mkdir MindIE-LLM + cd MindIE-LLM + tar -zxvf ../Ascend-mindie-atb-models_*_linux-*_torch*-abi*.tar.gz + ``` + - 安装atb_llm whl包 + ``` + cd ${working_dir}/MindIE-LLM + # 首次安装 + pip install atb_llm-0.0.1-py3-none-any.whl + # 更新 + pip install atb_llm-0.0.1-py3-none-any.whl --force-reinstall + ``` + + +## 纯模型推理 + +### 对话测试 +进入llm_model路径 + +```shell +cd $ATB_SPEED_HOME_PATH +``` + +执行对话测试 +-非量化场景 +```shell +python -m examples.run_fa_edge \ + --model_path ${权重路径} \ + --input_text 'What is deep learning?' \ + --max_output_length 20 \ + --is_chat_model \ +``` +## 声明 +- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。 +- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。 \ No newline at end of file -- Gitee From a2d64857a1e8982879d5b4ff5b0a8756576b2491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:43:36 +0000 Subject: [PATCH 24/42] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Qwen3-4B-OrangePi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep diff --git a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From 54abe4ba70fc3180c8de299d8189a8fe5c673210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 07:44:31 +0000 Subject: [PATCH 25/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0Qwen3-4B-OrangePi=20REA?= =?UTF-8?q?DME?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep | 0 MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md | 181 +++++++++++++++++++ 2 files changed, 181 insertions(+) delete mode 100644 MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep create mode 100644 MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md diff --git a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md new file mode 100644 index 0000000000..24fbe8178f --- /dev/null +++ b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md @@ -0,0 +1,181 @@ +# Qwen3-4B-OrangePi +## 简介 +Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混合专家(MoE)模型的全面套件。基于广泛的训练,Qwen3在推理、指令遵循、代理功能和多语言支持方面取得了很大的进展,主要具有以下功能: + +- **思维模式**(用于复杂的逻辑推理、数学和编码)和**非思维模式**(用于高效、通用的对话)在单个模型内无缝切换,确保跨各种场景的最佳性能。 +- **增强了推理能力**在数学、代码生成和常识逻辑推理方面超过了之前的QwQ(思维模式)和Qwen2.5(非思维模式)。 +- **人类偏好调整**,擅长创意写作、角色扮演、多轮对话和指令跟随,提供更自然、更吸引人、更沉浸式的对话体验。 +- **在代理能力方面的专业知识**,能够在思考模式和非思考模式下与外部工具精确集成,在基于代理的复杂任务中实现开源模型中的领先性能。 +- **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 + +## 约束条件 +* 在20t24g 香橙派aipro上部署Qwen3-4B模型 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 由于此硬件为单卡,仅支持TP=1 + +## 权重 + +**权重下载** + +- [Qwen3-4B](https://huggingface.co/Qwen/Qwen3-4B/tree/main) + +## 新建环境 + +### 1.1 安装CANN +- CANN-kernels[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-kernels-310b_8.1.RC1_linux-aarch64.run) +- CANN-toolkit[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-toolkit_8.1.RC1_linux-aarch64.run) +- 安装顺序:先安装toolkit 再安装kernel + +#### 1.1.1 安装toolkit + +- 下载 + +| cpu | 包名(其中`${version}`为实际版本) | +| ------- | ------------------------------------------------ | +| aarch64 | Ascend-cann-toolkit_${version}_linux-aarch64.run | + +- 安装 + ```bash + # 安装toolkit 以arm为例 + chmod +x Ascend-cann-toolkit_${version}_linux-aarch64.run + ./Ascend-cann-toolkit_${version}_linux-aarch64.run --install + source /usr/local/Ascend/ascend-toolkit/set_env.sh + ``` + +#### 1.1.2 安装kernel + +- 下载 + +| 包名 | +| ------------------------------------------ | +| Ascend-cann-kernels*_${version}_linux.run | + + - 根据芯片型号选择对应的安装包 + +- 安装 + ```bash + chmod +x Ascend-cann-kernels-*_${version}_linux.run + ./Ascend-cann-kernels-*_${version}_linux.run --install + ``` + +#### 1.1.3 安装加速库 +- 下载加速库 + - [下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-nnal_8.1.RC1_linux-aarch64.run)。 + + | 包名(其中`${version}`为实际版本) | + | -------------------------------------------- | + | Ascend-cann-nnal_${version}_linux-aarch64.run | + | ... | + + - 将文件放置在\${working_dir}路径下 + +- 安装 + ```shell + chmod +x Ascend-cann-nnal_*_linux-*.run + ./Ascend-cann-nnal_*_linux-*.run --install --install-path=${working_dir} + source ${working_dir}/nnal/atb/set_env.sh + ``` +- 可以使用`uname -a`指令查看服务器是x86还是aarch架构 +- 可以使用以下指令查看abi是0还是1 + ```shell + python -c "import torch; print(torch.compiled_with_cxx11_abi())" + ``` + - 若输出结果为True表示abi1,False表示abi0 + +### 1.2 安装PytorchAdapter + +先安装torch 再安装torch_npu + +#### 1.2.1 安装torch + +- 下载 + + | 包名 | + | -------------------------------------------- | + | torch-2.1.0-cp310-cp10-linux_aarch64.whl | + | ... | + + - 根据所使用的环境中的python版本以及cpu类型,选择对应版本的torch安装包。 + +- 安装 + ```bash + # 安装torch 2.1.0 的python 3.10 的arm版本为例 + pip install torch-2.1.0-cp310-cp310-linux_aarch64.whl + ``` + +#### 1.2.2 安装torch_npu + +[下载PyTorch Adapter](https://www.hiascend.com/developer/download/community/result?module=pt),安装方法: + +| 包名 | +| --------------------------- | +| pytorch_v2.1.0_py38.tar.gz | +| pytorch_v2.1.0_py39.tar.gz | +| pytorch_v2.1.0_py310.tar.gz | +| ... | + +- 安装选择与torch版本以及python版本一致的npu_torch版本 + +```bash +# 安装 torch_npu,以 torch 2.1.0,python 3.10 的版本为例 +tar -zxvf pytorch_v2.1.0_py310.tar.gz +pip install torch*_aarch64.whl +``` +### 1.3 安装开源软件依赖 +| 默认依赖 | [requirement.txt](./requirements.txt) | +- 开源软件依赖请使用下述命令进行安装: + ```bash + pip install -r ./requirements.txt + ``` + +### 1.4 安装模型仓 +使用编译好的包进行安装 + - 下载编译好的包 + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi0.tar.gz) + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi1.tar.gz) + + | 包名 | + | ------------------------------------------------------------ | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch1.11.0-abi0.tar.gz | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch2.1.0-abi1.tar.gz | + | ... | + + - 将文件放置在\${working_dir}路径下 + - 解压 + ```shell + cd ${working_dir} + mkdir MindIE-LLM + cd MindIE-LLM + tar -zxvf ../Ascend-mindie-atb-models_*_linux-*_torch*-abi*.tar.gz + ``` + - 安装atb_llm whl包 + ``` + cd ${working_dir}/MindIE-LLM + # 首次安装 + pip install atb_llm-0.0.1-py3-none-any.whl + # 更新 + pip install atb_llm-0.0.1-py3-none-any.whl --force-reinstall + ``` + + +## 纯模型推理 + +### 对话测试 +进入llm_model路径 + +```shell +cd $ATB_SPEED_HOME_PATH +``` + +执行对话测试 +-非量化场景 +```shell +python -m examples.run_fa_edge \ + --model_path ${权重路径} \ + --input_text 'What is deep learning?' \ + --max_output_length 20 \ + --is_chat_model \ +``` +## 声明 +- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。 +- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。 \ No newline at end of file -- Gitee From 39cff878e8a219bdc75c604fa6868a13f609e5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:11:24 +0000 Subject: [PATCH 26/42] update MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md index 1f798cef23..36af169061 100644 --- a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md @@ -10,7 +10,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 ## 约束条件 * 在20t24g 香橙派aipro上部署Qwen3-0.6B模型 -* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 ## 权重 -- Gitee From 94ddcd4219fb582f4bcb1b9cc010f75de80f9644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:11:42 +0000 Subject: [PATCH 27/42] update MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md index c1ffecc9ef..f6a070245f 100644 --- a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md @@ -10,7 +10,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 ## 约束条件 * 在20t24g 香橙派aipro上部署Qwen3-1.7B模型 -* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 ## 权重 -- Gitee From 34fb95d2e1f9d61f5b429a9af7acca2831291a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:11:58 +0000 Subject: [PATCH 28/42] update MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md index 24fbe8178f..b5529e122d 100644 --- a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md @@ -10,7 +10,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 ## 约束条件 * 在20t24g 香橙派aipro上部署Qwen3-4B模型 -* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 ## 权重 -- Gitee From eafc8f4df971aee35dda11503a34bbc451329565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:51:48 +0000 Subject: [PATCH 29/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Janus-Pro-1B-OrangePi/ pyproject.toml | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml deleted file mode 100644 index ee6d7ee3d7..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/ pyproject.toml +++ /dev/null @@ -1,53 +0,0 @@ -[build-system] -requires = ["setuptools>=40.6.0", "wheel"] -build-backend = "setuptools.build_meta" - -[project] -name = "janus" -version = "1.0.0" -description = "Janus" -authors = [{name = "DeepSeek-AI"}] -license = {file = "LICENSE-CODE"} -urls = {homepage = "https://github.com/deepseek-ai/Janus"} -readme = "README.md" -requires-python = ">=3.8" -dependencies = [ - "torch>=2.0.1", - "transformers>=4.38.2", - "timm>=0.9.16", - "accelerate", - "sentencepiece", - "attrdict", - "einops", -] - -[project.optional-dependencies] -gradio = [ - "gradio==3.48.0", - "gradio-client==0.6.1", - "mdtex2html==1.3.0", - "pypinyin==0.50.0", - "tiktoken==0.5.2", - "tqdm==4.64.0", - "colorama==0.4.5", - "Pygments==2.12.0", - "markdown==3.4.1", - "SentencePiece==0.1.96" -] -lint = [ - "isort", - "black[jupyter] >= 22.6.0", - "pylint[spelling] >= 2.15.0", - "flake8", - "flake8-bugbear", - "flake8-comprehensions", - "flake8-docstrings", - "flake8-pyi", - "flake8-simplify", - "ruff", - "pyenchant", - "pre-commit", -] - -[tool.setuptools] -packages = {find = {exclude = ["images"]}} -- Gitee From 43c5e1135bf069de8b418c95806d0ed117f57cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:52:13 +0000 Subject: [PATCH 30/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MultiModal/Janus-Pro-1B-OrangePi/Makefile | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile deleted file mode 100644 index 493ded435b..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/Makefile +++ /dev/null @@ -1,99 +0,0 @@ -print-% : ; @echo $* = $($*) -PROJECT_NAME = Janus -COPYRIGHT = "DeepSeek." -PROJECT_PATH = janus -SHELL = /bin/bash -SOURCE_FOLDERS = janus -PYTHON_FILES = $(shell find $(SOURCE_FOLDERS) -type f -name "*.py" -o -name "*.pyi") inference.py -COMMIT_HASH = $(shell git log -1 --format=%h) -PATH := $(HOME)/go/bin:$(PATH) -PYTHON ?= $(shell command -v python3 || command -v python) -PYTESTOPTS ?= - -.PHONY: default -default: install - -# Tools Installation - -check_pip_install = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(1) --upgrade) -check_pip_install_extra = $(PYTHON) -m pip show $(1) &>/dev/null || (cd && $(PYTHON) -m pip install $(2) --upgrade) - -pylint-install: - $(call check_pip_install_extra,pylint,pylint[spelling]) - $(call check_pip_install,pyenchant) - -flake8-install: - $(call check_pip_install,flake8) - $(call check_pip_install,flake8-bugbear) - $(call check_pip_install,flake8-comprehensions) - $(call check_pip_install,flake8-docstrings) - $(call check_pip_install,flake8-pyi) - $(call check_pip_install,flake8-simplify) - -py-format-install: - $(call check_pip_install,isort) - $(call check_pip_install_extra,black,black[jupyter]) - -ruff-install: - $(call check_pip_install,ruff) - -mypy-install: - $(call check_pip_install,mypy) - -pre-commit-install: - $(call check_pip_install,pre-commit) - $(PYTHON) -m pre_commit install --install-hooks - -go-install: - # requires go >= 1.16 - command -v go || (sudo apt-get install -y golang && sudo ln -sf /usr/lib/go/bin/go /usr/bin/go) - -addlicense-install: go-install - command -v addlicense || go install github.com/google/addlicense@latest - -addlicense: addlicense-install - addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l mit -y 2023-$(shell date +"%Y") -check $(SOURCE_FOLDERS) - -# Python linters - -pylint: pylint-install - $(PYTHON) -m pylint $(PROJECT_PATH) - -flake8: flake8-install - $(PYTHON) -m flake8 --count --show-source --statistics - -py-format: py-format-install - $(PYTHON) -m isort --project $(PROJECT_PATH) --check $(PYTHON_FILES) && \ - $(PYTHON) -m black --check $(PYTHON_FILES) - -black-format: py-format-install - $(PYTHON) -m black --check $(PYTHON_FILES) - -ruff: ruff-install - $(PYTHON) -m ruff check . - -ruff-fix: ruff-install - $(PYTHON) -m ruff check . --fix --exit-non-zero-on-fix - -mypy: mypy-install - $(PYTHON) -m mypy $(PROJECT_PATH) --install-types --non-interactive - -pre-commit: pre-commit-install - $(PYTHON) -m pre_commit run --all-files - -# Utility functions - -lint: ruff flake8 py-format mypy pylint addlicense - -format: py-format-install ruff-install addlicense-install - $(PYTHON) -m isort --project $(PROJECT_PATH) $(PYTHON_FILES) - $(PYTHON) -m black $(PYTHON_FILES) - addlicense -c $(COPYRIGHT) -ignore tests/coverage.xml -l mit -y 2023-$(shell date +"%Y") $(SOURCE_FOLDERS) inference.py - -clean-py: - find . -type f -name '*.py[co]' -delete - find . -depth -type d -name "__pycache__" -exec rm -r "{}" + - find . -depth -type d -name ".ruff_cache" -exec rm -r "{}" + - find . -depth -type d -name ".mypy_cache" -exec rm -r "{}" + - -clean: clean-py -- Gitee From 328a3bfa39b5a6441a24f6fb8414aaa543362aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:54:30 +0000 Subject: [PATCH 31/42] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Llama3.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindIE/LLM/Llama3.2/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MindIE/LLM/Llama3.2/.keep diff --git a/MindIE/LLM/Llama3.2/.keep b/MindIE/LLM/Llama3.2/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From d52cda36ee9bb7664e2af2a147e718b291d9e14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 08:56:40 +0000 Subject: [PATCH 32/42] update MindIE/LLM/Llama3.2/.keep. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Llama3.2/{.keep => Llama3.2-1B-Instruct-OrangePi/README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename MindIE/LLM/Llama3.2/{.keep => Llama3.2-1B-Instruct-OrangePi/README.md} (100%) diff --git a/MindIE/LLM/Llama3.2/.keep b/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md similarity index 100% rename from MindIE/LLM/Llama3.2/.keep rename to MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md -- Gitee From fee336ad8f61f418d507ca0de3ae504dbbb4c1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 09:00:14 +0000 Subject: [PATCH 33/42] update MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Llama3.2-1B-Instruct-OrangePi/README.md | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) diff --git a/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md b/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md index e69de29bb2..822ef46887 100644 --- a/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md +++ b/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md @@ -0,0 +1,173 @@ +# Llama3.2-1B-Instruct-OrangePi + +## 约束条件 +* 在20t24g 香橙派aipro上部署Llama3.2-1B-Instruct模型 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 由于此硬件为单卡,仅支持TP=1 + +## 权重 + +**权重下载** + +- [Llama3.2-1B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-1B-Instruct/tree/main) + +## 新建环境 + +### 1.1 安装CANN +- CANN-kernels[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-kernels-310b_8.1.RC1_linux-aarch64.run) +- CANN-toolkit[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-toolkit_8.1.RC1_linux-aarch64.run) +- 安装顺序:先安装toolkit 再安装kernel + +#### 1.1.1 安装toolkit + +- 下载 + +| cpu | 包名(其中`${version}`为实际版本) | +| ------- | ------------------------------------------------ | +| aarch64 | Ascend-cann-toolkit_${version}_linux-aarch64.run | + +- 安装 + ```bash + # 安装toolkit 以arm为例 + chmod +x Ascend-cann-toolkit_${version}_linux-aarch64.run + ./Ascend-cann-toolkit_${version}_linux-aarch64.run --install + source /usr/local/Ascend/ascend-toolkit/set_env.sh + ``` + +#### 1.1.2 安装kernel + +- 下载 + +| 包名 | +| ------------------------------------------ | +| Ascend-cann-kernels*_${version}_linux.run | + + - 根据芯片型号选择对应的安装包 + +- 安装 + ```bash + chmod +x Ascend-cann-kernels-*_${version}_linux.run + ./Ascend-cann-kernels-*_${version}_linux.run --install + ``` + +#### 1.1.3 安装加速库 +- 下载加速库 + - [下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-nnal_8.1.RC1_linux-aarch64.run)。 + + | 包名(其中`${version}`为实际版本) | + | -------------------------------------------- | + | Ascend-cann-nnal_${version}_linux-aarch64.run | + | ... | + + - 将文件放置在\${working_dir}路径下 + +- 安装 + ```shell + chmod +x Ascend-cann-nnal_*_linux-*.run + ./Ascend-cann-nnal_*_linux-*.run --install --install-path=${working_dir} + source ${working_dir}/nnal/atb/set_env.sh + ``` +- 可以使用`uname -a`指令查看服务器是x86还是aarch架构 +- 可以使用以下指令查看abi是0还是1 + ```shell + python -c "import torch; print(torch.compiled_with_cxx11_abi())" + ``` + - 若输出结果为True表示abi1,False表示abi0 + +### 1.2 安装PytorchAdapter + +先安装torch 再安装torch_npu + +#### 1.2.1 安装torch + +- 下载 + + | 包名 | + | -------------------------------------------- | + | torch-2.1.0-cp310-cp10-linux_aarch64.whl | + | ... | + + - 根据所使用的环境中的python版本以及cpu类型,选择对应版本的torch安装包。 + +- 安装 + ```bash + # 安装torch 2.1.0 的python 3.10 的arm版本为例 + pip install torch-2.1.0-cp310-cp310-linux_aarch64.whl + ``` + +#### 1.2.2 安装torch_npu + +[下载PyTorch Adapter](https://www.hiascend.com/developer/download/community/result?module=pt),安装方法: + +| 包名 | +| --------------------------- | +| pytorch_v2.1.0_py38.tar.gz | +| pytorch_v2.1.0_py39.tar.gz | +| pytorch_v2.1.0_py310.tar.gz | +| ... | + +- 安装选择与torch版本以及python版本一致的npu_torch版本 + +```bash +# 安装 torch_npu,以 torch 2.1.0,python 3.10 的版本为例 +tar -zxvf pytorch_v2.1.0_py310.tar.gz +pip install torch*_aarch64.whl +``` +### 1.3 安装开源软件依赖 +| 默认依赖 | [requirement.txt](./requirements.txt) | +- 开源软件依赖请使用下述命令进行安装: + ```bash + pip install -r ./requirements.txt + ``` + +### 1.4 安装模型仓 +使用编译好的包进行安装 + - 下载编译好的包 + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi0.tar.gz) + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi1.tar.gz) + + | 包名 | + | ------------------------------------------------------------ | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch1.11.0-abi0.tar.gz | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch2.1.0-abi1.tar.gz | + | ... | + + - 将文件放置在\${working_dir}路径下 + - 解压 + ```shell + cd ${working_dir} + mkdir MindIE-LLM + cd MindIE-LLM + tar -zxvf ../Ascend-mindie-atb-models_*_linux-*_torch*-abi*.tar.gz + ``` + - 安装atb_llm whl包 + ``` + cd ${working_dir}/MindIE-LLM + # 首次安装 + pip install atb_llm-0.0.1-py3-none-any.whl + # 更新 + pip install atb_llm-0.0.1-py3-none-any.whl --force-reinstall + ``` + + +## 纯模型推理 + +### 对话测试 +进入llm_model路径 + +```shell +cd $ATB_SPEED_HOME_PATH +``` + +执行对话测试 +-非量化场景 +```shell +python -m examples.run_fa_edge \ + --model_path ${权重路径} \ + --input_text 'What is deep learning?' \ + --max_output_length 20 \ + --is_chat_model \ +``` +## 声明 +- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。 +- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。 \ No newline at end of file -- Gitee From fb266ca6925bbc06b2c21096681d5b7cb54ca148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 09:00:58 +0000 Subject: [PATCH 34/42] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20Llama3.2-3B-Instruct?= =?UTF-8?q?-OrangePi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep diff --git a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep new file mode 100644 index 0000000000..e69de29bb2 -- Gitee From f1bf69cc82b332208627f369d565beca64dd12ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 09:02:17 +0000 Subject: [PATCH 35/42] =?UTF-8?q?=E6=9B=B4=E6=96=B0llama3.2-3b-instruct=20?= =?UTF-8?q?README?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- .../Llama3.2-3B-Instruct-OrangePi/.keep | 0 .../Llama3.2-3B-Instruct-OrangePi/README.md | 173 ++++++++++++++++++ 2 files changed, 173 insertions(+) delete mode 100644 MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep create mode 100644 MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md diff --git a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/.keep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md new file mode 100644 index 0000000000..52ab823b2a --- /dev/null +++ b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md @@ -0,0 +1,173 @@ +# Llama3.2-1B-Instruct-OrangePi + +## 约束条件 +* 在20t24g 香橙派aipro上部署Llama3.2-3B-Instruct模型 +* 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 +* 由于此硬件为单卡,仅支持TP=1 + +## 权重 + +**权重下载** + +- [Llama3.2-3B-Instruct](https://huggingface.co/meta-llama/Llama-3.2-3B-Instruct/tree/main) + +## 新建环境 + +### 1.1 安装CANN +- CANN-kernels[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-kernels-310b_8.1.RC1_linux-aarch64.run) +- CANN-toolkit[下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-toolkit_8.1.RC1_linux-aarch64.run) +- 安装顺序:先安装toolkit 再安装kernel + +#### 1.1.1 安装toolkit + +- 下载 + +| cpu | 包名(其中`${version}`为实际版本) | +| ------- | ------------------------------------------------ | +| aarch64 | Ascend-cann-toolkit_${version}_linux-aarch64.run | + +- 安装 + ```bash + # 安装toolkit 以arm为例 + chmod +x Ascend-cann-toolkit_${version}_linux-aarch64.run + ./Ascend-cann-toolkit_${version}_linux-aarch64.run --install + source /usr/local/Ascend/ascend-toolkit/set_env.sh + ``` + +#### 1.1.2 安装kernel + +- 下载 + +| 包名 | +| ------------------------------------------ | +| Ascend-cann-kernels*_${version}_linux.run | + + - 根据芯片型号选择对应的安装包 + +- 安装 + ```bash + chmod +x Ascend-cann-kernels-*_${version}_linux.run + ./Ascend-cann-kernels-*_${version}_linux.run --install + ``` + +#### 1.1.3 安装加速库 +- 下载加速库 + - [下载链接](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-cann-nnal_8.1.RC1_linux-aarch64.run)。 + + | 包名(其中`${version}`为实际版本) | + | -------------------------------------------- | + | Ascend-cann-nnal_${version}_linux-aarch64.run | + | ... | + + - 将文件放置在\${working_dir}路径下 + +- 安装 + ```shell + chmod +x Ascend-cann-nnal_*_linux-*.run + ./Ascend-cann-nnal_*_linux-*.run --install --install-path=${working_dir} + source ${working_dir}/nnal/atb/set_env.sh + ``` +- 可以使用`uname -a`指令查看服务器是x86还是aarch架构 +- 可以使用以下指令查看abi是0还是1 + ```shell + python -c "import torch; print(torch.compiled_with_cxx11_abi())" + ``` + - 若输出结果为True表示abi1,False表示abi0 + +### 1.2 安装PytorchAdapter + +先安装torch 再安装torch_npu + +#### 1.2.1 安装torch + +- 下载 + + | 包名 | + | -------------------------------------------- | + | torch-2.1.0-cp310-cp10-linux_aarch64.whl | + | ... | + + - 根据所使用的环境中的python版本以及cpu类型,选择对应版本的torch安装包。 + +- 安装 + ```bash + # 安装torch 2.1.0 的python 3.10 的arm版本为例 + pip install torch-2.1.0-cp310-cp310-linux_aarch64.whl + ``` + +#### 1.2.2 安装torch_npu + +[下载PyTorch Adapter](https://www.hiascend.com/developer/download/community/result?module=pt),安装方法: + +| 包名 | +| --------------------------- | +| pytorch_v2.1.0_py38.tar.gz | +| pytorch_v2.1.0_py39.tar.gz | +| pytorch_v2.1.0_py310.tar.gz | +| ... | + +- 安装选择与torch版本以及python版本一致的npu_torch版本 + +```bash +# 安装 torch_npu,以 torch 2.1.0,python 3.10 的版本为例 +tar -zxvf pytorch_v2.1.0_py310.tar.gz +pip install torch*_aarch64.whl +``` +### 1.3 安装开源软件依赖 +| 默认依赖 | [requirement.txt](./requirements.txt) | +- 开源软件依赖请使用下述命令进行安装: + ```bash + pip install -r ./requirements.txt + ``` + +### 1.4 安装模型仓 +使用编译好的包进行安装 + - 下载编译好的包 + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi0.tar.gz) + - [下载链接-abi0](https://mindie.obs.cn-north-4.myhuaweicloud.com/xiangchengpai_20250211/Ascend-mindie-atb-models_2.0.RC1_linux-aarch64_py310_torch2.1.0-abi1.tar.gz) + + | 包名 | + | ------------------------------------------------------------ | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch1.11.0-abi0.tar.gz | + | Ascend-mindie-atb-models_1.0.RC1_linux-aarch64_torch2.1.0-abi1.tar.gz | + | ... | + + - 将文件放置在\${working_dir}路径下 + - 解压 + ```shell + cd ${working_dir} + mkdir MindIE-LLM + cd MindIE-LLM + tar -zxvf ../Ascend-mindie-atb-models_*_linux-*_torch*-abi*.tar.gz + ``` + - 安装atb_llm whl包 + ``` + cd ${working_dir}/MindIE-LLM + # 首次安装 + pip install atb_llm-0.0.1-py3-none-any.whl + # 更新 + pip install atb_llm-0.0.1-py3-none-any.whl --force-reinstall + ``` + + +## 纯模型推理 + +### 对话测试 +进入llm_model路径 + +```shell +cd $ATB_SPEED_HOME_PATH +``` + +执行对话测试 +-非量化场景 +```shell +python -m examples.run_fa_edge \ + --model_path ${权重路径} \ + --input_text 'What is deep learning?' \ + --max_output_length 20 \ + --is_chat_model \ +``` +## 声明 +- 本代码仓提到的数据集和模型仅作为示例,这些数据集和模型仅供您用于非商业目的,如您使用这些数据集和模型来完成示例,请您特别注意应遵守对应数据集和模型的License,如您因使用数据集或模型而产生侵权纠纷,华为不承担任何责任。 +- 如您在使用本代码仓的过程中,发现任何问题(包括但不限于功能问题、合规问题),请在本代码仓提交issue,我们将及时审视并解答。 \ No newline at end of file -- Gitee From 8d60d72aaead00f65e403cda7b0218d8891fa9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Mon, 9 Jun 2025 09:05:16 +0000 Subject: [PATCH 36/42] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20Mi?= =?UTF-8?q?ndIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Janus-Pro-1B-OrangePi/LICENSE-CODE | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE diff --git a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE b/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE deleted file mode 100644 index 6eca5dda82..0000000000 --- a/MindIE/MultiModal/Janus-Pro-1B-OrangePi/LICENSE-CODE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2023 DeepSeek - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -- Gitee From 8f98c18dceaedea85e675f4527ba48e427b0bcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:28:47 +0000 Subject: [PATCH 37/42] update MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md index b5529e122d..1d39b06303 100644 --- a/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-4B-OrangePi/README.md @@ -9,7 +9,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 - **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 ## 约束条件 -* 在20t24g 香橙派aipro上部署Qwen3-4B模型 +* 在OrangePi AIpro(20T)上部署Qwen3-4B模型 * 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 -- Gitee From a78ab074c1ecf0d1aa62048969b0d891d51f79e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:29:05 +0000 Subject: [PATCH 38/42] update MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md index f6a070245f..e637d94981 100644 --- a/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-1.7B-OrangePi/README.md @@ -9,7 +9,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 - **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 ## 约束条件 -* 在20t24g 香橙派aipro上部署Qwen3-1.7B模型 +* 在OrangePi AIpro(20T)上部署Qwen3-1.7B模型 * 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 -- Gitee From b777b6b2953e81c39b5061968142db202d9ce246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:29:27 +0000 Subject: [PATCH 39/42] update MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md index 36af169061..0a995767c1 100644 --- a/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md +++ b/MindIE/LLM/Qwen3/Qwen3-0.6B-OrangePi/README.md @@ -9,7 +9,7 @@ Qwen3是Qwen系列中最新一代的大型语言模型,提供了密集和混 - **支持100多种语言和方言***具有强大多语言教学能力和翻译能力。 ## 约束条件 -* 在20t24g 香橙派aipro上部署Qwen3-0.6B模型 +* 在OrangePi AIpro(20T)上部署Qwen3-0.6B模型 * 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096, 删除“rope_scaling”字段 * 由于此硬件为单卡,仅支持TP=1 -- Gitee From ab1ac52a13a5caf9aabc489f01ee6d573ce4d56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:29:47 +0000 Subject: [PATCH 40/42] update MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md b/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md index 822ef46887..2bdadd8232 100644 --- a/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md +++ b/MindIE/LLM/Llama3.2/Llama3.2-1B-Instruct-OrangePi/README.md @@ -1,7 +1,7 @@ # Llama3.2-1B-Instruct-OrangePi ## 约束条件 -* 在20t24g 香橙派aipro上部署Llama3.2-1B-Instruct模型 +* 在OrangePi AIpro(20T)上部署Llama3.2-1B-Instruct模型 * 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 * 由于此硬件为单卡,仅支持TP=1 -- Gitee From eaaacad8b7ca42b23a9b1d8743cc1618b0eb12dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:30:00 +0000 Subject: [PATCH 41/42] update MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md index 52ab823b2a..1e3c2daf97 100644 --- a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md +++ b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md @@ -1,7 +1,7 @@ # Llama3.2-1B-Instruct-OrangePi ## 约束条件 -* 在20t24g 香橙派aipro上部署Llama3.2-3B-Instruct模型 +* 在OrangePi AIpro(20T)上部署Llama3.2-3B-Instruct模型 * 需要修改权重目录下的config.json文件,"torch_dtype"字段改为"float16", "max_position_embedding"字段改为4096 * 由于此硬件为单卡,仅支持TP=1 -- Gitee From 23061fcdd76443fb22e8de6effeae45392a03f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=92=E6=A3=92=E9=94=A4?= Date: Tue, 10 Jun 2025 01:55:00 +0000 Subject: [PATCH 42/42] update MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 棒棒锤 --- MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md index 1e3c2daf97..896bee4ea4 100644 --- a/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md +++ b/MindIE/LLM/Llama3.2/Llama3.2-3B-Instruct-OrangePi/README.md @@ -1,4 +1,4 @@ -# Llama3.2-1B-Instruct-OrangePi +# Llama3.2-3B-Instruct-OrangePi ## 约束条件 * 在OrangePi AIpro(20T)上部署Llama3.2-3B-Instruct模型 -- Gitee