Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/prep/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ class ProcArgs:

answer_cols: list[str] = field(default_factory=lambda: DEFAULT_ACOLS)
answer_template: str = DEFAULT_ATEMP
labels: list[str] = field(default_factory=lambda: [])

extra_info: str | None = None

# image-to-image transforms applied in order during conversion
labels: list[str] = field(default_factory=lambda: [])
transforms: list[str] = field(default_factory=lambda: [])

# to fill in verl fields, this does not affect verl training
Expand Down
4 changes: 4 additions & 0 deletions src/prep/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def prep(
a_template: str = typer.Option(
default=DEFAULT_ATEMP, envvar="A_TEMP", rich_help_panel=_AUTO
),
extra_info: str | None = typer.Option(
default=None, envvar="EXTRA_INFO", rich_help_panel=_AUTO
),
verl_ability: str = typer.Option(
default="math", envvar="VERL_ABILITY", rich_help_panel=_AUTO
),
Expand Down Expand Up @@ -113,6 +116,7 @@ def prep(
option_cols=op_cols,
answer_cols=a_cols,
answer_template=a_template,
extra_info=extra_info,
labels=labels,
transforms=transforms,
verl_ability=verl_ability,
Expand Down
4 changes: 3 additions & 1 deletion src/prep/formatter/auto_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def auto_cls(
split: str,
a_cols: list[str],
transforms: list[str],
extra_info: str | None = None,
):
images = extract_images(e)
if len(images) != 1:
Expand All @@ -30,7 +31,7 @@ def auto_cls(
"id": f"{data_name}/{split}{idx:08d}",
"image": image,
"label": label,
"extra_info": e.get("extra_info", ""),
"extra_info": e.get(extra_info, extra_info) or "",
}
Comment on lines 33 to 35


Expand All @@ -47,6 +48,7 @@ def load_cls(path: str, split: str, args: ProcArgs):
split=split,
a_cols=args.answer_cols,
transforms=args.transforms,
extra_info=args.extra_info,
),
remove_columns=d.column_names,
num_proc=args.num_proc,
Expand Down
4 changes: 3 additions & 1 deletion src/prep/formatter/auto_sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def auto_sft(
option_cols: list[str],
q_template: str,
a_template: str,
extra_info: str | None = None,
) -> dict:
images = extract_images(e)
question, answer = extract_qa(
Expand All @@ -25,7 +26,7 @@ def auto_sft(
{"role": "assistant", "content": answer},
],
"id": f"{data_name}/{idx:08d}",
"extra_info": e.get("extra_info", ""),
"extra_info": e.get(extra_info, extra_info) or "",
}
Comment on lines 28 to 30


Expand All @@ -44,6 +45,7 @@ def load_sft(path: str, split: str, args: ProcArgs):
option_cols=args.option_cols,
q_template=args.question_template,
a_template=args.answer_template,
extra_info=args.extra_info,
),
remove_columns=d.column_names,
num_proc=args.num_proc,
Expand Down
4 changes: 3 additions & 1 deletion src/prep/formatter/auto_verl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def auto_verl(
a_template: str,
ability: str,
style: str,
extra_info: str | None = None,
):
images = extract_images(e)
question, answer = extract_qa(
Expand All @@ -35,7 +36,7 @@ def auto_verl(
"split": split,
"index": f"{idx:08d}",
"explanation": e.get("explanation", ""),
"misc": e.get("extra_info", ""),
"misc": e.get(extra_info, extra_info) or "",
},
Comment on lines 38 to 40
}

Expand All @@ -58,6 +59,7 @@ def load_verl(path: str, split: str, args: ProcArgs):
a_template=args.answer_template,
ability=args.verl_ability,
style=args.verl_style,
extra_info=args.extra_info,
),
remove_columns=d.column_names,
num_proc=args.num_proc,
Expand Down
8 changes: 7 additions & 1 deletion tests/formatter/test_auto_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ def test_auto_cls_basic(self):
}

result = auto_cls(
example, 0, data_name="test", split="train", a_cols=["label"], transforms=[]
example,
0,
data_name="test",
split="train",
a_cols=["label"],
transforms=[],
extra_info="extra_info",
)
Comment on lines +45 to 47

assert result["id"] == "test/train00000000"
Expand Down
1 change: 1 addition & 0 deletions tests/formatter/test_auto_sft.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_auto_sft_basic_text_only(self):
option_cols=[],
q_template="Question: {question}",
a_template="{answer}",
extra_info="extra_info",
)
Comment on lines 25 to 28

assert result["id"] == "test/00000000"
Expand Down
1 change: 1 addition & 0 deletions tests/formatter/test_auto_verl.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def test_auto_verl_extra_info_fields(self):
a_template="{answer}",
ability="math",
style="rule",
extra_info="extra_info",
)
Comment on lines 111 to 113

assert result["extra_info"]["split"] == "train"
Expand Down