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

Sync eval changes in OLMo/ladder-1xC to here #122

Merged
merged 23 commits into from
Dec 19, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added support for tensor parallelism. See the `TransformerConfig` class for usage.
- Added more downstream tasks from the model ladder.
- Added `io.copy_dir()` function.
- Added new LR schedulers: `LinearWithWarmup`, `InvSqrtWithWarmup`, `ConstantWithWarmup`, `SequentialScheduler`.
- Added option to pre-download checkpoint files from remote storage before trying to load a checkpoint.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies = [
"omegaconf",
"safetensors",
"importlib_resources",
"ai2-olmo-eval==0.2.0",
"ai2-olmo-eval==0.5.0",
]

[project.urls]
Expand Down
17 changes: 11 additions & 6 deletions src/olmo_core/train/callbacks/evaluator_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def post_step(self):
metrics = []
with cuda_sync_debug_mode(0):
for name, value in evaluator.compute_metrics().items():
value = value.item()
metrics.append(f" {name}={format_float(value)}")
self.trainer.record_metric(f"eval/{evaluator.name}/{name}", value)
log.info("Eval metrics:\n" + "\n".join(metrics))
Expand Down Expand Up @@ -161,6 +160,8 @@ class DownstreamEvaluator(Evaluator):
"pmi_dc": "PMI-DC accuracy",
"ce_loss": "CE loss",
"bpb": "BPB",
"soft": "soft loss",
"soft_log": "log soft loss",
}

def __init__(
Expand All @@ -184,13 +185,14 @@ def __init__(
if is_distributed():
sampler = DistributedSampler(
self.task, # type: ignore
drop_last=True,
drop_last=False,
shuffle=False,
num_replicas=get_world_size(dp_process_group),
rank=get_rank(dp_process_group),
)

rank_batch_size_instances = max(0, rank_batch_size // self.task.max_sequence_length)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a bug. I don't see why we should divide batch size by seq len. Batch size was already number of examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Batch size was already number of examples.

Where was it set to number of examples instead of tokens? It should always be set in tokens. This change will cause bugs elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's derived from Line 230 of this file, eval_batch_size. Do you mean this variable should be in number of tokens? It seems to be a semantic change from the old repo, and each eval's max seq length is dependent on the task so we can't set a fixed batch size ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a change from the old repo.

each eval's max seq length is dependent on the task so we can't set a fixed batch size

Well batch size is roughly fixed by number of tokens, not instances. This is more efficient because we can pack more instances from shorter tasks together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I've reverted it so now eval_batch_size takes number of tokens.


log.info(
f"Using per-rank batch size of {rank_batch_size_instances} instances "
f"for downstream eval task '{task}' with max sequence length {self.task.max_sequence_length:,d} tokens"
Expand All @@ -215,9 +217,12 @@ def update_metrics(
self.metric.update(batch, logits)

def compute_metrics(self) -> Dict[str, torch.Tensor]:
value = self.metric.compute()
label = f"{self.label} ({self.metric_type_to_label[self.task.metric_type]})"
return {label: value}
metric_type_to_value = self.metric.compute()
outputs = {}
for metric_type, value in metric_type_to_value.items():
key = f"{self.label} ({self.metric_type_to_label[metric_type]})"
outputs[key] = value.item()
return outputs

def reset_metrics(self) -> None:
self.metric.reset()
Expand All @@ -227,7 +232,7 @@ def reset_metrics(self) -> None:
class DownstreamEvaluatorCallbackConfig(CallbackConfig):
tasks: List[str]
tokenizer: TokenizerConfig
eval_batch_size: Optional[int] = None
eval_batch_size: Optional[int] = None # NOTE: this counts in number of tokens
eval_interval: int = 1000
eval_duration: Duration = field(default_factory=lambda: Duration.epochs(1))
log_interval: int = 5
Expand Down
45 changes: 45 additions & 0 deletions src/scripts/train/OLMo2-1B.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from olmo_core.optim import AdamWConfig, OptimGroupOverride
from olmo_core.train import TrainerConfig
from olmo_core.train.callbacks import CheckpointerCallback, CometCallback, WandBCallback
from olmo_core.train.callbacks.evaluator_callback import (
DownstreamEvaluatorCallbackConfig,
)


def build_model_config(common: CommonComponents) -> TransformerConfig:
Expand Down Expand Up @@ -73,6 +76,48 @@ def build_trainer_config(common: CommonComponents) -> TrainerConfig:
cancel_check_interval=10,
),
)
.with_callback(
"downstream_evaluator",
DownstreamEvaluatorCallbackConfig(
tasks=[
"arc_challenge_val_rc_5shot",
"arc_challenge_val_mc_5shot",
"arc_challenge_test_rc_5shot",
"arc_challenge_test_mc_5shot",
"arc_easy_val_rc_5shot",
"arc_easy_val_mc_5shot",
"arc_easy_test_rc_5shot",
"arc_easy_test_mc_5shot",
"boolq_val_rc_5shot",
"boolq_val_mc_5shot",
"csqa_val_rc_5shot",
"csqa_val_mc_5shot",
"hellaswag_val_rc_5shot",
"hellaswag_val_mc_5shot",
"openbookqa_val_rc_5shot",
"openbookqa_val_mc_5shot",
"openbookqa_test_rc_5shot",
"openbookqa_test_mc_5shot",
"piqa_val_rc_5shot",
"piqa_val_mc_5shot",
"socialiqa_val_rc_5shot",
"socialiqa_val_mc_5shot",
"winogrande_val_rc_5shot",
"winogrande_val_mc_5shot",
"mmlu_stem_val_rc_5shot",
"mmlu_stem_val_mc_5shot",
"mmlu_humanities_val_rc_5shot",
"mmlu_humanities_val_mc_5shot",
"mmlu_social_sciences_val_rc_5shot",
"mmlu_social_sciences_val_mc_5shot",
"mmlu_other_val_rc_5shot",
"mmlu_other_val_mc_5shot",
],
tokenizer=common.tokenizer,
eval_batch_size=1024 * 4096,
eval_interval=1000,
),
)
)


Expand Down
Loading