File size: 11,955 Bytes
3cd1076 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | #!/usr/bin/env python
# coding=utf-8
"""
Commonly used constants.
"""
TEXT_ONLY_DATASET_DESCRIPTION = (
"""
"text_only": a dataset with only raw text instances, with following format:
{
"type": "text_only",
"instances": [
{ "text": "TEXT_1" },
{ "text": "TEXT_2" },
...
]
}
"""
).lstrip("\n")
TEXT_TO_SCORED_TEXTLIST_DATASET_DESCRIPTION = (
"""
This kind of dataset is commonly used in reward model training/prediction, as well as rl training.
{
"type": "text_to_scored_textlist",
"instances": [
{
"input": "what's your name?",
"output": [
{"score": 1.0, "text": "My name is John"},
{"score": -0.8, "text": "I'm John"}
]
},
{
"input": "Who are you?",
"output": [
{"score": 1.5, "text": "My name is Amy"},
{"score": 1.0, "text": "I'm Amy"}
]
},
]
}
"""
).lstrip("\n")
PAIRED_TEXT_TO_TEXT_DATASET_DESCRIPTION = (
"""
This kind of dataset is commonly used in reward model training as well as rl training.
{
"type": "paired_text_to_text",
"instances": [
{
"prompt": "Who are you?",
"chosen": "My name is Amy.",
"rejected": "I'm Amy",
"margin": 0.6
},
{
"prompt": "what's your name?",
"chosen": "My name is John.",
"rejected": "I'm John",
"margin": 0.5
}
]
}
"""
).lstrip("\n")
TEXT_ONLY_DATASET_DETAILS = (
"""
For example,
```python
from lmflow.datasets import Dataset
data_dict = {
"type": "text_only",
"instances": [
{ "text": "Human: Hello. Bot: Hi!" },
{ "text": "Human: How are you today? Bot: Fine, thank you!" },
]
}
dataset = Dataset.create_from_dict(data_dict)
```
You may also save the corresponding format to json,
```python
import json
from lmflow.args import DatasetArguments
from lmflow.datasets import Dataset
data_dict = {
"type": "text_only",
"instances": [
{ "text": "Human: Hello. Bot: Hi!" },
{ "text": "Human: How are you today? Bot: Fine, thank you!" },
]
}
with open("data.json", "w") as fout:
json.dump(data_dict, fout)
data_args = DatasetArgument(dataset_path="data.json")
dataset = Dataset(data_args)
new_data_dict = dataset.to_dict()
# `new_data_dict` Should have the same content as `data_dict`
```
"""
).lstrip("\n")
TEXT2TEXT_DATASET_DESCRIPTION = (
"""
"text2text": a dataset with input & output instances, with following format:
{
"type": "text2text",
"instances": [
{ "input": "INPUT_1", "output": "OUTPUT_1" },
{ "input": "INPUT_2", "output": "OUTPUT_2" },
...
]
}
"""
).lstrip("\n")
CONVERSATION_DATASET_DESCRIPTION = (
"""
"conversation": a dataset with conversation instances, with following format (`conversation_id`, `system` and `tools` are optional):
{
"type": "conversation",
"instances": [
{
"conversation_id": "CONVERSATION_ID",
"system": "SYSTEM_PROPMT",
"tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_X"],
"messages": [
{
"role": "user",
"content": "USER_INPUT_1"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_1"
},
{
"role": "user",
"content": "USER_INPUT_2"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_2"
}
]
},
{
"conversation_id": "CONVERSATION_ID",
"system": "SYSTEM_PROPMT",
"tools": ["TOOL_DESCRIPTION_1"],
"messages": [
{
"role": "user",
"content": "USER_INPUT_1"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_1"
}
]
}
]
}
"""
).lstrip("\n")
PAIRED_CONVERSATION_DATASET_DESCRIPTION = (
"""
"paired_conversation": a dataset with paired conversation instances, with following format:
{
"type": "paired_conversation",
"instances": [
{
"chosen": {
"conversation_id": "CONVERSATION_ID",
"system": "SYSTEM_PROPMT",
"tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"],
"messages": [
{
"role": "user",
"content": "USER_INPUT_1"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_1_GOOD"
},
{
"role": "user",
"content": "USER_INPUT_2"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_2_GOOD"
}
]
},
"rejected": {
"conversation_id": "CONVERSATION_ID",
"system": "SYSTEM_PROPMT",
"tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"],
"messages": [
{
"role": "user",
"content": "USER_INPUT_1"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_1_BAD"
},
{
"role": "user",
"content": "USER_INPUT_2"
},
{
"role": "assistant",
"content": "ASSISTANT_RESPONSE_2_BAD"
}
]
}
}
]
}
"""
).lstrip("\n")
TEXT_TO_TEXTLIST_DATASET_DESCRIPTION = (
"""
This kind of dataset is commonly used in reward model inference.
{
"type": "text_to_textlist",
"instances": [
{
"input": "what's your name?",
"output": [
"My name is John",
"I'm John",
]
},
{
"input": "Who are you?",
"output": [
"My name is Amy",
"I'm Amy",
]
},
]
}
"""
).lstrip("\n")
TEXT2TEXT_DATASET_DETAILS = (
"""
For example,
```python
from lmflow.datasets import Dataset
data_dict = {
"type": "text2text",
"instances": [
{
"input": "Human: Hello.",
"output": "Bot: Hi!",
},
{
"input": "Human: How are you today?",
"output": "Bot: Fine, thank you! And you?",
}
]
}
dataset = Dataset.create_from_dict(data_dict)
```
You may also save the corresponding format to json,
```python
import json
from lmflow.args import DatasetArguments
from lmflow.datasets import Dataset
data_dict = {
"type": "text2text",
"instances": [
{
"input": "Human: Hello.",
"output": "Bot: Hi!",
},
{
"input": "Human: How are you today?",
"output": "Bot: Fine, thank you! And you?",
}
]
}
with open("data.json", "w") as fout:
json.dump(data_dict, fout)
data_args = DatasetArgument(dataset_path="data.json")
dataset = Dataset(data_args)
new_data_dict = dataset.to_dict()
# `new_data_dict` Should have the same content as `data_dict`
```
"""
).lstrip("\n")
FLOAT_ONLY_DATASET_DESCRIPTION = (
"""
"float_only": a dataset with only float instances, with following format:
{
"type": "float_only",
"instances": [
{ "value": "FLOAT_1" },
{ "value": "FLOAT_2" },
...
]
}
"""
).lstrip("\n")
TEXT_ONLY_DATASET_LONG_DESCRITION = (
TEXT_ONLY_DATASET_DESCRIPTION + TEXT_ONLY_DATASET_DETAILS
)
TEXT2TEXT_DATASET_LONG_DESCRITION = (
TEXT2TEXT_DATASET_DESCRIPTION + TEXT2TEXT_DATASET_DETAILS
)
DATASET_DESCRIPTION_MAP = {
"text_only": TEXT_ONLY_DATASET_DESCRIPTION,
"text2text": TEXT2TEXT_DATASET_DESCRIPTION,
"float_only": FLOAT_ONLY_DATASET_DESCRIPTION,
}
INSTANCE_FIELDS_MAP = {
"text_only": ["text"],
"text2text": ["input", "output"],
"conversation": ["messages"], # system, tools and conversation_id are optional
"paired_conversation": ["chosen", "rejected"],
"paired_text_to_text": ["prompt", "chosen", "rejected"],
"float_only": ["value"],
"image_text": ["images", "text"],
"text_to_textlist": ["input", "output"],
"text_to_scored_textlist": ["input", "output"],
}
CONVERSATION_ROLE_NAMES = {
"system": "system",
"user": "user",
"assistant": "assistant",
"function": "function",
"observation": "observation"
}
# LLAVA constants
CONTROLLER_HEART_BEAT_EXPIRATION = 30
WORKER_HEART_BEAT_INTERVAL = 15
LOGDIR = "."
# Model Constants
IGNORE_INDEX = -100
IMAGE_TOKEN_INDEX = -200
DEFAULT_IMAGE_TOKEN = "<image>"
DEFAULT_IMAGE_PATCH_TOKEN = "<im_patch>"
DEFAULT_IM_START_TOKEN = "<im_start>"
DEFAULT_IM_END_TOKEN = "<im_end>"
# Lora
# NOTE: This work as a mapping for those models that `peft` library doesn't support yet, and will be
# overwritten by peft.utils.constants.TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING
# if the model is supported (see hf_model_mixin.py).
# NOTE: When passing lora_target_modules through arg parser, the
# value should be a string. Using commas to separate the module names, e.g.
# "--lora_target_modules 'q_proj, v_proj'".
# However, when specifying here, they should be lists.
LMFLOW_LORA_TARGET_MODULES_MAPPING = {
'qwen2': ["q_proj", "v_proj"],
'internlm2': ["wqkv"],
'hymba': ["x_proj.0", "in_proj", "out_proj", "dt_proj.0"]
}
# vllm inference
MEMORY_SAFE_VLLM_INFERENCE_FINISH_FLAG = "MEMORY_SAFE_VLLM_INFERENCE_DONE"
RETURN_CODE_ERROR_BUFFER = [
134
]
# return code 134:
# > Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stdout>'>
# > at interpreter shutdown, possibly due to daemon threads
# The above error, by our observation, is due to the kill signal with unfinished
# stdout/stderr writing in the subprocess
MEMORY_SAFE_VLLM_INFERENCE_ENV_VAR_TO_REMOVE = [
"OMP_NUM_THREADS",
"LOCAL_RANK",
"RANK",
"GROUP_RANK",
"ROLE_RANK",
"ROLE_NAME",
"LOCAL_WORLD_SIZE",
"WORLD_SIZE",
"GROUP_WORLD_SIZE",
"ROLE_WORLD_SIZE",
"MASTER_ADDR",
"MASTER_PORT",
"TORCHELASTIC_RESTART_COUNT",
"TORCHELASTIC_MAX_RESTARTS",
"TORCHELASTIC_RUN_ID",
"TORCHELASTIC_USE_AGENT_STORE",
"TORCH_NCCL_ASYNC_ERROR_HANDLING",
"TORCHELASTIC_ERROR_FILE",
]
# dpov2 align
MEMORY_SAFE_DPOV2_ALIGN_ENV_VAR_TO_REMOVE = [
"OMP_NUM_THREADS",
"LOCAL_RANK",
"RANK",
"GROUP_RANK",
"ROLE_RANK",
"ROLE_NAME",
"LOCAL_WORLD_SIZE",
"WORLD_SIZE",
"GROUP_WORLD_SIZE",
"ROLE_WORLD_SIZE",
"MASTER_ADDR",
"MASTER_PORT",
"TORCHELASTIC_RESTART_COUNT",
"TORCHELASTIC_MAX_RESTARTS",
"TORCHELASTIC_RUN_ID",
"TORCHELASTIC_USE_AGENT_STORE",
"TORCH_NCCL_ASYNC_ERROR_HANDLING",
"TORCHELASTIC_ERROR_FILE",
] |