Husnain
		
	commited on
		
		
					💎 [Feature] New model supported: zephyr-orpo-141b (HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1)
Browse files- messagers/message_composer.py +15 -15
    	
        messagers/message_composer.py
    CHANGED
    
    | @@ -48,10 +48,10 @@ class MessageComposer: | |
| 48 |  | 
| 49 | 
             
                def merge(self, messages) -> str:
         | 
| 50 | 
             
                    # Templates for Chat Models
         | 
| 51 | 
            -
                    # | 
| 52 | 
             
                    #   - https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1#instruction-format
         | 
| 53 | 
             
                    #   - https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO#prompt-format
         | 
| 54 | 
            -
                    #   - https://huggingface.co/ | 
| 55 | 
             
                    #   - https://huggingface.co/google/gemma-1.1-7b-it#chat-template
         | 
| 56 |  | 
| 57 | 
             
                    # Mistral and Mixtral:
         | 
| @@ -64,8 +64,8 @@ class MessageComposer: | |
| 64 | 
             
                    #   Hello, who are you?<|im_end|>
         | 
| 65 | 
             
                    #   <|im_start|>assistant
         | 
| 66 |  | 
| 67 | 
            -
                    #  | 
| 68 | 
            -
                    #    | 
| 69 |  | 
| 70 | 
             
                    # Google Gemma-it
         | 
| 71 | 
             
                    # <start_of_turn>user
         | 
| @@ -103,8 +103,8 @@ class MessageComposer: | |
| 103 | 
             
                            self.merged_str_list.append(message_line)
         | 
| 104 | 
             
                        self.merged_str_list.append("<|im_start|>assistant")
         | 
| 105 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 106 | 
            -
                    # https://huggingface.co/ | 
