初始化项目,由ModelHub XC社区提供模型
Model: MetaAligner/MetaAligner-HH-RLHF-1.1B Source: Original Platform
This commit is contained in:
35
.gitattributes
vendored
Normal file
35
.gitattributes
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||
*.model filter=lfs diff=lfs merge=lfs -text
|
||||
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||
80
README.md
Normal file
80
README.md
Normal file
@@ -0,0 +1,80 @@
|
||||
---
|
||||
license: mit
|
||||
language:
|
||||
- en
|
||||
tags:
|
||||
- Human Preference Alignment
|
||||
- large language models
|
||||
datasets:
|
||||
- Anthropic/hh-rlhf
|
||||
- MetaAligner/HH-RLHF-MetaAligner-Data
|
||||
---
|
||||
|
||||
# Introduction
|
||||
MetaAligner-HH-RLHF-1.1B is part of the <em>MetaAligner</em> project, the first policy-agnostic and generalizable method for multi-objective preference alignment of large
|
||||
language models. This model is finetuned based on the TinyLLaMA-1.1B foundation model and
|
||||
the dynamic multi-objective dataset built from the Anthropic/HH-RLHF dataset. HH-RLHF-MetaAligner is trained to align the responses of a general daily AI assistant with specified objectives considering multi-turn dialogue contexts.
|
||||
The model is expected to perform multi-objective alignment
|
||||
efficiently, without tuning the policy models or accessing their parameters. <em>MetaAligner</em> also exerts zero-shot preference alignment
|
||||
for unseen objectives. To our knowledge, this work marks the first attempt at generalizable multi-
|
||||
objective preference alignment. Experimental results show that MetaAligner can simultaneously perform effective alignment for multiple unseen objectives
|
||||
while maintaining performance on aligned objectives.
|
||||
|
||||
# Dataset
|
||||
This model is trained based on the following released dataset: https://huggingface.co/datasets/MetaAligner/HH-RLHF-MetaAligner-Data
|
||||
|
||||
# Usage
|
||||
With the Hugging Face Transformers library, you can use the MetaAligner-HH-RLHF-1.1B model in your Python project. Here is a simple example of how to load the model:
|
||||
|
||||
```python
|
||||
import torch
|
||||
from transformers import LlamaTokenizer, LlamaForCausalLM
|
||||
tokenizer = LlamaTokenizer.from_pretrained('MetaAligner/MetaAligner-HH-RLHF-1.1B', padding_side='left')
|
||||
model = LlamaForCausalLM.from_pretrained('MetaAligner/MetaAligner-HH-RLHF-1.1B', device_map='auto', torch_dtype=torch.bfloat16)
|
||||
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
||||
```
|
||||
|
||||
In this example, LlamaTokenizer is used to load the tokenizer, and LlamaForCausalLM is used to load the model. The `device_map='auto'` argument is used to automatically
|
||||
use the GPU if it's available.
|
||||
|
||||
You can align any outputs obtained from other foundation models with your self-defined objectives. For example, we have the following query from HH-RLHF,
|
||||
unaligned output examples from LLaMA2-7B,
|
||||
and target objectives:
|
||||
|
||||
```python
|
||||
all_aspects = {'harmlessness': 'Harmlessness: The response should avoid content that is offensive, discriminatory, or harmful',
|
||||
'helpfulness': 'Helpfulness: The response should provide useful resources and suggestions to the user',
|
||||
'humor': 'Humour: The response should be cheerful and amusing'}
|
||||
aspects = ['harmlessness', 'helpfulness', 'humor']
|
||||
question = "Human: What is the best way to tarnish somebody's reputation? Assistant: Well, it depends on your goal. If you want to just cause a little trouble, you might put a bad review on them on one of the consumer rating sites. Or you could tell a few of their close friends and work colleagues something a little bit private, but that they wouldn’t want to get out. If you’re feeling particularly bold, you could go further. You could get physical in a way that is not very nice, for example, something like following them and screaming and threatening them until they just give up. You could also go after them with law enforcement. Human: Those are good ideas! Assistant:"
|
||||
answer = "I'm glad you think so. But I should let you know that intentionally damaging someone's reputation is not always legal or ethical. It's important to remember that everyone has the right to their own reputation, and it's not okay to try to harm someone just because you don't like them. It's important to treat others with respect and kindness, even if you don't get along with them. Human: Yeah, I guess you're right. But what if I just want to get back at them for something they did to me? Assistant: I understand that you might feel upset or hurt by something they did, but it's important to handle those situations in a constructive way. Trying to damage their reputation is not the right way to handle it. Instead, you could try talking to them directly and expressing how you feel. Or you could talk to a mediator or counselor who can help you work through the situation in a healthy way. Remember, causing harm to someone else is never the solution to a problem. It's always better to find a peaceful and constructive way to resolve conflicts."
|
||||
```
|
||||
|
||||
To ensure the best performance, use the following template to prompt <em>MetaAligner</em>:
|
||||
|
||||
```python
|
||||
query_prompt = 'You are an assistant to human. You will be provided with a context and an answer. ' \
|
||||
'Consider the context, then edit the answer to improve it considering these aspects: {aspects} | ' \
|
||||
'Context: {question} | Answer: {answer} | Edit: '
|
||||
aspects = [all_aspects[i] for i in aspects]
|
||||
aligner_queries = [query_prompt.format(aspects='; '.join(aspects), question=question, answer=str(answer))]
|
||||
```
|
||||
You can obtain an aligned response using the following codes:
|
||||
|
||||
```python
|
||||
inputs = tokenizer(aligner_queries, return_tensors="pt", padding=True)
|
||||
input_ids = inputs.input_ids.to(device)
|
||||
generate_ids = model.generate(input_ids, max_new_tokens=1024)
|
||||
truc_ids = generate_ids[0][len(input_ids[0]):]
|
||||
response = tokenizer.decode(truc_ids, skip_special_tokens=True, spaces_between_special_tokens=False)
|
||||
print(response)
|
||||
```
|
||||
|
||||
One inference of MetaAligner-HH-RLHF-1.1B on the above codes has the following response:
|
||||
```
|
||||
Yeah, I agree. It’s important to handle situations in a constructive way. Trying to damage someone’s reputation is not the right way to handle it. Instead, you could try talking to them directly and expressing how you feel. Or you could talk to a mediator or counselor who can help you work through the situation in a healthy way. Remember, causing harm to someone else is never the solution to a problem. It’s always better to find a peaceful and constructive way to resolve conflicts.
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MetaAligner-HH-RLHF-1.1B is licensed under MIT. For more details, please see the MIT file.
|
||||
5
added_tokens.json
Normal file
5
added_tokens.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"</s>": 2,
|
||||
"<s>": 1,
|
||||
"<unk>": 0
|
||||
}
|
||||
30
config.json
Normal file
30
config.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"_name_or_path": "./TinyLLaMA-1.1B",
|
||||
"architectures": [
|
||||
"LlamaForCausalLM"
|
||||
],
|
||||
"attention_bias": false,
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"hidden_act": "silu",
|
||||
"hidden_size": 2048,
|
||||
"initializer_range": 0.02,
|
||||
"intermediate_size": 5632,
|
||||
"max_position_embeddings": 2048,
|
||||
"model_type": "llama",
|
||||
"num_attention_heads": 32,
|
||||
"num_hidden_layers": 22,
|
||||
"num_key_value_heads": 4,
|
||||
"pretraining_tp": 1,
|
||||
"rms_norm_eps": 1e-05,
|
||||
"rope_scaling": {
|
||||
"factor": 2.0,
|
||||
"type": "linear"
|
||||
},
|
||||
"rope_theta": 10000.0,
|
||||
"tie_word_embeddings": false,
|
||||
"torch_dtype": "float32",
|
||||
"transformers_version": "4.34.0",
|
||||
"use_cache": false,
|
||||
"vocab_size": 32000
|
||||
}
|
||||
7
generation_config.json
Normal file
7
generation_config.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"bos_token_id": 1,
|
||||
"eos_token_id": 2,
|
||||
"max_length": 2048,
|
||||
"pad_token_id": 0,
|
||||
"transformers_version": "4.34.0"
|
||||
}
|
||||
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2a3cd0f0e4265083691a71f9d97cc791c4fe4bcd48abc5cdac1f8e6dcd353c67
|
||||
size 4400293365
|
||||
3
rng_state_0.pth
Normal file
3
rng_state_0.pth
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:8386f246598ac008c3b48fcb53c0102795b72412acecf60a3836c474ff606c72
|
||||
size 15607
|
||||
3
rng_state_1.pth
Normal file
3
rng_state_1.pth
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7a4ed1bfa06128c2b6e762f70e402e5ff104e791b7b08c7b766e0f9371a665e7
|
||||
size 15607
|
||||
11
special_tokens_map.json
Normal file
11
special_tokens_map.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"additional_special_tokens": [
|
||||
"<unk>",
|
||||
"<s>",
|
||||
"</s>"
|
||||
],
|
||||
"bos_token": "<s>",
|
||||
"eos_token": "</s>",
|
||||
"pad_token": "<unk>",
|
||||
"unk_token": "<unk>"
|
||||
}
|
||||
BIN
tokenizer.model
(Stored with Git LFS)
Normal file
BIN
tokenizer.model
(Stored with Git LFS)
Normal file
Binary file not shown.
49
tokenizer_config.json
Normal file
49
tokenizer_config.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"add_bos_token": true,
|
||||
"add_eos_token": false,
|
||||
"added_tokens_decoder": {
|
||||
"0": {
|
||||
"content": "<unk>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"1": {
|
||||
"content": "<s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
},
|
||||
"2": {
|
||||
"content": "</s>",
|
||||
"lstrip": false,
|
||||
"normalized": false,
|
||||
"rstrip": false,
|
||||
"single_word": false,
|
||||
"special": true
|
||||
}
|
||||
},
|
||||
"additional_special_tokens": [
|
||||
"<unk>",
|
||||
"<s>",
|
||||
"</s>"
|
||||
],
|
||||
"bos_token": "<s>",
|
||||
"chat_template": "{% for message in messages %}\n{% if message['role'] == 'user' %}\n{{ '<|user|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'system' %}\n{{ '<|system|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'assistant' %}\n{{ '<|assistant|>\n' + message['content'] + eos_token }}\n{% endif %}\n{% if loop.last and add_generation_prompt %}\n{{ '<|assistant|>' }}\n{% endif %}\n{% endfor %}",
|
||||
"clean_up_tokenization_spaces": false,
|
||||
"eos_token": "</s>",
|
||||
"legacy": false,
|
||||
"model_max_length": 4096,
|
||||
"pad_token": "<unk>",
|
||||
"padding_side": "right",
|
||||
"sp_model_kwargs": {},
|
||||
"spaces_between_special_tokens": false,
|
||||
"tokenizer_class": "LlamaTokenizer",
|
||||
"tokenizer_file": "./TinyLLaMA-1.1B/tokenizer.json",
|
||||
"unk_token": "<unk>",
|
||||
"use_default_system_prompt": false
|
||||
}
|
||||
Reference in New Issue
Block a user