Skip to content

Commit 6901c93

Browse files
authored
feat: Move functionality of granite-common to mellea (#571)
* Fix broken tests Signed-off-by: Fred Reiss <frreiss@us.ibm.com> * Update test outputs for upstream bug fix Signed-off-by: Fred Reiss <frreiss@us.ibm.com> * Import code from granite-common Signed-off-by: Fred Reiss <frreiss@us.ibm.com> --------- Signed-off-by: Fred Reiss <frreiss@us.ibm.com>
1 parent 78c5aab commit 6901c93

58 files changed

Lines changed: 6858 additions & 269 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/alora/README_TEMPLATE.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ from mellea.core import Context
4141
from mellea.backends import Backend
4242
from mellea.stdlib.components.simple import SimpleComponent
4343
from mellea.backends.adapters import AdapterMixin
44-
from mellea.backends.adapters.adapter import CustomGraniteCommonAdapter
44+
from mellea.backends.adapters.adapter import CustomIntrinsicAdapter
4545
from mellea.stdlib.components.intrinsic import Intrinsic
4646

4747

4848
_INTRINSIC_MODEL_ID = "{{ userid }}/{{ intrinsic_name }}"
4949
_INTRINSIC_ADAPTER_NAME = "{{ intrinsic_name }}"
5050

5151

52-
class {{ intrinsic_name_camelcase }}Adapter(CustomGraniteCommonAdapter):
52+
class {{ intrinsic_name_camelcase }}Adapter(CustomIntrinsicAdapter):
5353
def __init__(self, base_model_name: str):
5454
super().__init__(
5555
model_id=_INTRINSIC_MODEL_ID,

cli/alora/commands.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ def alora_upload(
4747
),
4848
intrinsic: bool = typer.Option(
4949
default=False,
50-
help="Formats model upload using granite-intrinsic. An io.yaml file must be provided.",
50+
help="True if the uploaded adapter implements an intrinsic. "
51+
"If true, the caller must provide an io.yaml file.",
5152
),
5253
io_yaml: str = typer.Option(
5354
default=None,
54-
help="Location of a granite-common io.yaml file. See https://nfulton.org/blog/alora_io_yaml.html",
55+
help="Location of the io.yaml file that configures input and output "
56+
"processing if the model is invoked as an intrinsic.",
5557
),
5658
):
5759
"""Upload trained adapter to remote model registry."""
@@ -99,7 +101,8 @@ def alora_add_readme(
99101
),
100102
io_yaml: str = typer.Option(
101103
default=None,
102-
help="Location of a granite-common io.yaml file. See https://nfulton.org/blog/alora_io_yaml.html",
104+
help="Location of the io.yaml file that configures input and output "
105+
"processing if the model is invoked as an intrinsic.",
103106
),
104107
):
105108
"""Generate and upload an INTRINSIC_README.md for a trained adapter."""

docs/dev/intrinsics_and_adapters.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Intrinsics and Adapters
2-
Note: Mellea currently only supports GraniteCommonAdapters and Intrinsics.
2+
Note: Mellea currently only supports IntrinsicAdapters and Intrinsics.
33

44
## Basics
55
In Mellea, intrinsics are a type of Component that signals one or more of the following to a backend:
@@ -24,7 +24,7 @@ Adapters specify:
2424
- functions for getting a path to load them
2525

