-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Registry based config - Part 1 (#975)
- Loading branch information
Showing
28 changed files
with
788 additions
and
207 deletions.
There are no files selected for viewing
This file contains 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 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,84 @@ | ||
# :construction: LLM Foundry Registry | ||
|
||
Some components of LLM Foundry are registrable. This means that you can register options for these components, and then use them in your yaml config, without forking the library. | ||
|
||
## How to register | ||
|
||
There are a few ways to register a new component: | ||
|
||
### Python entrypoints | ||
|
||
You can specify registered components via a Python entrypoint if you are building your own package with registered components. | ||
|
||
For example, the following would register the `WandBLogger` class, under the key `wandb`, in the `llm_foundry.loggers` registry: | ||
|
||
<!--pytest.mark.skip--> | ||
```yaml | ||
[build-system] | ||
requires = ["setuptools>=42", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project] | ||
name = "foundry_registry" | ||
version = "0.1.0" | ||
dependencies = [ | ||
"mosaicml", | ||
"llm-foundry", | ||
] | ||
|
||
[project.entry-points."llm_foundry.loggers"] | ||
my_logger = "foundry_registry.loggers:MyLogger" | ||
``` | ||
|
||
### Direct call to register | ||
|
||
You can also register a component directly in your code: | ||
|
||
<!--pytest.mark.skip--> | ||
```python | ||
from composer.loggers import LoggerDestination | ||
from llmfoundry.registry import loggers | ||
|
||
class MyLogger(LoggerDestination): | ||
pass | ||
|
||
loggers.register("my_logger", func=MyLogger) | ||
``` | ||
|
||
### Decorators | ||
|
||
You can also use decorators to register components directly from your code: | ||
|
||
<!--pytest.mark.skip--> | ||
```python | ||
from composer.loggers import LoggerDestination | ||
from llmfoundry.registry import loggers | ||
|
||
@loggers.register("my_logger") | ||
class MyLogger(LoggerDestination): | ||
pass | ||
``` | ||
|
||
For both the direct call and decorator approaches, if using the LLM Foundry train/eval scripts, you will need to provide the `code_paths` argument, which is a list of files need to execute in order to register your components. For example, you may have a file called `foundry_imports.py` that contains the following: | ||
|
||
<!--pytest.mark.skip--> | ||
```python | ||
from foundry_registry.loggers import MyLogger | ||
from llmfoundry.registry import loggers | ||
|
||
loggers.register("my_logger", func=MyLogger) | ||
``` | ||
|
||
You would then provide `code_paths` to the train/eval scripts in your yaml config: | ||
|
||
<!--pytest.mark.skip--> | ||
```yaml | ||
... | ||
code_paths: | ||
- foundry_imports.py | ||
... | ||
``` | ||
|
||
|
||
## Discovering registrable components | ||
Coming soon |
This file contains 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 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,12 @@ | ||
# Copyright 2024 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from composer.algorithms import (Alibi, GatedLinearUnits, GradientClipping, | ||
LowPrecisionLayerNorm) | ||
|
||
from llmfoundry.registry import algorithms | ||
|
||
algorithms.register('gradient_clipping', func=GradientClipping) | ||
algorithms.register('alibi', func=Alibi) | ||
algorithms.register('gated_linear_units', func=GatedLinearUnits) | ||
algorithms.register('low_precision_layernorm', func=LowPrecisionLayerNorm) |
This file contains 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 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 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 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,8 @@ | ||
# Copyright 2024 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from llmfoundry.interfaces.callback_with_config import CallbackWithConfig | ||
|
||
__all__ = [ | ||
'CallbackWithConfig', | ||
] |
This file contains 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,21 @@ | ||
# Copyright 2024 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import abc | ||
from typing import Any | ||
|
||
from composer.core import Callback | ||
|
||
__all__ = ['CallbackWithConfig'] | ||
|
||
|
||
class CallbackWithConfig(Callback, abc.ABC): | ||
"""A callback that takes a config dictionary as an argument, in addition to. | ||
its other kwargs. | ||
""" | ||
|
||
def __init__(self, config: dict[str, Any], *args: Any, | ||
**kwargs: Any) -> None: | ||
del config, args, kwargs | ||
pass |
This file contains 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,14 @@ | ||
# Copyright 2024 MosaicML LLM Foundry authors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from composer.loggers import (InMemoryLogger, MLFlowLogger, TensorboardLogger, | ||
WandBLogger) | ||
|
||
from llmfoundry.registry import loggers | ||
|
||
loggers.register('wandb', func=WandBLogger) | ||
loggers.register('tensorboard', func=TensorboardLogger) | ||
loggers.register('inmemory', func=InMemoryLogger) | ||
loggers.register('in_memory_logger', | ||
func=InMemoryLogger) # for backwards compatibility | ||
loggers.register('mlflow', func=MLFlowLogger) |
This file contains 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.