| 107 | 
            -
                    elif self.model in [" | 
| 108 | 
             
                        self.messages = self.concat_messages_by_role(messages)
         | 
| 109 | 
             
                        self.merged_str_list = []
         | 
| 110 | 
             
                        self.end_of_turn = "<|end_of_turn|>"
         | 
| @@ -113,17 +113,17 @@ class MessageComposer: | |
| 113 | 
             
                            content = message["content"]
         | 
| 114 | 
             
                            if role in self.inst_roles:
         | 
| 115 | 
             
                                self.merged_str_list.append(
         | 
| 116 | 
            -
                                    f" | 
| 117 | 
             
                                )
         | 
| 118 | 
             
                            elif role in self.answer_roles:
         | 
| 119 | 
             
                                self.merged_str_list.append(
         | 
| 120 | 
            -
                                    f" | 
| 121 | 
             
                                )
         | 
| 122 | 
             
                            else:
         | 
| 123 | 
             
                                self.merged_str_list.append(
         | 
| 124 | 
            -
                                    f" | 
| 125 | 
             
                                )
         | 
| 126 | 
            -
                        self.merged_str_list.append(f" | 
| 127 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 128 | 
             
                    # https://huggingface.co/google/gemma-1.1-7b-it#chat-template
         | 
| 129 | 
             
                    elif self.model in ["gemma-1.1-7b"]:
         | 
| @@ -149,9 +149,9 @@ class MessageComposer: | |
| 149 | 
             
                        self.merged_str_list.append(f"{self.start_of_turn}model\n")
         | 
| 150 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 151 | 
             
                    # https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO#prompt-format
         | 
| 152 | 
            -
                    # https://huggingface.co/ | 
| 153 | 
            -
                    # elif self.model in [" | 
| 154 | 
            -
                    elif self.model in [" | 
| 155 | 
             
                        tokenizer = AutoTokenizer.from_pretrained(self.model_fullname)
         | 
| 156 | 
             
                        self.merged_str = tokenizer.apply_chat_template(
         | 
| 157 | 
             
                            messages, tokenize=False, add_generation_prompt=True
         | 
| @@ -168,13 +168,13 @@ if __name__ == "__main__": | |
| 168 | 
             
                # model = "mixtral-8x7b"
         | 
| 169 | 
             
                # model = "nous-mixtral-8x7b"
         | 
| 170 | 
             
                # model = "gemma-1.1-7b"
         | 
| 171 | 
            -
                # model = " | 
| 172 | 
             
                model = "command-r-plus"
         | 
| 173 | 
             
                composer = MessageComposer(model)
         | 
| 174 | 
             
                messages = [
         | 
| 175 | 
             
                    {
         | 
| 176 | 
             
                        "role": "system",
         | 
| 177 | 
            -
                        "content": "You are  | 
| 178 | 
             
                    },
         | 
| 179 | 
             
                    {"role": "user", "content": "Hello, who are you?"},
         | 
| 180 | 
             
                    {"role": "assistant", "content": "I am a bot."},
         | 
|  | |
| 48 |  | 
| 49 | 
             
                def merge(self, messages) -> str:
         | 
| 50 | 
             
                    # Templates for Chat Models
         | 
| 51 | 
            +
                    #   - https://huggingface.co/docs/transformers/main/en/chat_templating
         | 
| 52 | 
             
                    #   - https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1#instruction-format
         | 
| 53 | 
             
                    #   - https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO#prompt-format
         | 
| 54 | 
            +
                    #   - https://huggingface.co/HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1
         | 
| 55 | 
             
                    #   - https://huggingface.co/google/gemma-1.1-7b-it#chat-template
         | 
| 56 |  | 
| 57 | 
             
                    # Mistral and Mixtral:
         | 
|  | |
| 64 | 
             
                    #   Hello, who are you?<|im_end|>
         | 
| 65 | 
             
                    #   <|im_start|>assistant
         | 
| 66 |  | 
| 67 | 
            +
                    # HuggingFaceH4:
         | 
| 68 | 
            +
                    #   zephyr-orpo-141b Correct User: Hello<|end_of_turn|>zephyr-orpo-141b Correct Assistant: Hi<|end_of_turn|>zephyr-orpo-141b Correct User: How are you today?<|end_of_turn|>zephyr-orpo-141b Correct Assistant:
         | 
| 69 |  | 
| 70 | 
             
                    # Google Gemma-it
         | 
| 71 | 
             
                    # <start_of_turn>user
         | 
|  | |
| 103 | 
             
                            self.merged_str_list.append(message_line)
         | 
| 104 | 
             
                        self.merged_str_list.append("<|im_start|>assistant")
         | 
| 105 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 106 | 
            +
                    # https://huggingface.co/HuggingFaceH4/zephyr-orpo-141b-A35b-v0.1
         | 
| 107 | 
            +
                    elif self.model in ["zephyr-orpo-141b"]:
         | 
| 108 | 
             
                        self.messages = self.concat_messages_by_role(messages)
         | 
| 109 | 
             
                        self.merged_str_list = []
         | 
| 110 | 
             
                        self.end_of_turn = "<|end_of_turn|>"
         | 
|  | |
| 113 | 
             
                            content = message["content"]
         | 
| 114 | 
             
                            if role in self.inst_roles:
         | 
| 115 | 
             
                                self.merged_str_list.append(
         | 
| 116 | 
            +
                                    f"zephyr-orpo-141b Correct User:\n{content}{self.end_of_turn}"
         | 
| 117 | 
             
                                )
         | 
| 118 | 
             
                            elif role in self.answer_roles:
         | 
| 119 | 
             
                                self.merged_str_list.append(
         | 
| 120 | 
            +
                                    f"zephyr-orpo-141b Correct Assistant:\n{content}{self.end_of_turn}"
         | 
| 121 | 
             
                                )
         | 
| 122 | 
             
                            else:
         | 
| 123 | 
             
                                self.merged_str_list.append(
         | 
| 124 | 
            +
                                    f"zephyr-orpo-141b Correct User: {content}{self.end_of_turn}"
         | 
| 125 | 
             
                                )
         | 
| 126 | 
            +
                        self.merged_str_list.append(f"zephyr-orpo-141b Correct Assistant:\n")
         | 
| 127 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 128 | 
             
                    # https://huggingface.co/google/gemma-1.1-7b-it#chat-template
         | 
| 129 | 
             
                    elif self.model in ["gemma-1.1-7b"]:
         | 
|  | |
| 149 | 
             
                        self.merged_str_list.append(f"{self.start_of_turn}model\n")
         | 
| 150 | 
             
                        self.merged_str = "\n".join(self.merged_str_list)
         | 
| 151 | 
             
                    # https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO#prompt-format
         | 
| 152 | 
            +
                    # https://huggingface.co/HuggingFaceH4/zephyr-orpo-141b
         | 
| 153 | 
            +
                    # elif self.model in ["zephyr-orpo-141b", "nous-mixtral-8x7b"]:
         | 
| 154 | 
            +
                    elif self.model in ["zephyr-orpo-141b", "command-r-plus"]:
         | 
| 155 | 
             
                        tokenizer = AutoTokenizer.from_pretrained(self.model_fullname)
         | 
| 156 | 
             
                        self.merged_str = tokenizer.apply_chat_template(
         | 
| 157 | 
             
                            messages, tokenize=False, add_generation_prompt=True
         | 
|  | |
| 168 | 
             
                # model = "mixtral-8x7b"
         | 
| 169 | 
             
                # model = "nous-mixtral-8x7b"
         | 
| 170 | 
             
                # model = "gemma-1.1-7b"
         | 
| 171 | 
            +
                # model = "zephyr-orpo-141b"
         | 
| 172 | 
             
                model = "command-r-plus"
         | 
| 173 | 
             
                composer = MessageComposer(model)
         | 
| 174 | 
             
                messages = [
         | 
| 175 | 
             
                    {
         | 
| 176 | 
             
                        "role": "system",
         | 
| 177 | 
            +
                        "content": "You are Zephyr, an assistant developed by KAIST AI, Argilla, and Hugging Face. You should give concise responses to very simple questions, but provide thorough responses to more complex and open-ended questions. You are happy to help with writing, analysis, question answering, math, coding, and all sorts of other tasks.",
         | 
| 178 | 
             
                    },
         | 
| 179 | 
             
                    {"role": "user", "content": "Hello, who are you?"},
         | 
| 180 | 
             
                    {"role": "assistant", "content": "I am a bot."},
         | 
 
			
