Run this model with HF Jobs

Run 2npc/gemma2-9b-drs-lora on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/2npc/gemma2-9b-drs-lora. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/2npc/gemma2-9b-drs-lora on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

DRS Parser: Gemma-2-9B-it + LoRA (silver_gold)

A DRS (Discourse Representation Structure) parser for English. Give it a sentence and it returns its meaning in SBN (Simple Box Notation), the format used by the Parallel Meaning Bank:

Input:  He organized a summer rock festival.
Output: male.n.02 organize.v.03 Agent -1 Time +1 Result +4 time.n.08 TPR now summer.n.01 rock.n.06 festival.n.02 Time -2 Theme -1

It is a LoRA adapter (108 MB) for google/gemma-2-9b-it, fine-tuned with LLaMA-Factory. The base model (18 GB) downloads automatically the first time you run it.

What you need

  • An NVIDIA GPU with at least 24 GB of memory, for example an A100, L4, RTX 3090 or RTX 4090. A cluster node or a Google Colab L4/A100 runtime also works. CPU-only machines and Macs are too slow for practical use.
  • Python 3.9 or newer.
  • A free Hugging Face account.

Quick start

1. Get access to Gemma (one time). Open the gemma-2-9b-it page, log in, and accept the license. Access is usually granted right away. Then log in from the terminal:

pip install -U huggingface_hub
hf auth login

Use a token from https://huggingface.co/settings/tokens; the "Read" type is enough.

2. Download this repo and install the dependencies:

hf download 2npc/gemma2-9b-drs-lora --local-dir drs-parser
cd drs-parser
pip install torch "transformers>=4.44" "peft>=0.11" accelerate

3. Parse a sentence:

python inference.py --text "He organized a summer rock festival."

The first run downloads the base model, which takes a few minutes. Later runs start much faster.

Parse many sentences at once

Put your sentences in a JSON file:

[
  {"input": "He organized a summer rock festival."},
  {"input": "Mary was impressed with what she saw."}
]
python inference.py --in_json data.json --out_json data_pred.json

Each record in data_pred.json gets an output field with its parse.

Other options:

  • --max_new_tokens: raise it if long outputs get cut off (default 1024).
  • --base: path to a local copy of gemma-2-9b-it.

Common problems

Error Fix
401 / GatedRepoError / "Access to model google/gemma-2-9b-it is restricted" You have not accepted the Gemma license yet, or you are not logged in. Repeat step 1.
CUDA out of memory The GPU has less than 24 GB. Use a bigger GPU.
hf: command not found Run pip install -U huggingface_hub, then open a new terminal.
Very slow, "no GPU found" PyTorch cannot see a GPU. Install the CUDA build of PyTorch from https://pytorch.org.

Use it in your own code

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

base = "google/gemma-2-9b-it"
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, torch_dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, "2npc/gemma2-9b-drs-lora").eval()

instruction = "Please parse the following text in Discourse Representation Structure:"
text = "He organized a summer rock festival."
prompt = f"<start_of_turn>user\n{instruction}\n{text}<end_of_turn>\n<start_of_turn>model\n"

inputs = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**inputs, max_new_tokens=1024, do_sample=False,
                     eos_token_id=[tok.eos_token_id, tok.convert_tokens_to_ids("<end_of_turn>")])
print(tok.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip())

Keep the prompt in exactly this layout, with the same instruction text the model was trained on. The tokenizer adds <bos> itself.

Merge into a standalone model (optional)

Merging bakes the LoRA into the base weights. The result is a normal ~18 GB model that loads without peft, which also lets you serve it with tools such as vLLM:

model = PeftModel.from_pretrained(base_model, "2npc/gemma2-9b-drs-lora").merge_and_unload()
model.save_pretrained("gemma2-9b-drs-merged")
tok.save_pretrained("gemma2-9b-drs-merged")

Training details

  • Base model: google/gemma-2-9b-it
  • Method: LoRA, r=8, alpha=16, dropout 0. Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
  • Data: English text paired with gold DRSs in SBN format (LLaMA-Factory dataset DRS_parsing_gold)
  • Training: 10 epochs (2,980 steps), learning rate 1e-4 with a cosine schedule and 10% warmup. Effective batch size 32 (4 GPUs ร— 1 ร— 8 gradient accumulation). bf16 mixed precision, seed 42.
  • Final train loss 0.0077, eval loss 0.0361
  • Framework: LLaMA-Factory, PEFT 0.11.1, Transformers 4.44.0, PyTorch 2.2.0

License

This adapter is a derivative of Gemma. Gemma is provided under and subject to the Gemma Terms of Use found at https://ai.google.dev/gemma/terms. By using this adapter you agree to those terms, including the Gemma Prohibited Use Policy.

Downloads last month
39
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for 2npc/gemma2-9b-drs-lora

Adapter
(498)
this model