-
Notifications
You must be signed in to change notification settings - Fork 86
Metrics for training #982
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
Merged
Merged
Metrics for training #982
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
9625ce6
feat: metrics for training
michaelbenayoun c212f8c
feat: metrics for training
michaelbenayoun 833888e
feat: metrics for training
michaelbenayoun 9dd04c5
feat: metrics for training
michaelbenayoun f85638a
feat: metrics for training
michaelbenayoun dcd5883
feat: metrics for training
michaelbenayoun 3d1fd56
feat: add summary for metrics
michaelbenayoun 4df2d90
feat: add summary for metrics
michaelbenayoun ea5edf0
feat: effective throughput
michaelbenayoun cb0a5b3
feat: polishing the metrics classes
michaelbenayoun 879d75a
feat: optimization of metric computation
michaelbenayoun e99d37d
test: add tests for metrics, wip
michaelbenayoun 902d69e
Add training efficiency
michaelbenayoun 9ba7d53
feat: add overhead time
michaelbenayoun 7d6ff60
feat: cleanup and keep training efficiency
michaelbenayoun b86dfc2
feat: remove docstrings
michaelbenayoun 5168337
feat: remove backward compatibility code
michaelbenayoun f2498c1
feat: keep relevant metrics
michaelbenayoun 14cb336
feat: add metrics breakdown
michaelbenayoun 6e391bf
feat: handle the case where there are no metrics
michaelbenayoun 2d8e8e0
fix: change sec to % for percents
michaelbenayoun 090a7c5
remove test_metrics.py
michaelbenayoun 26a0f19
test: add tests for metrics
michaelbenayoun 7ef5ed5
test: improve metrics tests
michaelbenayoun 08c6db4
test: improve metrics tests
michaelbenayoun 5499f19
feat: added plugin system for metrics
michaelbenayoun 48c620d
refactor: delete metric.py file since plugin system changes that
michaelbenayoun aa9821e
refactor: improve the existing base
michaelbenayoun 8025e1b
refactor: easier imports
michaelbenayoun b987e04
refactor: easier imports
michaelbenayoun d8b38fc
test: improve metrics tests
michaelbenayoun a47e9b7
test: improve metrics tests
michaelbenayoun 1975137
test: improve metrics tests
michaelbenayoun b4543ea
Merge branch 'main' into metrics
michaelbenayoun 0ed9244
test: improve metrics tests
michaelbenayoun 99e0eb5
fix: mfu computation
michaelbenayoun 7f142e5
fix: mfu computation
michaelbenayoun c155c57
fix: training effiency
michaelbenayoun 5302622
fix: add missing files
michaelbenayoun a7f9ea7
feat: enable metrics collection only for the rank responsible for log…
michaelbenayoun 6c616db
wip: test metrics
michaelbenayoun 6aca088
test: change the assert criteria to account for rounding
michaelbenayoun a42a095
feat: add hardware specs per dtype
michaelbenayoun 53ea695
fix: broken import
michaelbenayoun 564ee50
refactor: mfu computation in a function
michaelbenayoun 4b5480e
fix: restore finetune_qwen3.sh
michaelbenayoun 86918db
fix: divide the flops constants by 8 for trn2 and take the lnc into a…
michaelbenayoun 681ebec
fix: add useful comment
michaelbenayoun ea70bb8
fix: cache dtype entry
michaelbenayoun 3e0cdb7
Merge branch 'main' into metrics
michaelbenayoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,12 @@ export MALLOC_ARENA_MAX=64 # Host OOM mitigation | |
| PROCESSES_PER_NODE=32 | ||
| NUM_EPOCHS=3 | ||
| TP_DEGREE=8 | ||
| PP_DEGREE=4 | ||
| BS=1 | ||
| GRADIENT_ACCUMULATION_STEPS=8 | ||
| LOGGING_STEPS=2 | ||
| MODEL_NAME="Qwen/Qwen3-8B" # Change this to the desired model name | ||
| # MODEL_NAME="Qwen/Qwen3-8B" # Change this to the desired model name | ||
| MODEL_NAME="Qwen/Qwen3-0.6B" # Change this to the desired model name | ||
|
||
| OUTPUT_DIR="$(echo $MODEL_NAME | cut -d'/' -f2)-finetuned" | ||
| DISTRIBUTED_ARGS="--nproc_per_node $PROCESSES_PER_NODE" | ||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
|
@@ -34,6 +36,7 @@ torchrun --nproc_per_node $PROCESSES_PER_NODE finetune_qwen3.py \ | |
| --learning_rate 8e-4 \ | ||
| --bf16 \ | ||
| --tensor_parallel_size $TP_DEGREE \ | ||
| --pipeline_parallel_size $PP_DEGREE \ | ||
michaelbenayoun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --zero_1 \ | ||
| --async_save \ | ||
| --logging_steps $LOGGING_STEPS \ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 The HuggingFace Inc. team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from .collector import TrainingMetricsCollector | ||
| from .window import MovingAverageWindow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 The HuggingFace Inc. team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from ..training_args import NeuronTrainingArguments | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .collector import TrainingMetricsCollector | ||
|
|
||
|
|
||
| class MetricUnit: | ||
| SECONDS = "s" | ||
| MILLISECONDS = "ms" | ||
| TOKENS_PER_SECOND = "tokens/s" | ||
| SAMPLES_PER_SECOND = "samples/s" | ||
| PERCENT = "%" | ||
| COUNT = "count" | ||
| TFLOPS = "TFLOP/s" | ||
| RATIO = "ratio" | ||
| NONE = "" | ||
|
|
||
|
|
||
| @dataclass | ||
| class MetricPlugin(ABC): | ||
| """Base class for metrics plugins. Each plugin calculates one type of metric.""" | ||
|
|
||
| name: str | ||
| requires_accumulation: bool = False | ||
| depends_on: list[str] | None = None | ||
|
|
||
| @abstractmethod | ||
| def is_enabled(self, args: NeuronTrainingArguments) -> bool: | ||
| """Check if this plugin should be active.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def calculate_realtime(self, window_stats: dict, collector: "TrainingMetricsCollector") -> dict[str, float]: | ||
| """Calculate train/ metrics from current window data.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def calculate_summary(self, summary_data: dict, collector: "TrainingMetricsCollector") -> dict[str, float]: | ||
| """Calculate summary/ metrics from all collected data.""" | ||
| pass | ||
|
|
||
| def get_metric_names(self) -> list[str]: | ||
| """Get the metrics this plugin provides. Override for multi-metric plugins.""" | ||
| return [self.name] | ||
|
|
||
| def handles_metric(self, metric_name: str) -> bool: | ||
| """Check if this plugin handles the given metric.""" | ||
| return metric_name in self.get_metric_names() | ||
|
|
||
| def get_metric_units(self) -> dict[str, str]: | ||
| """Get units for each metric this plugin produces. Override in subclasses.""" | ||
| return dict.fromkeys(self.get_metric_names(), MetricUnit.NONE) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.