Downloads · 30 days
10
8% of all-time downloads
Madhur-Prakash-Mangal/distilgpt2-TFLITE
distilgpt2-TFLITE is a machine learning model from Madhur-Prakash-Mangal. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This repository provides a TensorFlow Lite (TFLite) version of the DistilGPT2 language model for on-device inference. It enables running DistilGPT2 on mobile and embedded devices with reduced size and latency while pr…
Downloads · 30 days
10
8% of all-time downloads
All-time downloads
121
Public
Repo size
164 MB
Likes
0
Public
Click a slice to open those files.
.tflite164 MB · 100%
From the Hugging Face model README
This repository provides a TensorFlow Lite (TFLite) version of the DistilGPT2 language model for on-device inference. It enables running DistilGPT2 on mobile and embedded devices with reduced size and latency while preserving output quality.
DistilGPT2 is a distilled version of GPT-2 offering a smaller footprint and faster inference. This TFLite conversion reduces memory usage and enables offline NLP applications such as text generation, completion, and chatbots directly on edge devices.
distilgpt2This model can be used in scenarios where cloud-based inference is not possible or desirable, such as:
| Metric | DistilGPT2 (HF PyTorch) | DistilGPT2 (TFLite FP32) | DistilGPT2 (TFLite INT8) |
|---|---|---|---|
| Model Size | ~320 MB | ~240 MB | ~120 MB |
| Avg. Latency (per token, CPU) | ~120 ms | ~80 ms | ~55 ms |
| Memory Footprint (RAM) | ~700 MB | ~450 MB | ~280 MB |
| Accuracy (compared to FP32) | 100% | ~99% | ~96–97% |
| Best Use Case | Research / Training | Mobile apps, prototyping | Resource-constrained IoT |
(Benchmarks tested on Snapdragon 870 and Intel i5 CPU; numbers may vary depending on device.)
Make sure you have TensorFlow Lite runtime installed:
pip install tflite-runtime tensorFlow
import numpy as np
import tensorflow as tf
# Load TFLite model
interpreter = tf.lite.Interpreter(model_path="distilgpt2.tflite")
interpreter.allocate_tensors()
# Get input and output details
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Example input (token IDs from tokenizer)
# NOTE: Use Hugging Face's GPT2 tokenizer to prepare inputs
from transformers import GPT2Tokenizer
tokenizer = GPT2Tokenizer.from_pretrained("distilgpt2")
input_ids = tokenizer.encode("The future of AI is", return_tensors="np")
# Prepare input tensor
interpreter.set_tensor(input_details[0]['index'], input_ids.astype(np.int32))
# Run inference
interpreter.invoke()
# Extract output
output = interpreter.get_tensor(output_details[0]['index'])
decoded_text = tokenizer.decode(output[0])
print(decoded_text)
import 'package:tflite_flutter/tflite_flutter.dart';
final interpreter = await Interpreter.fromAsset('distilgpt2.tflite');
// Prepare input tensor and run inference
// (tokenization/decoding handled separately)
// Generate answer based on query
Found an issue or want to improve the model? Feel free to:
This model follows the same license terms as the original distilgpt2 model.
Made with ❤️ for the mobile AI community
Enabling powerful text understanding directly on your device