2.5 KiB
2.5 KiB
license, tasks, base_model
| license | tasks | base_model | ||
|---|---|---|---|---|
| Apache License 2.0 |
|
|
Intro
The AWQ version is quantized using ms-swift. Note that the AWQ version for QwenLong-L1-32B models are verified to be working on Transformers/vLLM. We have not have the chance to tested them on other engines.
Inference
from modelscope import AutoModelForCausalLM, AutoTokenizer
model_name = "swift/QwenLong-L1-32B-AWQ"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
# prepare the model input
template = """Please read the following text and answer the question below.
<text>
$DOC$
</text>
$Q$
Format your response as follows: "Therefore, the answer is (insert answer here)"."""
context = "<YOUR_CONTEXT_HERE>"
question = "<YOUR_QUESTION_HERE>"
prompt = template.replace('$DOC$', context.strip()).replace('$Q$', question.strip())
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=10000,
temperature=0.7,
top_p=0.95
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# parsing thinking content
try:
# rindex finding 151649 (</think>)
index = len(output_ids) - output_ids[::-1].index(151649)
except ValueError:
index = 0
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
print("thinking content:", thinking_content)
print("content:", content)
Quantization
The model has undergone AWQ int4 quantization using the ms-swift framework.
If you have fine-tuned the model and wish to quantize the fine-tuned version, you can refer to the following quantization scripts:
With these scripts, you can easily complete the quantization process for the model.