Text Generation
Transformers
PyTorch
TensorFlow
JAX
TensorBoard
Persian
gpt2
text-generation-inference
Run this model with HF Jobs
Run flax-community/gpt2-medium-persian 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 and TRL to fine-tune https://huggingface.co/flax-community/gpt2-medium-persian. 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/flax-community/gpt2-medium-persian 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/flax-community/gpt2-medium-persian. 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/flax-community/gpt2-medium-persian. 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 flax-community/gpt2-medium-persian with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use flax-community/gpt2-medium-persian with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="flax-community/gpt2-medium-persian")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("flax-community/gpt2-medium-persian") model = AutoModelForCausalLM.from_pretrained("flax-community/gpt2-medium-persian", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use flax-community/gpt2-medium-persian with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "flax-community/gpt2-medium-persian" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "flax-community/gpt2-medium-persian", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/flax-community/gpt2-medium-persian
- SGLang
How to use flax-community/gpt2-medium-persian with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "flax-community/gpt2-medium-persian" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "flax-community/gpt2-medium-persian", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "flax-community/gpt2-medium-persian" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "flax-community/gpt2-medium-persian", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use flax-community/gpt2-medium-persian with Docker Model Runner:
docker model run hf.co/flax-community/gpt2-medium-persian
Download src/create_config.py from flax-community/gpt2-medium-persian: direct link, hf CLI and curl.
- Browser
- Download file 2.32 kB
-
https://huggingface.co/flax-community/gpt2-medium-persian/resolve/main/src/create_config.py
- Command line
-
hf download hf://flax-community/gpt2-medium-persian/src/create_config.py
-
curl -L -o create_config.py https://huggingface.co/flax-community/gpt2-medium-persian/resolve/main/src/create_config.py
2.32 kB
| import ast | |
| import logging | |
| import os | |
| import sys | |
| from dataclasses import dataclass, field | |
| from typing import Dict, List, Optional, Tuple | |
| from transformers import ( | |
| HfArgumentParser, | |
| AutoConfig | |
| ) | |
| logger = logging.getLogger(__name__) | |
| class ConfigArguments: | |
| """ | |
| Arguments to which config we are going to set up. | |
| """ | |
| output_dir: str = field( | |
| default=".", | |
| metadata={"help": "The output directory where the config will be written."}, | |
| ) | |
| name_or_path: Optional[str] = field( | |
| default=None, | |
| metadata={ | |
| "help": "The model checkpoint for weights initialization." | |
| "Don't set if you want to train a model from scratch." | |
| }, | |
| ) | |
| params: Optional[str] = field( | |
| default=None, | |
| metadata={"help": "Custom configuration for the specific `name_or_path`"} | |
| ) | |
| def __post_init__(self): | |
| if self.params: | |
| try: | |
| self.params = ast.literal_eval(self.params) | |
| except Exception as e: | |
| print(f"Your custom parameters do not acceptable due to {e}") | |
| def main(): | |
| parser = HfArgumentParser([ConfigArguments]) | |
| if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): | |
| # If we pass only one argument to the script and it's the path to a json file, | |
| # let's parse it to get our arguments. | |
| config_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1]))[0] | |
| else: | |
| config_args = parser.parse_args_into_dataclasses()[0] | |
| # Setup logging | |
| logging.basicConfig( | |
| format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", | |
| datefmt="%m/%d/%Y %H:%M:%S", | |
| handlers=[logging.StreamHandler(sys.stdout)], | |
| ) | |
| logger.setLevel(logging.INFO) | |
| logger.info(f"Setting up configuration {config_args.name_or_path} with extra params {config_args.params}") | |
| if config_args.params and isinstance(config_args.params, dict): | |
| config = AutoConfig.from_pretrained(config_args.name_or_path, **config_args.params) | |
| else: | |
| config = AutoConfig.from_pretrained(config_args.name_or_path) | |
| logger.info(f"Your configuration saved here {config_args.output_dir}/config.json") | |
| config.save_pretrained(config_args.output_dir) | |
| if __name__ == '__main__': | |
| main() | |