Views
No views yet

{prompt}
desc_act. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.| Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
|---|---|---|---|---|---|---|---|---|---|
| main | 4 | 128 | Yes | 0.1 | Alpaca Japanese | 4096 | 7.49 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
| gptq-4bit-32g-actorder_True | 4 | 32 | Yes | 0.1 | Alpaca Japanese | 4096 | 8.23 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
| gptq-8bit--1g-actorder_True | 8 | None | Yes | 0.1 | Alpaca Japanese | 4096 | 13.59 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
| gptq-8bit-128g-actorder_True | 8 | 128 | Yes | 0.1 | Alpaca Japanese | 4096 | 13.88 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
| gptq-8bit-32g-actorder_True | 8 | 32 | Yes | 0.1 | Alpaca Japanese | 4096 | 14.77 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
| gptq-4bit-64g-actorder_True | 4 | 64 | Yes | 0.1 | Alpaca Japanese | 4096 | 7.74 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
main branch, enter TheBloke/Swallow-13B-GPTQ in the "Download model" box.:branchname to the end of the download name, eg TheBloke/Swallow-13B-GPTQ:gptq-4bit-32g-actorder_Truehuggingface-hub Python library:pip3 install huggingface-hubmain branch to a folder called Swallow-13B-GPTQ:1mkdir Swallow-13B-GPTQ
2huggingface-cli download TheBloke/Swallow-13B-GPTQ --local-dir Swallow-13B-GPTQ --local-dir-use-symlinks False--revision parameter:1mkdir Swallow-13B-GPTQ
2huggingface-cli download TheBloke/Swallow-13B-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir Swallow-13B-GPTQ --local-dir-use-symlinks False--local-dir-use-symlinks False parameter, the files will instead be stored in the central Hugging Face cache directory (default location on Linux is: ~/.cache/huggingface), and symlinks will be added to the specified --local-dir, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.HF_HOME environment variable, and/or the --cache-dir parameter to huggingface-cli.huggingface-cli, please see: HF -> Hub Python Library -> Download files -> Download from the CLI.hf_transfer:pip3 install hf_transferHF_HUB_ENABLE_HF_TRANSFER to 1:1mkdir Swallow-13B-GPTQ
2HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/Swallow-13B-GPTQ --local-dir Swallow-13B-GPTQ --local-dir-use-symlinks Falseset HF_HUB_ENABLE_HF_TRANSFER=1 before the download command.git (not recommended)git, use a command like this:git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/Swallow-13B-GPTQhuggingface-hub, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the .git folder as a blob.)TheBloke/Swallow-13B-GPTQ.TheBloke/Swallow-13B-GPTQ:gptq-4bit-32g-actorder_TrueSwallow-13B-GPTQquantize_config.json.ghcr.io/huggingface/text-generation-inference:1.1.0--model-id TheBloke/Swallow-13B-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096pip3 install huggingface-hub1from huggingface_hub import InferenceClient
2
3endpoint_url = "https://your-endpoint-url-here"
4
5prompt = "Tell me about AI"
6prompt_template=f'''{prompt}
7'''
8
9client = InferenceClient(endpoint_url)
10response = client.text_generation(prompt,
11 max_new_tokens=128,
12 do_sample=True,
13 temperature=0.7,
14 top_p=0.95,
15 top_k=40,
16 repetition_penalty=1.1)
17
18print(f"Model output: {response}")1pip3 install --upgrade transformers optimum
2# If using PyTorch 2.1 + CUDA 12.x:
3pip3 install --upgrade auto-gptq
4# or, if using PyTorch 2.1 + CUDA 11.x:
5pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/1pip3 uninstall -y auto-gptq
2git clone https://github.com/PanQiWei/AutoGPTQ
3cd AutoGPTQ
4git checkout v0.5.1
5pip3 install .1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2
3model_name_or_path = "TheBloke/Swallow-13B-GPTQ"
4# To use a different branch, change revision
5# For example: revision="gptq-4bit-32g-actorder_True"
6model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
7 device_map="auto",
8 trust_remote_code=False,
9 revision="main")
10
11tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
12
13prompt = "Write a story about llamas"
14system_message = "You are a story writing assistant"
15prompt_template=f'''{prompt}
16'''
17
18print("\n\n*** Generate:")
19
20input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
21output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
22print(tokenizer.decode(output[0]))
23
24# Inference can also be done using transformers' pipeline
25
26print("*** Pipeline:")
27pipe = pipeline(
28 "text-generation",
29 model=model,
30 tokenizer=tokenizer,
31 max_new_tokens=512,
32 do_sample=True,
33 temperature=0.7,
34 top_p=0.95,
35 top_k=40,
36 repetition_penalty=1.1
37)
38
39print(pipe(prompt_template)[0]['generated_text'])
| Model | Size | JCommonsenseQA | JEMHopQA | NIILC | JSQuAD | XL-Sum | MGSM | WMT20-en-ja | WMT20-ja-en |
|---|---|---|---|---|---|---|---|---|---|
| 4-shot | 4-shot | 4-shot | 4-shot | 1-shot | 4-shot | 4-shot | 4-shot | ||
| Llama 2 | 7B | 0.3852 | 0.4240 | 0.3410 | 0.7917 | 0.1905 | 0.0760 | 0.1783 | 0.1738 |
| Swallow | 7B | 0.4808 | 0.5078 | 0.5968 | 0.8573 | 0.1830 | 0.1240 | 0.2510 | 0.1511 |
| Llama 2 | 13B | 0.6997 | 0.4415 | 0.4170 | 0.8533 | 0.2139 | 0.1320 | 0.2146 | 0.1982 |
| Swallow | 13B | 0.7837 | 0.5063 | 0.6398 | 0.9005 | 0.2168 | 0.2040 | 0.2720 | 0.1771 |
| Llama 2 | 70B | 0.8686 | 0.4656 | 0.5256 | 0.9080 | 0.2361 | 0.3560 | 0.2643 | 0.2398 |
| Swallow | 70B | 0.9348 | 0.6290 | 0.6960 | 0.9176 | 0.2266 | 0.4840 | 0.3043 | 0.2298 |
pip install -r requirements.txt1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_name = "tokyotech-llm/Swallow-7b-instruct-hf"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")
8
9
10PROMPT_DICT = {
11 "prompt_input": (
12 "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
13 "リクエストを適切に完了するための回答を記述してください。\n\n"
14 "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"
15
16 ),
17 "prompt_no_input": (
18 "以下に、あるタスクを説明する指示があります。"
19 "リクエストを適切に完了するための回答を記述してください。\n\n"
20 "### 指示:\n{instruction}\n\n### 応答:"
21 ),
22}
23
24def create_prompt(instruction, input=None):
25 """
26 Generates a prompt based on the given instruction and an optional input.
27 If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
28 If no input is provided, it uses the 'prompt_no_input' template.
29
30 Args:
31 instruction (str): The instruction describing the task.
32 input (str, optional): Additional input providing context for the task. Default is None.
33
34 Returns:
35 str: The generated prompt.
36 """
37 if input:
38 # Use the 'prompt_input' template when additional input is provided
39 return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
40 else:
41 # Use the 'prompt_no_input' template when no additional input is provided
42 return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)
43
44# Example usage
45instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
46input_example = "東京工業大学の主なキャンパスについて教えてください"
47prompt = create_prompt(instruction_example, input_example)
48
49input_ids = tokenizer.encode(
50 prompt,
51 add_special_tokens=False,
52 return_tensors="pt"
53)
54
55tokens = model.generate(
56 input_ids.to(device=model.device),
57 max_new_tokens=128,
58 temperature=0.99,
59 top_p=0.95,
60 do_sample=True,
61)
62
63out = tokenizer.decode(tokens[0], skip_special_tokens=True)
64print(out)
651import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4model_name = "tokyotech-llm/Swallow-7b-hf"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
8
9prompt = "東京工業大学の主なキャンパスは、"
10input_ids = tokenizer.encode(
11 prompt,
12 add_special_tokens=False,
13 return_tensors="pt"
14)
15tokens = model.generate(
16 input_ids.to(device=model.device),
17 max_new_tokens=128,
18 temperature=0.99,
19 top_p=0.95,
20 do_sample=True,
21)
22
23out = tokenizer.decode(tokens[0], skip_special_tokens=True)
24print(out)