n1ck-guo commited on
Commit
72ad96c
·
verified ·
1 Parent(s): 8387baf

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +118 -0
README.md ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model:
3
+ - zai-org/GLM-4.7
4
+ pipeline_tag: text-generation
5
+ ---
6
+
7
+ ## Model Details
8
+
9
+ This model is a mixed int4 model with group_size 128 and symmetric quantization of [zai-org/GLM-4.7](https://huggingface.co/zai-org/GLM-4.7) generated by [intel/auto-round](https://github.com/intel/auto-round) **via RTN(without algorithm tuning)**.
10
+ Non expert layers are fallback to 8 bits. Please refer to Section Generate the model for more details.
11
+ Please follow the license of the original model.
12
+
13
+ ## How To Use
14
+
15
+ ### INT4 Inference
16
+ ```python
17
+ import torch
18
+ from transformers import AutoModelForCausalLM, AutoTokenizer
19
+
20
+ MODEL_PATH = "Intel/GLM-4.7-int4-mixed-AutoRound"
21
+ messages = [{"role": "user", "content": "Give me a short introduction to large language model."}]
22
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
23
+ inputs = tokenizer.apply_chat_template(
24
+ messages,
25
+ tokenize=True,
26
+ add_generation_prompt=True,
27
+ return_dict=True,
28
+ return_tensors="pt",
29
+ )
30
+ model = AutoModelForCausalLM.from_pretrained(
31
+ pretrained_model_name_or_path=MODEL_PATH,
32
+ torch_dtype=torch.bfloat16,
33
+ device_map="auto",
34
+ )
35
+ inputs = inputs.to(model.device)
36
+ inputs.pop("token_type_ids")
37
+ generated_ids = model.generate(**inputs, max_new_tokens=512, do_sample=False)
38
+ output_text = tokenizer.decode(generated_ids[0][inputs.input_ids.shape[1] :])
39
+ print(output_text)
40
+ """
41
+ 1. **Analyze the Request:**
42
+ * **Topic:** Large Language Models (LLMs).
43
+ * **Format:** Short introduction.
44
+ * **Goal:** Explain what they are, how they work (briefly), and why they matter, in a concise and accessible way.
45
+
46
+ 2. **Identify Key Concepts to Cover:**
47
+ * Definition: What is an LLM? (AI, text processing).
48
+ * Mechanism: How does it work? (Training on massive data, predicting the next word).
49
+ * Capabilities: What can it do? (Writing, coding, translating, summarizing).
50
+ * Examples: ChatGPT, Claude, Llama (to make it concrete).
51
+ * Significance: Why is it important? (Versatility, human-like interaction).
52
+
53
+ 3. **Drafting - Section by Section:**
54
+
55
+ * *The Hook/Definition:* Start with a simple definition. It's a type of AI trained on text.
56
+ * *The "How":* Explain the core mechanism simply. It's not magic; it's probability. "Next token prediction."
57
+ * *The "Scale":* Mention the "Large" part. Huge datasets, huge parameters.
58
+ * *The "What can it do":* List common use cases (chatbots, writing, coding).
59
+ * *The "Why it matters":* It's a shift in how we interact with computers (natural language).
60
+
61
+ 4. **Refining and Condensing (Iterative Process):**
62
+
63
+ * *Draft 1 (Mental Outline):* A Large Language Model is an AI that reads a lot of text. It uses deep learning to understand patterns. It predicts the next word in a sentence. Because it's trained on the internet, it knows a lot. It can write essays, code, and answer questions. Examples are GPT-4. It changes how we use computers because we can talk to them normally.
64
+
65
+ * *Draft 2 (Polishing for flow and tone):* A Large Language Model (LLM) is a deep learning algorithm that can perform a variety of natural language processing tasks. It is trained on massive amounts of text data from the internet. The fundamental way it works is by predicting the next word in a sequence based on context. This allows it to generate human-like text, translate languages, and write code. Popular examples include ChatGPT and Claude. They represent a
66
+ """
67
+ ```
68
+
69
+ ### Generate the model
70
+
71
+ ```python
72
+ import torch
73
+ from transformers import AutoModelForCausalLM, AutoTokenizer
74
+ import transformers
75
+ from auto_round import AutoRound
76
+ from auto_round.utils import llm_load_model
77
+
78
+ model_name = "zai-org/GLM-4.7"
79
+ model, tokenizer = llm_load_model(model_name, device="cpu")
80
+
81
+ layer_config = {}
82
+ for n, m in model.named_modules():
83
+ if isinstance(m, torch.nn.Linear):
84
+ if "expert" in n and "shared_experts" not in n:
85
+ layer_config[n] = {"bits": 4}
86
+ print(n, 4)
87
+ elif n != "lm_head":
88
+ layer_config[n] = {"bits": 8}
89
+ print(n, 8)
90
+
91
+ autoround = AutoRound(model, tokenizer, iters=0, layer_config=layer_config, disable_opt_rtn=True))
92
+ autoround.quantize_and_save(format="auto_round", output_dir="tmp_autoround")
93
+
94
+ ```
95
+
96
+ ## Ethical Considerations and Limitations
97
+
98
+ The model can produce factually incorrect output, and should not be relied on to produce factually accurate information. Because of the limitations of the pretrained model and the finetuning datasets, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
99
+
100
+ Therefore, before deploying any applications of the model, developers should perform safety testing.
101
+
102
+ ## Caveats and Recommendations
103
+
104
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model.
105
+
106
+ Here are a couple of useful links to learn more about Intel's AI software:
107
+
108
+ - [Intel Neural Compressor](https://github.com/intel/neural-compressor)
109
+
110
+ ## Disclaimer
111
+
112
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please consult an attorney before using this model for commercial purposes.
113
+
114
+ ## Cite
115
+
116
+ @article{cheng2023optimize, title={Optimize weight rounding via signed gradient descent for the quantization of llms}, author={Cheng, Wenhua and Zhang, Weiwei and Shen, Haihao and Cai, Yiyang and He, Xin and Lv, Kaokao and Liu, Yi}, journal={arXiv preprint arXiv:2309.05516}, year={2023} }
117
+
118
+ [arxiv](https://arxiv.org/abs/2309.05516) [github](https://github.com/intel/auto-round)