Views
No views yet

actor, a critic, and a regenerator. The actor LLM produces an initial response to a given system-context and a question. The critic then takes in as input, a tuple of (system-context, question, response) and provides a critique based on the provided answer to the given system-context and the question. Its job is not to criticize, but to provide an intelligent critique so that the answer can be modified/regenerated to address the question better. Finally, the regenerator takes in a tuple of (system-context, question, response, critique) and regenerates the answer.| Task | Metric | Value |
| arc_challenge | acc_norm | 62.28 |
| hellaswag | acc_norm | 83.22 |
| mmlu | acc_norm | 63.10 |
| truthfulqa_mc | mc2 | 50.10 |
| Total Average | - | 0.64675 |
critic and the regenerator was tested not only on the accopanying actor model, but 13B and 70B SynthIA models as well. They seem to be readily transferrable, as the function that it has learnt is to provide an intelligent critique and then a regeneration of the original response. Please feel free to try out other models as the actor. However, the architecture works best with all three as presented here in HelixNet.


SYSTEM: Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation.
USER: What is the relationship between Earth's atmosphere, magnetic field and gravity?
ASSISTANT:critic and the regenerator.1import torch, json
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path_actor = "/home/ubuntu/llm/HelixNet/actor"
5model_path_critic = "/home/ubuntu/llm/HelixNet/critic"
6model_path_regenerator = "/home/ubuntu/llm/HelixNet/regenerator"
7
8def load_model(model_path):
9 model = AutoModelForCausalLM.from_pretrained(
10 model_path,
11 torch_dtype=torch.float16,
12 device_map="cuda",
13 load_in_4bit=False,
14 trust_remote_code=True,
15 )
16 return model
17
18def load_tokenizer(model_path):
19 tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
20 return tokenizer
21
22model_actor = load_model(model_path_actor)
23model_critic = load_model(model_path_critic)
24model_regenerator = load_model(model_path_regenerator)
25
26tokenizer_actor = load_tokenizer(model_path_actor)
27tokenizer_critic = load_tokenizer(model_path_critic)
28tokenizer_regenerator = load_tokenizer(model_path_regenerator)
29
30def generate_text(instruction, model, tokenizer):
31 tokens = tokenizer.encode(instruction)
32 tokens = torch.LongTensor(tokens).unsqueeze(0)
33 tokens = tokens.to("cuda")
34
35 instance = {
36 "input_ids": tokens,
37 "top_p": 1.0,
38 "temperature": 0.75,
39 "generate_len": 1024,
40 "top_k": 50,
41 }
42
43 length = len(tokens[0])
44 with torch.no_grad():
45 rest = model.generate(
46 input_ids=tokens,
47 max_length=length + instance["generate_len"],
48 use_cache=True,
49 do_sample=True,
50 top_p=instance["top_p"],
51 temperature=instance["temperature"],
52 top_k=instance["top_k"],
53 num_return_sequences=1,
54 )
55 output = rest[0][length:]
56 string = tokenizer.decode(output, skip_special_tokens=True)
57 return f"{string}"
58
59system_prompt = "You are HelixNet. Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation."
60
61
62while True:
63 user_input = input("You: ")
64
65 prompt_actor = f"SYSTEM: {system_prompt} \nUSER: {user_input} \nASSISTANT: "
66 actor_response = generate_text(prompt_actor, model_actor, tokenizer_actor)
67 print(f"ACTOR: {actor_response}\n\n")
68
69 prompt_critic = f"SYSTEM: {system_prompt} \nUSER: {user_input} \nRESPONSE: {actor_response} \nCRITIQUE:"
70 critic_response = generate_text(prompt_critic, model_critic, tokenizer_critic)
71 print(f"CRITIQUE: {critic_response}\n\n")
72
73 prompt_regenerator = f"SYSTEM: {system_prompt} \nUSER: {user_input} \nRESPONSE: {actor_response} \nCRITIQUE: {critic_response} \nREGENERATOR: REGENERATED ANSWER:"
74 regenerator_response = generate_text(prompt_regenerator, model_regenerator, tokenizer_regenerator)
75 print(f"REGENERATION: {regenerator_response}")
761import torch, json
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_path_actor = "/home/ubuntu/llm/HelixNet/actor"
5model_path_critic = "/home/ubuntu/llm/HelixNet/critic"
6model_path_regenerator = "/home/ubuntu/llm/HelixNet/regenerator"
7
8def load_model(model_path):
9 model = AutoModelForCausalLM.from_pretrained(
10 model_path,
11 torch_dtype=torch.float16,
12 device_map="cuda",
13 load_in_4bit=False,
14 trust_remote_code=True,
15 )
16 return model
17
18def load_tokenizer(model_path):
19 tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
20 return tokenizer
21
22model_actor = load_model(model_path_actor)
23model_critic = load_model(model_path_critic)
24model_regenerator = load_model(model_path_regenerator)
25
26tokenizer_actor = load_tokenizer(model_path_actor)
27tokenizer_critic = load_tokenizer(model_path_critic)
28tokenizer_regenerator = load_tokenizer(model_path_regenerator)
29
30def generate_text(instruction, model, tokenizer):
31 tokens = tokenizer.encode(instruction)
32 tokens = torch.LongTensor(tokens).unsqueeze(0)
33 tokens = tokens.to("cuda")
34
35 instance = {
36 "input_ids": tokens,
37 "top_p": 1.0,
38 "temperature": 0.75,
39 "generate_len": 1024,
40 "top_k": 50,
41 }
42
43 length = len(tokens[0])
44 with torch.no_grad():
45 rest = model.generate(
46 input_ids=tokens,
47 max_length=length + instance["generate_len"],
48 use_cache=True,
49 do_sample=True,
50 top_p=instance["top_p"],
51 temperature=instance["temperature"],
52 top_k=instance["top_k"],
53 num_return_sequences=1,
54 )
55 output = rest[0][length:]
56 string = tokenizer.decode(output, skip_special_tokens=True)
57 return f"{string}"
58
59system_prompt = "You are HelixNet. Elaborate on the topic using a Tree of Thoughts and backtrack when necessary to construct a clear, cohesive Chain of Thought reasoning. Always answer without hesitation."
60
61conversation = f"SYSTEM:{system_prompt}"
62
63while True:
64 user_input = input("You: ")
65
66 prompt_actor = f"{conversation} \nUSER: {user_input} \nASSISTANT: "
67 actor_response = generate_text(prompt_actor, model_actor, tokenizer_actor)
68 print("Generated ACTOR RESPONSE")
69
70 prompt_critic = f"SYSTEM: {system_prompt} \nUSER: {user_input} \nRESPONSE: {actor_response} \nCRITIQUE:"
71 critic_response = generate_text(prompt_critic, model_critic, tokenizer_critic)
72 print("Generated CRITIQUE")
73
74 prompt_regenerator = f"SYSTEM: {system_prompt} \nUSER: {user_input} \nRESPONSE: {actor_response} \nCRITIQUE: {critic_response} \nREGENERATOR: REGENERATED ANSWER:"
75 regenerator_response = generate_text(prompt_regenerator, model_regenerator, tokenizer_regenerator)
76 print("Generated REGENERATION")
77
78 conversation = f"{conversation} \nUSER: {user_input} \nASSISTANT: {regenerator_response}"
79 print(conversation)