explain this page like i am a layperson : ""Skip to content intel / neural-speed Type /…
- User
explain this page like i am a layperson
: ""Skip to content intel / neural-speed
Type / to search
Code Issues 8 Pull requests 11 Actions Projects Security Insights Owner avatar neural-speed Public intel/neural-speed Go to file t Add file Folders and files Name Latest commit Zhenzhong1 Zhenzhong1 Update convert_chatglm.py (#185) 1051182 · 4 days ago History .github [BesTLA] New thread pool and hybrid dispatcher (#118) 3 weeks ago bestla mha enhance (#180) last week docker add docker file and readme (#14) 3 months ago docs Gemma-7b&&Gemma-2b (#171) 4 days ago neural_speed Update convert_chatglm.py (#185) 4 days ago scripts [Model Enabling] Support ChatGLM3 (#182) 5 days ago tests Gemma-7b&&Gemma-2b (#171) 4 days ago third_party reorg directory 3 months ago .clang-format update readme path and copy hidden files (#185) 3 months ago .clang-tidy [Neural Speed] Cont Batching in Offline and Server (GPT-J & Beam Sear… 2 months ago .editorconfig update readme path and copy hidden files (#185) 3 months ago .gitignore fix clang-tidy issues (#123) last month .gitmodules reorg directory 3 months ago .pre-commit-config.yaml enable pre-commit CI (#113) last month CMakeLists.txt [BesTLA] New thread pool and hybrid dispatcher (#118) 3 weeks ago CMakePresets.json [BesTLA] New thread pool and hybrid dispatcher (#118) 3 weeks ago CODE_OF_CONDUCT.md add code_of_conduct, contributing agreement, and security.md file 4 months ago CONTRIBUTING.md add code_of_conduct, contributing agreement, and security.md file 4 months ago LICENSE add license file (#34) 2 months ago README.md Improve readme (#166) 2 weeks ago clang-format.py Init ns doc (#9) 3 months ago developer_document.md [Runtime Enhence] Extend long input tokens length (#157) 2 weeks ago requirements.txt Improvements Targeting Windows (#136) last month security.md add code_of_conduct, contributing agreement, and security.md file 4 months ago setup.py Improvements Targeting Windows (#136) last month Repository files navigation README Code of conduct Apache-2.0 license Security Neural Speed Neural Speed is an innovative library designed to support the efficient inference of large language models (LLMs) on Intel platforms through the state-of-the-art (SOTA) low-bit quantization powered by Intel Neural Compressor. The work is inspired by llama.cpp and further optimized for Intel platforms with our innovations in NeurIPS' 2023
Key Features Highly optimized low-precision kernels on CPUs with ISAs (AMX, VNNI, AVX512F, AVX_VNNI and AVX2). See details Up to 40x performance speedup on popular LLMs compared with llama.cpp. See details Tensor parallelism across sockets/nodes on CPUs. See details Neural Speed is under active development so APIs are subject to change.
Supported Hardware Hardware Supported Intel Xeon Scalable Processors ✔ Intel Xeon CPU Max Series ✔ Intel Core Processors ✔ Supported Models Support almost all the LLMs in PyTorch format from Hugging Face such as Llama2, ChatGLM2, Baichuan2, Qwen, Mistral, Whisper, etc. File an issue if your favorite LLM does not work.
- Assistant
- User
breakdown and explain the following code like i am a layperson. I want to follow along: ""from transformers import AutoTokenizer, TextStreamer from intel_extension_for_transformers.transformers import AutoModelForCausalLM
Specify the GGUF repo on the Hugginface
model_name = "TheBloke/Llama-2-7B-Chat-GGUF"
Download the the specific gguf model file from the above repo
model_file = "llama-2-7b-chat.Q4_0.gguf"
make sure you are granted to access this model on the Huggingface.
tokenizer_name = "meta-llama/Llama-2-7b-chat-hf"
prompt = "Once upon a time" tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True) inputs = tokenizer(prompt, return_tensors="pt").input_ids streamer = TextStreamer(tokenizer) model = AutoModelForCausalLM.from_pretrained(model_name, model_file = model_file) outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)""
- Assistant
- User
do i need to download the model first?
- Assistant
No, you don't have to manually download the model first for the kind of code you're working with. When you're using libraries like
transformersand the Intel extension for transformers, they handle the downloading process for you, given that you have an internet connection and the necessary permissions.Here's a simple breakdown of how it works in your case:
-
Model and Tokenizer Setup: When you specify
model_nameandtokenizer_namein your code, you're giving thetransformerslibrary clear instructions on which model and tokenizer you want to use. -
Automatic Download: Upon running your code, if the model or tokenizer isn't already downloaded on your machine, the library will automatically reach out to the Hugging Face model repository, find the correct model and tokenizer you specified, and download them for you.
-
- User
what if i already have a model downloaded on my pc?
- Assistant
If you already have a model downloaded on your PC, you can still use it with the
transformerslibrary without needing to download it again. The library supports loading models from a local path on your system. Here’s how you can do it:-
Using a Local Model with Transformers: Instead of specifying the model's name from the Hugging Face repository, you would point to the local directory where the model is stored on your computer.
-
- User
i dont have the tokenizer file, only the gguf file. should i try to find one?
- Assistant
- User
- Assistant
- User
i'm using inte's neural speed to proces this model faster locally on my cpu. here is the github repo details: ""Neural Speed Neural Speed is an innovative library designed to support the efficient inference of large language models (LLMs) on Intel platforms through the state-of-the-art (SOTA) low-bit quantization powered by Intel Neural Compressor. The work is inspired by llama.cpp and further optimized for Intel platforms with our innovations in NeurIPS' 2023
Key Features Highly optimized low-precision kernels on CPUs with ISAs (AMX, VNNI, AVX512F, AVX_VNNI and AVX2). See details Up to 40x performance speedup on popular LLMs compared with llama.cpp. See details Tensor parallelism across sockets/nodes on CPUs. See details Neural Speed is under active development so APIs are subject to change.
Supported Hardware Hardware Supported Intel Xeon Scalable Processors ✔ Intel Xeon CPU Max Series ✔ Intel Core Processors ✔ Supported Models Support almost all the LLMs in PyTorch format from Hugging Face such as Llama2, ChatGLM2, Baichuan2, Qwen, Mistral, Whisper, etc. File an issue if your favorite LLM does not work.
Support typical LLMs in GGUF format such as Llama2, Falcon, MPT, Bloom etc. More are coming. Check out the details.""
- Assistant
- User
i've done the installation already: ""Installation Install from binary pip install neural-speed Build from Source pip install -r requirements.txt pip install .""
now i want to follow thier gide for ggug:
""GGUF Model from Hugging Face from transformers import AutoTokenizer, TextStreamer from intel_extension_for_transformers.transformers import AutoModelForCausalLM
Specify the GGUF repo on the Hugginface
model_name = "TheBloke/Llama-2-7B-Chat-GGUF"
Download the the specific gguf model file from the above repo
model_file = "llama-2-7b-chat.Q4_0.gguf"
make sure you are granted to access this model on the Huggingface.
tokenizer_name = "meta-llama/Llama-2-7b-chat-hf"
prompt = "Once upon a time" tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True) inputs = tokenizer(prompt, return_tensors="pt").input_ids streamer = TextStreamer(tokenizer) model = AutoModelForCausalLM.from_pretrained(model_name, model_file = model_file) outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)""
otherwise there is a ever faster quick start method:
Quick Start (llama.cpp-like usage) Single (One-click) Step python scripts/run.py model-path --weight_dtype int4 -p "She opened the door and see" ""
- Assistant
- User
i want to use the gguf from hugging face method but i want to use thid model: ""https://huggingface.co/mlabonne/AlphaMonarch-7B-GGUF""
this is the path to the downloaded model on my local drive: """C:\Users\bower.ollama\models\blobs\alphamonarch-7b\alphamonarch-7b.Q6_K.gguf"""
can you give me the full code to run it please?
- Assistant
- User
one moment. i just found this code snippet on the model repository page:
""!pip install -qU transformers accelerate
from transformers import AutoTokenizer import transformers import torch
model = "mlabonne/AlphaMonarch-7B" messages = [{"role": "user", "content": "What is a large language model?"}]
tokenizer = AutoTokenizer.from_pretrained(model) prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) pipeline = transformers.pipeline( "text-generation", model=model, torch_dtype=torch.float16, device_map="auto", )
outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95) print(outputs[0]["generated_text"]) ""
does this change our code in anyway? i still want to use the original code but this code from the model page might change some of our settings, right? btw i am using VS Code on windows for my syntax/code.
- Assistant
- User
how about this?:
""from transformers import AutoTokenizer, TextStreamer from intel_extension_for_transformers.transformers import AutoModelForCausalLM
Since you’re loading from a local file, specify the path directly
model_path = “C:/Users/bower/.ollama/models/blobs/alphamonarch-7b/alphamonarch-7b.Q6_K.gguf”
For the tokenizer, since it’s not specified which exact tokenizer
AlphaMonarch-7B uses, we’ll assume it has a compatible one on Hugging Face.
If AlphaMonarch-7B has a custom tokenizer, you might need to adjust this.
tokenizer_name = “mlabonne/AlphaMonarch-7B-GGUF” messages = [{"role": "user", "content": "What is a large language model?"}] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True) inputs = tokenizer(prompt, return_tensors=“pt”).input_ids streamer = TextStreamer(tokenizer)
Notice below, how we use from_pretrained differently for custom local models.
Since you’re using a .gguf file directly, ensure your Intel Neural Speed and
transformers setup supports it. If not directly supported, you might require
- Assistant
- User
well, the model author says that "This model uses a context window of 8k. I recommend using it with the Mistral Instruct chat template "
- Assistant
- User
one the mistral model page, the authors say this:
""This format is available as a chat template via the apply_chat_template() method:
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1") tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
messages = [ {"role": "user", "content": "What is your favourite condiment?"}, {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"}, {"role": "user", "content": "Do you have mayonnaise recipes?"} ]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
model_inputs = encodeds.to(device) model.to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True) decoded = tokenizer.batch_decode(generated_ids) print(decoded[0])""
- Assistant
- User
why do think i have access to cuda (i dont even know what that is). The reason i am using Neural Speed is because it is optimized for intel cpu core. see: " Neural Speed Neural Speed is an innovative library designed to support the efficient inference of large language models (LLMs) on Intel platforms through the state-of-the-art (SOTA) low-bit quantization powered by Intel Neural Compressor. The work is inspired by llama.cpp and further optimized for Intel platforms with our innovations in NeurIPS' 2023"
- Assistant
- User
i changed the code. is it right? :
""from transformers import AutoTokenizer, TextStreamer from intel_extension_for_transformers.transformers import AutoModelForCausalLM
Adjusting the path and model as per Neural Speed’s specifications
model_path = "C:/Users/bower/.ollama/models/blobs/alphamonarch-7b/alphamonarch-7b.Q6_K.gguf" tokenizer_name = "mlabonne/AlphaMonarch-7B-GGUF"
Messages prepared for conversation
messages = [ {"role": "user", "content": "What is a large language model?"}, {"role": "assistant", "content": "A large language model is a type of artificial intelligence model designed to understand, generate, and interpret human language."}, {"role": "user", "content": "Can you provide examples?"} ]
prompt = tokenizer(messages[-1][‘content’], return_tensors=“pt”, padding=True, truncation=True, max_length=512)
Initialize the tokenizer
tokenizer = AutoTokenizer.from_pretrained(model, trust_remote_code=True) inputs = tokenizer(prompt, return_tensors="pt").input_ids streamer = TextStreamer(tokenizer) model = AutoModelForCausalLM.from_pretrained(model_name, model_file = model_file) outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)""
- Assistant
- User
i dont get this part: ""# Prepare the prompt from the last message
Note: Fixed the quotation marks and removed incorrect usage of tokenizer before its declaration
prompt = messages[-1][‘content’] # This gets the content of the last message
Convert the prompt into model input tokens"" explain it to me simply please. For example, why doesnt the model page code have it?
""from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1") tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.1")
messages = [ {"role": "user", "content": "What is your favourite condiment?"}, {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"}, {"role": "user", "content": "Do you have mayonnaise recipes?"} ]
encodeds = tokenizer.apply_chat_template(messages, return_tensors="pt")
model_inputs = encodeds.to(device) model.to(device)
generated_ids = model.generate(model_inputs, max_new_tokens=1000, do_sample=True) decoded = tokenizer.batch_decode(generated_ids) print(decoded[0]) ""
- Assistant
- User
well the code on the model page is written by the person who created the model, so i think we should go with his appreaoch/method, don't you think?
- Assistant
- User
you forgot the path tot the locally downloaded file. also what is this 'TextGenerationPipeline' ? It is not featured in the model author's code nor Intel Neural Speed's code. Think step by step through this
- Assistant
- User
- Assistant
- User
ok, now, i got this:
""PS C:\Users\bower\augmentoolkit> & C:/Users/bower/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/bower/Videos/AI Agent/model test/modeltest.py" tokenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.25k/1.25k [00:00<?, ?B/s] tokenizer.model: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 493k/493k [00:00<00:00, 5.94MB/s] tokenizer.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.80M/1.80M [00:01<00:00, 1.30MB/s] special_tokens_map.json: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 624/624 [00:00<?, ?B/s] Traceback (most recent call last): File "c:\Users\bower\Videos\AI Agent\model test\modeltest.py", line 16, in prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\bower\AppData\Local\Programs\Python\Python311\Lib\site-packages\transformers\tokenization_utils_base.py", line 1745, in apply_chat_template rendered = compiled_template.render( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\bower\AppData\Local\Programs\Python\Python311\Lib\site-packages\jinja2\environment.py", line 1301, in render self.environment.handle_exception() File "C:\Users\bower\AppData\Local\Programs\Python\Python311\Lib\site-packages\jinja2\environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "", line 2, in top-level template code jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'content' PS C:\Users\bower\augmentoolkit> ""
- Assistant
- User
- Assistant
- User
the author recommends using This model with the Mistral Instruct chat template. Their page is: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1
it reads: ""Instruction format In order to leverage instruction fine-tuning, your prompt should be surrounded by [INST] and [/INST] tokens. The very first instruction should begin with a begin of sentence id. The next instructions should not. The assistant generation will be ended by the end-of-sentence token id.
E.g.
text = "[INST] What is your favourite condiment? [/INST]" "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen! " "[INST] Do you have mayonnaise recipes? [/INST]"
This format is available as a chat template via the apply_chat_template() method:
from transformers import AutoModelForCausalLM, AutoTokenizer
- Assistant
- User
i think you are forgetting some important code from the original Intel Neural Speed repo which we were originally adapting for this new model:
""from transformers import AutoTokenizer, TextStreamer from intel_extension_for_transformers.transformers import AutoModelForCausalLM
Specify the GGUF repo on the Hugginface
model_name = "TheBloke/Llama-2-7B-Chat-GGUF"
Download the the specific gguf model file from the above repo
model_file = "llama-2-7b-chat.Q4_0.gguf"
make sure you are granted to access this model on the Huggingface.
tokenizer_name = "meta-llama/Llama-2-7b-chat-hf"
prompt = "Once upon a time" tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, trust_remote_code=True) inputs = tokenizer(prompt, return_tensors="pt").input_ids streamer = TextStreamer(tokenizer) model = AutoModelForCausalLM.from_pretrained(model_name, model_file = model_file) outputs = model.generate(inputs, streamer=streamer, max_new_tokens=300)""
- Assistant
- User
what is this encoding/decoding thing? none of the orignal codes mention that. also the text streamer is important as it lets you see text slowly arriving on screen instead of waiting for a big blob of text
- Assistant
- User
"" File "c:\Users\bower\Videos\AI Agent\model test\modeltest.py", line 2, in PS C:\Users\bower\augmentoolkit> & C:/Users/bower/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/bower/Videos/AI Agent/model test/modeltest.py" tokenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.47k/1.47k [00:00<?, ?B/s] tokenizer.model: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 493k/493k [00:00<00:00, 7.66MB/s] tokenizer.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.80M/1.80M [00:01<00:00, 1.29MB/s] special_tokens_map.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 72.0/72.0 [00:00<?, ?B/s] Traceback (most recent call last): File "c:\Users\bower\Videos\AI Agent\model test\modeltest.py", line 15, in inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").input_ids ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Tensor' object has no attribute 'input_ids' PS C:\Users\bower\augmentoolkit> ""
- Assistant
- User
i got this error: ""PS C:\Users\bower\augmentoolkit> & C:/Users/bower/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/bower/Videos/AI Agent/model test/modeltest.py" PS C:\Users\bower\augmentoolkit> & C:/Users/bower/AppData/Local/Programs/Python/Python311/python.exe "c:/Users/bower/Videos/AI Agent/model test/modeltest.py" Traceback (most recent call last): File "C:\Users\bower\AppData\Local\Programs\Python\Python311\Lib\site-packages\transformers\configuration_utils.py", line 718, in _get_config_dict config_dict = cls._dict_from_json_file(resolved_config_file) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\bower\AppData\Local\Programs\Python\Python311\Lib\site-packages\transformers\configuration_utils.py", line 816, in _dict_from_json_file text = reader.read() ^^^^^^^^^^^^^ File "", line 322, in decode UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 135: invalid start byte
- Assistant
- User
- Assistant