Skip to content
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
44 changes: 22 additions & 22 deletions cli/alora/commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Typer sub-application for the ``m alora`` command group.
"""Typer sub-application for the `m alora` command group.

Provides three commands: ``train`` (fine-tune a base causal language model on a JSONL
dataset to produce a LoRA or aLoRA adapter), ``upload`` (push adapter weights to
Provides three commands: `train` (fine-tune a base causal language model on a JSONL
dataset to produce a LoRA or aLoRA adapter), `upload` (push adapter weights to
Hugging Face Hub, optionally packaging the adapter as an intrinsic with an
``io.yaml`` configuration), and ``add-readme`` (use an LLM to auto-generate and
upload an ``INTRINSIC_README.md`` for the trained adapter).
`io.yaml` configuration), and `add-readme` (use an LLM to auto-generate and
upload an `INTRINSIC_README.md` for the trained adapter).
"""

import json
Expand Down Expand Up @@ -37,12 +37,12 @@ def alora_train(
pairs. Supports both aLoRA (asymmetric LoRA) and standard LoRA adapters.

Prerequisites:
Mellea installed with adapter extras (``uv add mellea[adapters]``).
Mellea installed with adapter extras (`uv add mellea[adapters]`).
A CUDA, MPS, or CPU device available for training.

Output:
Saves adapter weights to the path specified by ``--outfile``. The output
directory contains an ``adapter_config.json`` and the trained weight
Saves adapter weights to the path specified by `--outfile`. The output
directory contains an `adapter_config.json` and the trained weight
files, ready for upload or local inference.

Examples:
Expand All @@ -56,8 +56,8 @@ def alora_train(
basemodel: Base model ID or path.
outfile: Path to save adapter weights.
promptfile: Path to load the prompt format file.
adapter: Adapter type; ``"alora"`` or ``"lora"``.
device: Device to train on: ``"auto"``, ``"cpu"``, ``"cuda"``, or ``"mps"``.
adapter: Adapter type; `"alora"` or `"lora"`.
device: Device to train on: `"auto"`, `"cpu"`, `"cuda"`, or `"mps"`.
epochs: Number of training epochs.
learning_rate: Learning rate for the optimizer.
batch_size: Per-device training batch size.
Expand Down Expand Up @@ -100,14 +100,14 @@ def alora_upload(
"""Upload a trained adapter to a remote model registry.

Pushes adapter weights to Hugging Face Hub, optionally packaging the adapter
as an intrinsic with an ``io.yaml`` configuration file.
as an intrinsic with an `io.yaml` configuration file.

Prerequisites:
Hugging Face CLI authenticated (``huggingface-cli login``).
Hugging Face CLI authenticated (`huggingface-cli login`).

Output:
Creates or updates a Hugging Face Hub repository at the name specified
by ``--name`` and uploads the adapter weight files.
by `--name` and uploads the adapter weight files.

Examples:
m alora upload ./adapter --name acme/my-alora
Expand All @@ -118,10 +118,10 @@ def alora_upload(
Args:
weight_path: Path to saved adapter weights directory.
name: Destination model name on Hugging Face Hub
(e.g. ``"acme/carbchecker-alora"``).
intrinsic: If ``True``, the adapter implements an intrinsic and an
``io.yaml`` file must also be provided.
io_yaml: Path to the ``io.yaml`` file configuring input/output processing
(e.g. `"acme/carbchecker-alora"`).
intrinsic: If `True`, the adapter implements an intrinsic and an
`io.yaml` file must also be provided.
io_yaml: Path to the `io.yaml` file configuring input/output processing
when the model is invoked as an intrinsic.
"""
from cli.alora.intrinsic_uploader import upload_intrinsic
Expand Down Expand Up @@ -179,12 +179,12 @@ def alora_add_readme(
Face Hub repository.

Prerequisites:
Hugging Face CLI authenticated (``huggingface-cli login``).
Hugging Face CLI authenticated (`huggingface-cli login`).
An LLM backend available for README generation.

Output:
Generates a README.md file, displays it for confirmation, and uploads
it to the Hugging Face Hub repository specified by ``--name``.
it to the Hugging Face Hub repository specified by `--name`.

Examples:
m alora add-readme data.jsonl --basemodel ibm-granite/granite-3.3-2b-instruct --name acme/my-alora
Expand All @@ -195,10 +195,10 @@ def alora_add_readme(
Args:
datafile: JSONL file with item/label pairs used to train the adapter.
basemodel: Base model ID or path.
promptfile: Path to the prompt format file, or ``None``.
promptfile: Path to the prompt format file, or `None`.
name: Destination model name on Hugging Face Hub.
hints: Path to a file containing additional domain hints, or ``None``.
io_yaml: Path to the ``io.yaml`` intrinsic configuration file, or ``None``.
hints: Path to a file containing additional domain hints, or `None`.
io_yaml: Path to the `io.yaml` intrinsic configuration file, or `None`.

Raises:
OSError: If no Hugging Face authentication token is found.
Expand Down
36 changes: 18 additions & 18 deletions cli/alora/intrinsic_uploader.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Upload a trained adapter to Hugging Face Hub in the intrinsic directory layout.

Creates or updates a private Hugging Face repository and uploads adapter weights
into a ``<intrinsic_name>/<base_model>/<adapter_type>`` sub-directory, together with
the required ``io.yaml`` configuration file. If an ``INTRINSIC_README.md`` exists in
the weight directory it is also uploaded as the repository's root ``README.md``.
Requires an authenticated Hugging Face token obtained via ``huggingface-cli login``.
into a `<intrinsic_name>/<base_model>/<adapter_type>` sub-directory, together with
the required `io.yaml` configuration file. If an `INTRINSIC_README.md` exists in
the weight directory it is also uploaded as the repository's root `README.md`.
Requires an authenticated Hugging Face token obtained via `huggingface-cli login`.
"""

import os
Expand Down Expand Up @@ -38,31 +38,31 @@ def upload_intrinsic(
"""Upload an adapter to Hugging Face Hub using the intrinsic directory layout.

Creates or updates a private Hugging Face repository and uploads adapter
weights into a ``<intrinsic_name>/<base_model>/<adapter_type>`` sub-directory,
together with the ``io.yaml`` configuration file. If an
``INTRINSIC_README.md`` exists in the weight directory it is also uploaded
as the repository root ``README.md``.
weights into a `<intrinsic_name>/<base_model>/<adapter_type>` sub-directory,
together with the `io.yaml` configuration file. If an
`INTRINSIC_README.md` exists in the weight directory it is also uploaded
as the repository root `README.md`.

Args:
weight_path (str): Local directory containing the adapter weights
(output of ``save_pretrained``).
(output of `save_pretrained`).
model_name (str): Target Hugging Face repository name in
``"<userid>/<intrinsic_name>"`` format (e.g. ``"acme/carbchecker-alora"``).
`"<userid>/<intrinsic_name>"` format (e.g. `"acme/carbchecker-alora"`).
base_model (str): Base model ID or path (e.g.
``"ibm-granite/granite-3.3-2b-instruct"``). Must contain at most
one ``"/"`` separator.
`"ibm-granite/granite-3.3-2b-instruct"`). Must contain at most
one `"/"` separator.
type (Literal['lora', 'alora']): Adapter type, used as the leaf
directory name in the repository layout.
io_yaml (str): Path to the ``io.yaml`` configuration file for
io_yaml (str): Path to the `io.yaml` configuration file for
intrinsic input/output processing.
private (bool): Whether the repository should be private. Currently
only ``True`` is supported.
only `True` is supported.

Raises:
AssertionError: If ``weight_path`` or ``io_yaml`` do not exist, if
``private`` is ``False``, if ``base_model`` contains more than one
``"/"`` separator, or if ``model_name`` does not contain exactly
one ``"/"`` separator.
AssertionError: If `weight_path` or `io_yaml` do not exist, if
`private` is `False`, if `base_model` contains more than one
`"/"` separator, or if `model_name` does not contain exactly
one `"/"` separator.
OSError: If no Hugging Face authentication token is found.
"""
try:
Expand Down
28 changes: 14 additions & 14 deletions cli/alora/readme_generator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""LLM-assisted generator for adapter intrinsic README files.

Uses a ``MelleaSession`` with rejection sampling to derive README template variables
Uses a `MelleaSession` with rejection sampling to derive README template variables
from a JSONL training dataset — including a high-level description, the inferred
Python argument list, and Jinja2-renderable sample rows. Validates the generated
output with deterministic requirements (correct naming conventions, syntactically
valid argument lists) before rendering the final ``INTRINSIC_README.md`` via a
valid argument lists) before rendering the final `INTRINSIC_README.md` via a
Jinja2 template.
"""

Expand All @@ -28,10 +28,10 @@ class ReadmeTemplateVars(BaseModel):
high_level_description (str): A 2-3 sentence description of what the intrinsic adapter does.
dataset_description (str): Brief description of the training dataset contents and format.
userid (str): HuggingFace user ID (the namespace portion of the model name).
intrinsic_name (str): Short snake_case identifier for the intrinsic (e.g. ``"carbchecker"``).
intrinsic_name_camelcase (str): CamelCase version of ``intrinsic_name`` (e.g. ``"CarbChecker"``).
arglist (str): Python function argument list with type hints (e.g. ``"description: str"``).
arglist_without_type_annotations (str): Argument list without type hints (e.g. ``"description"``).
intrinsic_name (str): Short snake_case identifier for the intrinsic (e.g. `"carbchecker"`).
intrinsic_name_camelcase (str): CamelCase version of `intrinsic_name` (e.g. `"CarbChecker"`).
arglist (str): Python function argument list with type hints (e.g. `"description: str"`).
arglist_without_type_annotations (str): Argument list without type hints (e.g. `"description"`).
"""

high_level_description: str
Expand Down Expand Up @@ -141,20 +141,20 @@ def make_readme_jinja_dict(
"""Generate all template variables for the intrinsic README using an LLM.

Loads the first five lines of the JSONL dataset, determines the input structure,
and uses ``m.instruct`` with deterministic requirements and rejection sampling to
and uses `m.instruct` with deterministic requirements and rejection sampling to
generate README template variables.

Args:
m: Active ``MelleaSession`` to use for LLM generation.
m: Active `MelleaSession` to use for LLM generation.
dataset_path: Path to the JSONL training dataset file.
base_model: Base model ID or path used to train the adapter.
prompt_file: Path to the prompt format file (empty string if not provided).
name: Destination model name on Hugging Face Hub
(e.g. ``"acme/carbchecker-alora"``).
(e.g. `"acme/carbchecker-alora"`).
hints: Optional string of additional domain hints to include in the prompt.

Returns:
Dict of Jinja2 template variables for rendering the ``INTRINSIC_README.md``.
Dict of Jinja2 template variables for rendering the `INTRINSIC_README.md`.
"""
# Load first 5 lines of the dataset.
samples = []
Expand Down Expand Up @@ -294,19 +294,19 @@ def generate_readme(
) -> str:
"""Generate an INTRINSIC_README.md file from the dataset and template.

Creates a ``MelleaSession``, uses the LLM to generate template variables,
renders the Jinja template, and writes the result to ``output_path``.
Creates a `MelleaSession`, uses the LLM to generate template variables,
renders the Jinja template, and writes the result to `output_path`.

Args:
dataset_path: Path to the JSONL training dataset file.
base_model: Base model ID or path used to train the adapter.
prompt_file: Path to the prompt format file, or ``None``.
prompt_file: Path to the prompt format file, or `None`.
output_path: Destination path for the generated README file.
name: Destination model name on Hugging Face Hub.
hints: Optional string of additional domain hints for the LLM.

Returns:
The path to the written output file (same as ``output_path``).
The path to the written output file (same as `output_path`).
"""
from jinja2 import Environment, FileSystemLoader

Expand Down
Loading
Loading