2626
## Using Intrinsics
27-
Mellea Intrinsics currently utilize the granite-common package for loading adapters and formatting input/outputs (https://github.com/ibm-granite/granite-common). This means Mellea only allows intrinsics/adapters that follow this pattern.
27+
Mellea Intrinsics currently use the routines under `mellea.formatters.granite` for loading adapters and formatting input/outputs. This means Mellea only allows intrinsics/adapters that follow this pattern.
2828

2929
## Needed Future Work
3030
### Custom Adapters / Intrinsics

docs/dev/requirement_aLoRA_rerouting.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ Suppose that the user creates a backend and then adds a generic constraint check
3434
```python
3535
from mellea import start_session
3636
from mellea.core import Requirement
37-
from mellea.backends.adapters import GraniteCommonAdapter
37+
from mellea.backends.adapters import IntrinsicAdapter
3838

3939
m = start_session(
4040
"huggingface.LocalHFBackend:ibm-granite/granite-4.0-micro")
4141

42-
# By default, the AloraRequirement uses a GraniteCommonAdapter with "requirement_check".
43-
m.backend.add_adapter(GraniteCommonAdapter("ibm-granite/rag-intrinsics-lib", "requirement_check", base_model_name="granite-4.0-micro"))
42+
# By default, the AloraRequirement uses a IntrinsicAdapter with "requirement_check".
43+
m.backend.add_adapter(IntrinsicAdapter("ibm-granite/rag-intrinsics-lib", "requirement_check", base_model_name="granite-4.0-micro"))
4444

4545
m.instruct(
4646
"Corporate wants you to find the difference between these two strings:\n\naaa\naba")

docs/docs/api/mellea/backends/adapters/adapter.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ Returns the path needed to load the adapter.
106106

107107
<div className="w-full h-px bg-gray-200 dark:bg-gray-700 my-4" />
108108

109-
### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#4ADE8033]/20 text-[#15803D]">CLASS</span> `GraniteCommonAdapter` <sup><a href="https://github.com/generative-computing/mellea/blob/main/mellea/backends/adapters/adapter.py#L73" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
109+
### <span className="ml-2 inline-flex items-center rounded-full px-2 py-1 text-[0.7rem] font-bold tracking-wide bg-[#4ADE8033]/20 text-[#15803D]">CLASS</span> `IntrinsicAdapter` <sup><a href="https://github.com/generative-computing/mellea/blob/main/mellea/backends/adapters/adapter.py#L73" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
110110

111111

112-
Adapter for intrinsics that utilize the ``granite-common`` library.
112+
Adapter for intrinsics that use the input and output processing routines in `mellea.formatters.granite.intrinsics`.
113113

114114

115115

docs/docs/dev/intrinsics-and-adapters.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Developer notes on Intrinsics and Adapters."
55

66
# Intrinsics and Adapters
77

8-
Note: Mellea currently only supports GraniteCommonAdapters and Intrinsics.
8+
Note: Mellea currently only supports IntrinsicAdapters and Intrinsics.
99

1010
## Basics
1111
In Mellea, intrinsics are a type of Component that signals one or more of the following to a backend:
@@ -30,7 +30,7 @@ Adapters specify:
3030
- functions for getting a path to load them
3131

3232
## Using Intrinsics
33-
Mellea Intrinsics currently utilize the granite-common package for loading adapters and formatting input/outputs (https://github.com/ibm-granite/granite-common). This means Mellea only allows intrinsics/adapters that follow this pattern.
33+
Mellea Intrinsics currently use the routines under `mellea.formatters.granite` for loading adapters and formatting input/outputs. This means Mellea only allows intrinsics/adapters that follow this pattern.
3434

3535
## Needed Future Work
3636
### Custom Adapters / Intrinsics

docs/docs/dev/requirement-alora-rerouting.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ from mellea.stdlib.requirement import Requirement
4343
m = start_session(
4444
"huggingface.LocalHFBackend:ibm-granite/granite-3.2-8b-instruct")
4545

46-
## By default, the AloraRequirement uses a GraniteCommonAdapter with "requirement_check".
47-
m.backend.add_adapter(GraniteCommonAdapter("ibm-granite/rag-intrinsics-lib", "requirement_check", base_model_name="granite-3.2-8b-instruct"))
46+
## By default, the AloraRequirement uses a IntrinsicAdapter with "requirement_check".
47+
m.backend.add_adapter(IntrinsicAdapter("ibm-granite/rag-intrinsics-lib", "requirement_check", base_model_name="granite-3.2-8b-instruct"))
4848

4949
m.instruct(
5050
"Corporate wants you to find the difference between these two strings:\n\naaa\naba")

docs/examples/aLora/101_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import time
55

66
from mellea import MelleaSession
7-
from mellea.backends.adapters.adapter import CustomGraniteCommonAdapter
7+
from mellea.backends.adapters.adapter import CustomIntrinsicAdapter
88
from mellea.backends.cache import SimpleLRUCache
99
from mellea.backends.huggingface import LocalHFBackend
1010
from mellea.core import GenerateLog
@@ -18,7 +18,7 @@
1818
m = MelleaSession(backend=backend, ctx=ChatContext())
1919

2020

21-
class StemboltAdapter(CustomGraniteCommonAdapter):
21+
class StemboltAdapter(CustomIntrinsicAdapter):
2222
def __init__(self):
2323
super().__init__(
2424
model_id="nfulton/stembolts",

docs/examples/aLora/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ The generator will display the README and ask for confirmation before uploading
9191
You can now create a new adapter class for this model somewhere in your python project:
9292

9393
```python
94-
from mellea.backends.adapters.adapter import CustomGraniteCommonAdapter
94+
from mellea.backends.adapters.adapter import CustomIntrinsicAdapter
9595

96-
class StemboltAdapter(CustomGraniteCommonAdapter):
96+
class StemboltAdapter(CustomIntrinsicAdapter):
9797
def __init__(self, base_model_name:str="granite-4.0-micro"):
9898
super().__init__(
9999
model_id="$USERNAME/stembolts", # REPLACE $USERNAME WITH YOUR HUGGINGFACE USERNAME

docs/examples/aLora/stembolts_intrinsic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import mellea.stdlib.functional as mfuncs
66
from mellea.backends import Backend
77
from mellea.backends.adapters import AdapterMixin
8-
from mellea.backends.adapters.adapter import CustomGraniteCommonAdapter
8+
from mellea.backends.adapters.adapter import CustomIntrinsicAdapter
99
from mellea.core import Context
1010
from mellea.stdlib.components import Message
1111
from mellea.stdlib.components.intrinsic import Intrinsic
@@ -15,7 +15,7 @@
1515
_INTRINSIC_ADAPTER_NAME = "stembolts"
1616

1717

18-
class StemboltAdapter(CustomGraniteCommonAdapter):
18+
class StemboltAdapter(CustomIntrinsicAdapter):
1919
def __init__(self, base_model_name: str):
2020
super().__init__(
2121
model_id=_INTRINSIC_MODEL_ID,

0 commit comments

Comments
 (0)