Views
No views yet
⚠️ ARCHIVED / LEGACY MODEL NOTICE
This repository is part of a legacy collection quantized around 2023. To manage storage quotas and maintain active community projects, some rarely used quantization formats (e.g., Q2_K, Q3_K, Q4_1, Q5_1) have been permanently removed.Only the most popular and stable formats (Q4_0, Q4_K_M, Q5_K_M, Q6_K, and Q8_0) remain available.💡 Looking for something modern? If you are starting a new project, we highly recommend using newer architectures (like Llama 3, Mistral, or Qwen) provided by official maintainers or active community members (e.g.,Bartowski,TheBlokelegacy files, or official organization handles).⚠️ This repository is no longer actively maintained. Existing files are provided "as is" for archival and legacy hardware purposes.
gguf is the current file format used by the ggml library.
A growing list of Software is using it and can therefore use this model.
The core project making use of the ggml library is the llama.cpp project by Georgi Gerganovlegacy quantization types.
Nevertheless, they are fully supported, as there are several circumstances that cause certain model not to be compatible with the modern K-quants.use_fast = False parameter, when instantiating the tokenizerimport os
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = 'VMware/open-llama-7b-v2-open-instruct'
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map='sequential')
prompt_template = "Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Response:"
prompt = """What is attention mechanism of a transformer model?
Write a python code to illustrate how attention works within a transformer model using numpy library. Donot use pytorch or tensorflow."""
inputt = prompt_template.format(instruction= prompt)
input_ids = tokenizer(inputt, return_tensors="pt").input_ids.to("cuda")
output1 = model.generate(input_ids, max_length=512)
input_length = input_ids.shape[1]
output1 = output1[:, input_length:]
output = tokenizer.decode(output1[0])
print(output)
1import numpy as np
2
3def attention_weights(query, key, value, mask):
4 # Query, key, and value are input tensors. Mask is a tensor of zeros and ones that represents the attention mask.
5 # It is used to prevent the model from attending to certain positions in the input sequence if they are not relevant.
6 # The attention weights are the element-wise product of the query, key, and mask tensors.
7 # The result is a tensor of the same shape as the query tensor.
8
9 # Compute the dot product between the query tensor and the key tensor
10 dot = np.matmul(query, key)
11
12 # Compute the element-wise softmax of the dot product tensor
13 exp_dot = np.exp(dot)
14
15 # Multiply the dot product and the softmax of the dot product tensors
16 weights = dot * exp_dot
17
18 # Return the attention weights as a NumPy tensor
19 return weights
20
21# Define the input sequence
22query = np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]])
23key = np.array([[0.1, 0.2], [0.3, 0.4]])
24value = np.array([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]])
25mask = np.array([[False, True, True], [False, True, True]])
26
27# Compute the attention weights
28weights = attention_weights(query, key, value, mask)
29
30# Print the attention weights
31print(weights)attention_weights function takes as input the query tensor, key tensor, value tensor, and mask tensor. It computes the dot product between the query and key tensors using the np.matmul function, and then applies a softmax function using the np.exp function to the element-wise dot product tensor. It then multiplies the dot product and softmax tensors using the np.matmul function, and returns the result as a NumPy tensor.query, key, and value tensors represent the input sequence to the transformer model. The mask tensor represents the attention mask, which is used to prevent the model from attending to certain positions in the input sequence if they are not relevant.attention_weights function is a NumPy tensor that represents the attention weights for the input sequence. These weights are used by the transformer model to weigh the contribution of each input element to the output.