{"id":26902835,"url":"https://github.com/windingmotor/lighttxt-predict","last_synced_at":"2025-08-13T22:15:34.938Z","repository":{"id":285457556,"uuid":"958205374","full_name":"WindingMotor/LightTxt-Predict","owner":"WindingMotor","description":"🚀 Ultra-lightweight LLM-based predictive text API achieving ~17.4ms (RTX3080) prediction time with minimal resources. Leverages Qwen2-0.5B with advanced optimizations for intelligent text suggestions.","archived":false,"fork":false,"pushed_at":"2025-03-31T20:43:25.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T21:27:34.265Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WindingMotor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-31T20:17:16.000Z","updated_at":"2025-03-31T20:43:28.000Z","dependencies_parsed_at":"2025-03-31T21:27:35.818Z","dependency_job_id":"c900360e-d23a-4fb4-873f-819413ef41fc","html_url":"https://github.com/WindingMotor/LightTxt-Predict","commit_stats":null,"previous_names":["windingmotor/lighttxt-predict"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindingMotor%2FLightTxt-Predict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindingMotor%2FLightTxt-Predict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindingMotor%2FLightTxt-Predict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WindingMotor%2FLightTxt-Predict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WindingMotor","download_url":"https://codeload.github.com/WindingMotor/LightTxt-Predict/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246620271,"owners_count":20806722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-01T09:53:53.577Z","updated_at":"2025-04-01T09:53:53.986Z","avatar_url":"https://github.com/WindingMotor.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LightTxt-Predict: Ultra-Fast LLM Predictive Text API\n\n## 🚀 Performance Highlights\n- *With RTX3080*\n- **Ultra-low latency**: 17.4ms average prediction time\n- **Fast initialization**: Model loads in under 1 second\n- **Efficient memory usage**: ~940MB model storage footprint\n- **Responsive API**: Non-blocking architecture with background processing\n\n## 📊 Benchmarks\n\n| Metric | LightTxt-Predict Qwen2 | Standard Qwen2-0.5B | GPT-3.5 Turbo |\n|--------|-------------|---------------------|---------------|\n| Avg. Latency | 17.4ms | ~20ms | 50-100ms |\n| Model Size | 942.3 MB | 1.17 GB | N/A (Cloud) |\n| Initialization | 0.69s | 1-2s | N/A (Cloud) |\n| Tokens/sec | ~57.5 | 49.94 | ~67.83 |\n\n## ✨ Key Features\n\n- **GPU-optimized inference** with Flash Attention 2.0 support on supported devices with \u003eAmpere\n- **Multi-level caching system** for repeated queries\n- **Precomputed common phrases** for frequently used inputs (needs to be expanded upon)\n- **Asynchronous processing** with background threading\n- **RESTful API** with both GET and POST endpoints\n- **Batch prediction support** for improved throughput\n- **Automatic hardware adaptation** (CPU/GPU with optimal settings) (limited testing so far)\n- **Comprehensive statistics** and basic health monitoring\n\n## 🔧 Installation\n\n```bash\ngit clone https://github.com/WindingMotor/LightTxt-Predict\ncd LightTxt-Predict\npip install -r requirements.txt\n\n# Optional: Install Flash Attention for maximum performance\npip install flash-attn --no-build-isolation\n```\n\n## 📋 Requirements\n\n- Python 3.8+\n- NVIDIA CUDA-compatible GPU recommended (but works on CPU)\n- 2GB RAM minimum (4GB+ recommended)\n\n## 🚦 Quick Start\n\n### Start the server\n\n```bash\npython server.py --host 0.0.0.0 --port 8000\n```\n\n### Query for predictions\n\n```python\nimport requests\n\n# Simple GET request\nresponse = requests.get(\"http://localhost:8000/predict?text=I would like to\")\npredictions = response.json()\n\n# Output predictions\nfor pred in predictions[\"predictions\"]:\n    print(f\"{pred['word']} ({pred['probability']:.0%})\")\n```\n\n### Sample output\n\n```\nknow (43%)\ncreate (31%)\nuse (26%)\n```\n\n## 🔄 API Endpoints\n\n| Endpoint | Method | Description |\n|----------|--------|-------------|\n| `/predict` | GET | Get predictions for a single text input |\n| `/predict` | POST | Get predictions for single or batch inputs |\n| `/health` | GET | Check server health and model status |\n| `/stats` | GET | Get performance statistics |\n\n### GET /predict\n\n```\nhttp://localhost:8000/predict?text=Hello world\u0026top_k=3\n```\n\n### POST /predict\n\n```json\n{\n  \"text\": \"Once upon a\",\n  \"top_k\": 3\n}\n```\n\n### Batch prediction (POST)\n\n```json\n{\n  \"text\": [\"Hello world\", \"Once upon a\", \"The weather is\"],\n  \"top_k\": 3\n}\n```\n\n## 📈 Advanced Configuration\n\nThe server accepts several command-line options:\n\n```bash\npython server.py --help\n```\n\nOptions:\n- `--host`: Host address (default: localhost)\n- `--port`: Port number (default: 8000)\n- `--disable-optimizations`: Disable model optimizations for higher quality (but slower) predictions\n\n## 🧠 Technical Details\n\nLightPredict uses several optimization techniques:\n\n1. **Flash Attention 2.0** when available for efficient transformer computation\n2. **Multi-level caching** to avoid redundant computation\n3. **Automatic precision adaptation** (FP16 on CUDA, FP32 on CPU)\n4. **Optimized tokenization** with left-side padding\n5. **Selective quantization** for CPU deployment\n6. **Context-aware processing** that only looks at relevant text\n7. **Warm-up phase** to avoid cold-start latency\n8. **Auto device mapping** for optimal GPU memory utilization\n\n## 🤝 Comparison with Other Solutions\n\nLightPredict offers a balance of speed and quality that outperforms many alternatives:\n\n- **vs. API-based services** (OpenAI, Claude): Lower latency, no API costs, local deployment\n- **vs. Local LLMs**: 2-5x faster than similar-sized models with standard configuration\n- **vs. Traditional Predictive Text**: Higher quality predictions with semantic understanding vs n-based approaches\n\n## 📚 Example Use Cases\n\n- Intelligent text editors\n- Code completion tools\n- Mobile keyboard suggestions\n- Form auto-completion\n- Chat applications\n- CLI tools with autocomplete\n\n## 📄 License\n\nMIT License\n\n## 🙏 Acknowledgements\n\nThis project uses the excellent [Qwen2-0.5B](https://huggingface.co/Qwen/Qwen2-0.5B) model developed by Alibaba Cloud.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindingmotor%2Flighttxt-predict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwindingmotor%2Flighttxt-predict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwindingmotor%2Flighttxt-predict/lists"}