Run this model with HF Jobs
Run ammarnasr/codegen-350M-mono-java 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/ammarnasr/codegen-350M-mono-java. 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/ammarnasr/codegen-350M-mono-java 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.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/ammarnasr/codegen-350M-mono-java. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/ammarnasr/codegen-350M-mono-java. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use ammarnasr/codegen-350M-mono-java with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Adapters
How to use ammarnasr/codegen-350M-mono-java with Adapters:
from adapters import AutoAdapterModel model = AutoAdapterModel.from_pretrained("<base-model-id>") model.load_adapter("ammarnasr/codegen-350M-mono-java", set_active=True) - Notebooks
- Google Colab
- Kaggle
Download handler.py from ammarnasr/codegen-350M-mono-java: direct link, hf CLI and curl.
- Browser
- Download file 1.49 kB
-
https://huggingface.co/ammarnasr/codegen-350M-mono-java/resolve/main/handler.py
- Command line
-
hf download hf://ammarnasr/codegen-350M-mono-java/handler.py
-
curl -L -o handler.py https://huggingface.co/ammarnasr/codegen-350M-mono-java/resolve/main/handler.py
1.49 kB
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from peft import PeftConfig | |
| from peft import PeftModel | |
| import torch.cuda | |
| from typing import Any, Dict | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| class EndpointHandler(): | |
| def __init__(self, path=""): | |
| config = PeftConfig.from_pretrained(path) | |
| model = AutoModelForCausalLM.from_pretrained(config.base_model_name_or_path) | |
| self.tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path) | |
| # Load the Lora model | |
| self.model = PeftModel.from_pretrained(model, path) | |
| def __call__(self, data: Dict[str, Any]) -> Dict[str, Any]: | |
| """ | |
| Args: | |
| data (Dict): The payload with the text prompt | |
| and generation parameters. | |
| """ | |
| # Get inputs | |
| prompt = data.pop("inputs", None) | |
| parameters = data.pop("parameters", None) | |
| if prompt is None: | |
| raise ValueError("Missing prompt.") | |
| # Preprocess | |
| input_ids = self.tokenizer(prompt, return_tensors="pt").input_ids.to(device) | |
| # Forward | |
| if parameters is not None: | |
| output = self.model.generate(input_ids=input_ids, **parameters) | |
| else: | |
| output = self.model.generate(input_ids=input_ids) | |
| # Postprocess | |
| prediction = self.tokenizer.decode(output[0]) | |
| return {"generated_text": prediction} |