Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add num_proc=4 to Dataset maps in Trainer #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions span_marker/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def preprocess_dataset(
if column not in dataset.column_names:
raise ValueError(f"The {dataset_name} dataset must contain a {column!r} column.")

dataset_num_proc = self.args.dataloader_num_workers or None

# Drop all unused columns, only keep "tokens", "ner_tags", "document_id", "sentence_id"
dataset = dataset.remove_columns(
set(dataset.column_names) - set(self.OPTIONAL_COLUMNS) - set(self.REQUIRED_COLUMNS)
Expand All @@ -203,6 +205,7 @@ def preprocess_dataset(
input_columns=("tokens", "ner_tags"),
desc=f"Label normalizing the {dataset_name} dataset",
batched=True,
num_proc=dataset_num_proc,
)

# Setting model card data based on training data
Expand Down Expand Up @@ -230,6 +233,7 @@ def preprocess_dataset(
remove_columns=set(dataset.column_names) - set(self.OPTIONAL_COLUMNS),
desc=f"Tokenizing the {dataset_name} dataset",
fn_kwargs={"return_num_words": is_evaluate},
num_proc=dataset_num_proc,
)
# If "document_id" AND "sentence_id" exist in the training dataset
if {"document_id", "sentence_id"} <= set(dataset.column_names):
Expand Down Expand Up @@ -265,6 +269,7 @@ def preprocess_dataset(
"model_max_length": tokenizer.model_max_length,
"marker_max_length": self.model.config.marker_max_length,
},
num_proc=dataset_num_proc,
)
new_length = len(dataset)
logger.info(
Expand Down
Loading