-
Notifications
You must be signed in to change notification settings - Fork 30
Reference model support for distillation,. etc. #216
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dbb6162
Reference model prototype
jlamypoirier fd38f7d
Merge remote-tracking branch 'origin/main' into reference_model
jlamypoirier ed8ec43
Generalize preprocessor
jlamypoirier c83076c
Merge branch 'preprocessor' into reference_model
jlamypoirier 8fe5973
fixes
jlamypoirier c8715e5
Merge branch 'preprocessor' into reference_model
jlamypoirier 191308c
fixes
jlamypoirier 4e6eaee
fix
jlamypoirier e2fe558
fix
jlamypoirier 52d160d
fix
jlamypoirier 35cc58b
fix
jlamypoirier 015232f
misc
jlamypoirier 16f71da
Merge branch 'main' into reference_model
jlamypoirier 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
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
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
File renamed without changes.
File renamed without changes.
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
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,58 @@ | ||
import abc | ||
import typing | ||
|
||
from fast_llm.config import NoAutoValidate | ||
from fast_llm.engine.distributed.config import PhaseType | ||
from fast_llm.engine.multi_stage.fast_llm_model import FastLLMModel | ||
from fast_llm.engine.schedule.config import BatchConfig, ScheduleConfig | ||
from fast_llm.engine.schedule.runner import ScheduleRunner | ||
from fast_llm.engine.schedule.schedule import Schedule | ||
|
||
|
||
class InferenceRunner(abc.ABC): | ||
model_class: typing.ClassVar[type[FastLLMModel]] = FastLLMModel | ||
|
||
def __init__(self, fast_llm_model: FastLLMModel): | ||
assert isinstance(fast_llm_model, self.model_class) | ||
self._fast_llm_model = fast_llm_model | ||
# We only need a basic schedule and don't care about dimensions. | ||
self._schedule_config = ScheduleConfig() | ||
# TODO: Sort things out. | ||
with NoAutoValidate(): | ||
self._batch_config = BatchConfig() | ||
self._batch_config.setup(self._fast_llm_model.config.distributed) | ||
self._batch_config.validate() | ||
self._runner = ScheduleRunner( | ||
config=self._schedule_config, | ||
multi_stage=self._fast_llm_model, | ||
distributed_config=self._fast_llm_model.config.distributed, | ||
) | ||
# TODO: Random state? (Distributed.set_step) | ||
self._schedule = Schedule( | ||
multi_stage=self._fast_llm_model, | ||
batch_config=self._batch_config, | ||
schedule_config=self._schedule_config, | ||
distributed_config=self._fast_llm_model.config.distributed, | ||
phase=PhaseType.inference, | ||
) | ||
|
||
@property | ||
def fast_llm_model(self) -> FastLLMModel: | ||
return self._fast_llm_model | ||
|
||
def setup(self): | ||
self._runner.setup(self._fast_llm_model.distributed) | ||
|
||
def forward( | ||
self, input_, kwargs: dict, *, iteration: int = 1, return_metrics: bool = False | ||
) -> tuple[dict[str, float | int], dict[str, typing.Any] | None]: | ||
# TODO: Return an actual model output. | ||
reduced_losses, update_successful, metrics = self._runner.run_step( | ||
iter((((input_, kwargs),),)), | ||
self._schedule, | ||
iteration=iteration, | ||
return_metrics=return_metrics, | ||
preprocessed=True, | ||
) | ||
assert update_successful | ||
return reduced_losses, metrics |
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like us to work on this in a separate PR soon, because this is needed for running generative benchmarks during training.