--- library_name: onnx tags: - text-generation - gpt2 - onnx - inference4j license: mit pipeline_tag: text-generation --- # GPT-2 — ONNX ONNX export of [GPT-2](https://huggingface.co/openai-community/gpt2) (124M parameters) with KV cache support for efficient autoregressive generation. Converted for use with [inference4j](https://github.com/inference4j/inference4j), an inference-only AI library for Java. ## Original Source - **Repository:** [OpenAI](https://huggingface.co/openai-community/gpt2) - **License:** MIT ## Usage with inference4j ```java try (Gpt2TextGenerator gen = Gpt2TextGenerator.builder().build()) { GenerationResult result = gen.generate("Once upon a time"); System.out.println(result.text()); } ``` ## Model Details | Property | Value | |----------|-------| | Architecture | GPT-2 (124M parameters, 12 layers, 768 hidden, 12 heads) | | Task | Text generation | | Context length | 1024 tokens | | Vocabulary | 50257 tokens (BPE) | | Original framework | PyTorch (transformers) | | Export method | Hugging Face Optimum (with KV cache) | ## License This model is licensed under the [MIT License](https://opensource.org/licenses/MIT). Original model by [OpenAI](https://openai.com/).