| GemmaTemplator |
Ran ran on a synthesized input |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("a1b197616af86079") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
from typing import List, Dict
# The class doesn't have an __init__, so INIT_ARGS is empty
INIT_ARGS = {}
# The computation method is `wrap`, which takes messages and optional kwargs
ARGS = {
'messages': [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Hello, how are you?'},
{'role': 'assistant', 'content': 'I am doing well, thank you!'},
{'role': 'user', 'content': 'What is 2+2?'}
],
'add_special_token_when_last_role_is_user': True,
'add_end_splitter': False,
'add_bos_token': True
}
METHOD = 'wrap'
# Setup and execution
if __name__ == '__main__':
from typing import Optional, Dict, Sequence
from typing import List, Tuple, Any, Dict
import warnings
class Templator:
@classmethod
def wrap(self, messages: List, **kwargs) -> str:
raise NotImplementedError('Please implement the function `wrap` for the class Templator.')
@classmethod
def generate_structured_input(cls, messages: List[Dict], system_template: str, user_template: str, assistant_template: str, assistant_template_left: str, assistant_template_right: str, splitter: str, splitter_after_user: str=None, final_input: str=None, structured_final_input: List[str]=None, add_special_token_when_last_role_is_user: bool=True, add_end_splitter: bool=False) -> List[str]:
if final_input == None:
final_input = ''
for message in messages:
if message['role'] == 'system':
if system_template == None:
warnings.warn('The current templator is not supported the role `system`. Now we ignore the content in the system role.')
else:
final_input = f"{final_input}{system_template.format(prompt=message['content'])}{splitter}"
elif message['role'] == 'user':
if splitter_after_user == None:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter}"
else:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter_after_user}"
elif message['role'] == 'assistant':
final_input = f"{final_input}{assistant_template.format(prompt=message['content'])}{splitter}"
else:
raise ValueError(f"the role `{message['role']}` is not supported. Our supported role list is `[system, user, assistant]`.")
if add_end_splitter:
final_input = f'{final_input}{splitter}'
elif len(splitter) > 0:
assert final_input.endswith(splitter)
final_input = final_input[:-len(splitter)]
if add_special_token_when_last_role_is_user and messages[-1]['role'] == 'user':
final_input = f'{final_input}{splitter}'
return final_input
class GemmaTemplator(Templator):
"""<bos><start_of_turn>user
user input 1<end_of_turn>
<start_of_turn>model
model output 1<end_of_turn>
<start_of_turn>user
user input 2<end_of_turn>
<start_of_turn>model
model output 2<end_of_turn>"""
@classmethod
def wrap(cls, messages: List, add_special_token_when_last_role_is_user: bool=False, add_end_splitter: bool=False, add_bos_token: bool=False) -> List[str]:
default_system_prompt = None
system_template = '<start_of_turn>system\n{prompt}<end_of_turn>'
user_template = '<start_of_turn>user\n{prompt}<end_of_turn>\n<start_of_turn>model'
assistant_template = '{prompt}<end_of_turn>'
assistant_template_left = '<start_of_turn>model\n'
assistant_template_right = '<end_of_turn>'
splitter = '\n'
if add_bos_token:
final_input = '<bos>'
else:
final_input = ''
return cls.generate_structured_input(messages=messages, system_template=system_template, user_template=user_template, assistant_template=assistant_template, assistant_template_left=assistant_template_left, assistant_template_right=assistant_template_right, splitter=splitter, final_input=final_input, add_special_token_when_last_role_is_user=add_special_token_when_last_role_is_user, add_end_splitter=add_end_splitter)
# Construct and call
instance = GemmaTemplator(**INIT_ARGS)
result = getattr(instance, METHOD)(**ARGS)
print("Result:")
print(result)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| Llama3Templator |
Ran ran on a synthesized input |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("167e22a9b15461c1") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
from typing import List, Dict
# The Templator and Llama3Templator classes are defined above
# (copy-pasted from the problem statement)
from typing import Optional, Dict, Sequence
from typing import List, Tuple, Any, Dict
import warnings
class Templator:
@classmethod
def wrap(self, messages: List, **kwargs) -> str:
raise NotImplementedError('Please implement the function `wrap` for the class Templator.')
@classmethod
def generate_structured_input(cls, messages: List[Dict], system_template: str, user_template: str, assistant_template: str, assistant_template_left: str, assistant_template_right: str, splitter: str, splitter_after_user: str=None, final_input: str=None, structured_final_input: List[str]=None, add_special_token_when_last_role_is_user: bool=True, add_end_splitter: bool=False) -> List[str]:
if final_input == None:
final_input = ''
for message in messages:
if message['role'] == 'system':
if system_template == None:
warnings.warn('The current templator is not supported the role `system`. Now we ignore the content in the system role.')
else:
final_input = f"{final_input}{system_template.format(prompt=message['content'])}{splitter}"
elif message['role'] == 'user':
if splitter_after_user == None:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter}"
else:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter_after_user}"
elif message['role'] == 'assistant':
final_input = f"{final_input}{assistant_template.format(prompt=message['content'])}{splitter}"
else:
raise ValueError(f"the role `{message['role']}` is not supported. Our supported role list is `[system, user, assistant]`.")
if add_end_splitter:
final_input = f'{final_input}{splitter}'
elif len(splitter) > 0:
assert final_input.endswith(splitter)
final_input = final_input[:-len(splitter)]
if add_special_token_when_last_role_is_user and messages[-1]['role'] == 'user':
final_input = f'{final_input}{splitter}'
return final_input
class Llama3Templator(Templator):
"""<|begin_of_text|><|start_header_id|>user<|end_header_id|>
user input 1<|eot_id|><|start_header_id|>assistant<|end_header_id|>
model output 1<|eot_id|>"""
@classmethod
def wrap(cls, messages: List, add_special_token_when_last_role_is_user: bool=False, add_end_splitter: bool=False, add_bos_token: bool=False) -> List[str]:
default_system_prompt = None
system_template = '<|start_header_id|>system<|end_header_id|>\n\n{prompt}<|eot_id|>'
user_template = '<|start_header_id|>user<|end_header_id|>\n\n{prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n'
assistant_template = '{prompt}<|eot_id|>'
assistant_template_left = '<|start_header_id|>assistant<|end_header_id|>\n\n'
assistant_template_right = '<|eot_id|>'
splitter = ''
if add_bos_token:
final_input = '<|begin_of_text|>'
else:
final_input = ''
return cls.generate_structured_input(messages=messages, system_template=system_template, user_template=user_template, assistant_template=assistant_template, assistant_template_left=assistant_template_left, assistant_template_right=assistant_template_right, final_input=final_input, splitter=splitter, add_special_token_when_last_role_is_user=add_special_token_when_last_role_is_user, add_end_splitter=add_end_splitter)
# Llama3Templator is a classmethod-only class with no __init__
# So INIT_ARGS is empty
INIT_ARGS = {}
# The computation method is wrap, which takes messages and optional kwargs
ARGS = {
'messages': [
{'role': 'user', 'content': 'Hello'},
{'role': 'assistant', 'content': 'Hi there'}
],
'add_special_token_when_last_role_is_user': False,
'add_end_splitter': False,
'add_bos_token': False
}
METHOD = 'wrap'
# Construct and call
instance = Llama3Templator()
result = getattr(instance, METHOD)(**ARGS)
print("Result:")
print(result)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| Qwen2Templator |
Ran ran on a synthesized input |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("8baed8907582a4a3") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import torch
import numpy as np
from typing import List, Dict
# The Qwen2Templator class doesn't have an __init__ method, so INIT_ARGS is empty
INIT_ARGS = {}
# The computation method is `wrap`, which takes messages and optional kwargs
ARGS = {
'messages': [
{'role': 'system', 'content': 'You are a helpful assistant.'},
{'role': 'user', 'content': 'Hello, how are you?'},
{'role': 'assistant', 'content': 'I am doing well, thank you for asking.'},
{'role': 'user', 'content': 'What is 2+2?'}
],
'add_special_token_when_last_role_is_user': False,
'force_system_prompt': False,
'add_end_splitter': False
}
METHOD = 'wrap'
# Construction and execution
if __name__ == '__main__':
from typing import Optional, Dict, Sequence
from typing import List, Tuple, Any, Dict
import warnings
class Templator:
@classmethod
def wrap(self, messages: List, **kwargs) -> str:
raise NotImplementedError('Please implement the function `wrap` for the class Templator.')
@classmethod
def generate_structured_input(cls, messages: List[Dict], system_template: str, user_template: str, assistant_template: str, assistant_template_left: str, assistant_template_right: str, splitter: str, splitter_after_user: str=None, final_input: str=None, structured_final_input: List[str]=None, add_special_token_when_last_role_is_user: bool=True, add_end_splitter: bool=False) -> List[str]:
if final_input == None:
final_input = ''
for message in messages:
if message['role'] == 'system':
if system_template == None:
warnings.warn('The current templator is not supported the role `system`. Now we ignore the content in the system role.')
else:
final_input = f"{final_input}{system_template.format(prompt=message['content'])}{splitter}"
elif message['role'] == 'user':
if splitter_after_user == None:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter}"
else:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter_after_user}"
elif message['role'] == 'assistant':
final_input = f"{final_input}{assistant_template.format(prompt=message['content'])}{splitter}"
else:
raise ValueError(f"the role `{message['role']}` is not supported. Our supported role list is `[system, user, assistant]`.")
if add_end_splitter:
final_input = f'{final_input}{splitter}'
elif len(splitter) > 0:
assert final_input.endswith(splitter)
final_input = final_input[:-len(splitter)]
if add_special_token_when_last_role_is_user and messages[-1]['role'] == 'user':
final_input = f'{final_input}{splitter}'
return final_input
class Qwen2Templator(Templator):
@classmethod
def wrap(cls, messages: List[Dict], add_special_token_when_last_role_is_user: bool=False, force_system_prompt: bool=False, add_end_splitter: bool=False) -> str:
default_system_prompt = 'You are a helpful assistant.'
system_template = '<|im_start|>system\n{prompt}<|im_end|>'
user_template = '<|im_start|>user\n{prompt}<|im_end|>\n<|im_start|>assistant'
assistant_template = '{prompt}<|im_end|>'
assistant_template_left = '<|im_start|>assistant\n'
assistant_template_right = '<|im_end|>'
splitter = '\n'
if force_system_prompt:
is_existed = False
for message in messages:
if message['role'] == 'system':
is_existed = True
break
if is_existed == False:
messages = [{'role': 'system', 'content': default_system_prompt}] + messages
return cls.generate_structured_input(messages=messages, system_template=system_template, user_template=user_template, assistant_template=assistant_template, assistant_template_left=assistant_template_left, assistant_template_right=assistant_template_right, splitter=splitter, add_special_token_when_last_role_is_user=add_special_token_when_last_role_is_user, add_end_splitter=add_end_splitter)
# Construct and call
instance = Qwen2Templator(**INIT_ARGS)
result = getattr(instance, METHOD)(**ARGS)
print("Result:")
print(result)
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| Templator |
Ran ran on a synthesized input |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("091e063b8c292191") How it ranRan in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.
import warnings
from typing import List, Dict
class Templator:
@classmethod
def wrap(cls, messages: List, **kwargs) -> str:
raise NotImplementedError('Please implement the function `wrap` for the class Templator.')
@classmethod
def generate_structured_input(cls, messages: List[Dict], system_template: str, user_template: str, assistant_template: str, assistant_template_left: str, assistant_template_right: str, splitter: str, splitter_after_user: str=None, final_input: str=None, structured_final_input: List[str]=None, add_special_token_when_last_role_is_user: bool=True, add_end_splitter: bool=False) -> str:
if final_input == None:
final_input = ''
for message in messages:
if message['role'] == 'system':
if system_template == None:
warnings.warn('The current templator is not supported the role `system`. Now we ignore the content in the system role.')
else:
final_input = f"{final_input}{system_template.format(prompt=message['content'])}{splitter}"
elif message['role'] == 'user':
if splitter_after_user == None:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter}"
else:
final_input = f"{final_input}{user_template.format(prompt=message['content'])}{splitter_after_user}"
elif message['role'] == 'assistant':
final_input = f"{final_input}{assistant_template.format(prompt=message['content'])}{splitter}"
else:
raise ValueError(f"the role `{message['role']}` is not supported. Our supported role list is `[system, user, assistant]`.")
if add_end_splitter:
final_input = f'{final_input}{splitter}'
elif len(splitter) > 0:
assert final_input.endswith(splitter)
final_input = final_input[:-len(splitter)]
if add_special_token_when_last_role_is_user and messages[-1]['role'] == 'user':
final_input = f'{final_input}{splitter}'
return final_input
INIT_ARGS = {}
ARGS = {
'messages': [
{'role': 'system', 'content': 'You are helpful.'},
{'role': 'user', 'content': 'Hello'},
{'role': 'assistant', 'content': 'Hi there!'},
{'role': 'user', 'content': 'How are you?'}
],
'system_template': '[SYSTEM]{prompt}[/SYSTEM]',
'user_template': '[USER]{prompt}[/USER]',
'assistant_template': '[ASSISTANT]{prompt}[/ASSISTANT]',
'assistant_template_left': '[ASST_L]',
'assistant_template_right': '[ASST_R]',
'splitter': '\n',
'splitter_after_user': None,
'final_input': None,
'structured_final_input': None,
'add_special_token_when_last_role_is_user': True,
'add_end_splitter': False
}
METHOD = 'generate_structured_input'
result = Templator.generate_structured_input(**ARGS)
print("Result:")
print(repr(result))
- Setup block drafted by
- a language model, class construct-then-call prompt, model not recorded
- Imports
- none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
- Returned
- type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
- Environment
- image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
|
| encode_with_messages_format |
Not yet run unverified (harvested, no recorded run) |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("413afba62a8952fc") How it ran |
| main |
Not yet run unverified (harvested, no recorded run) |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("5bbf3791e217df26") How it ran |
| parse_args |
Not yet run unverified (harvested, no recorded run) |
zjunlp/knowself/train/train_stage1.py code served (permissive licence) · get_code("b1cc0d38e387f876") How it ran |