Upload folder using huggingface_hub
Browse files- .gitattributes +1 -0
- README.md +429 -127
- media/projectnexus-arch.png +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
media/projectnexus-arch.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,127 +1,429 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
library_name: pytorch
|
| 4 |
-
tags:
|
| 5 |
-
- time-series-forecasting
|
| 6 |
-
- supply-chain
|
| 7 |
-
- demand-forecasting
|
| 8 |
-
- timellm
|
| 9 |
-
- llama
|
| 10 |
-
- aws-sagemaker
|
| 11 |
-
- time-series
|
| 12 |
-
base_model: meta-llama/Llama-3.2-3B
|
| 13 |
-
pipeline_tag: time-series-forecasting
|
| 14 |
-
datasets:
|
| 15 |
-
- supply-chain-data
|
| 16 |
-
language:
|
| 17 |
-
- en
|
| 18 |
-
metrics:
|
| 19 |
-
- mse
|
| 20 |
-
- mae
|
| 21 |
-
---
|
| 22 |
-
|
| 23 |
-
# TimeLLM Supply Chain Demand Forecasting Model
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
- **
|
| 41 |
-
- **
|
| 42 |
-
- **
|
| 43 |
-
- **
|
| 44 |
-
- **
|
| 45 |
-
- **
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
##
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
#
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: pytorch
|
| 4 |
+
tags:
|
| 5 |
+
- time-series-forecasting
|
| 6 |
+
- supply-chain
|
| 7 |
+
- demand-forecasting
|
| 8 |
+
- timellm
|
| 9 |
+
- llama
|
| 10 |
+
- aws-sagemaker
|
| 11 |
+
- time-series
|
| 12 |
+
base_model: meta-llama/Llama-3.2-3B
|
| 13 |
+
pipeline_tag: time-series-forecasting
|
| 14 |
+
datasets:
|
| 15 |
+
- supply-chain-data
|
| 16 |
+
language:
|
| 17 |
+
- en
|
| 18 |
+
metrics:
|
| 19 |
+
- mse
|
| 20 |
+
- mae
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# TimeLLM Supply Chain Demand Forecasting Model
|
| 24 |
+
|
| 25 |
+
<p align="center">
|
| 26 |
+
<img src="https://img.shields.io/badge/AWS-SageMaker-232F3E?logo=amazon-aws&logoColor=white" alt="AWS SageMaker"/>
|
| 27 |
+
<img src="https://img.shields.io/badge/HuggingFace-Llama--3.2--3B-orange?logo=huggingface" alt="HuggingFace Model"/>
|
| 28 |
+
<img src="https://img.shields.io/badge/python-3.10%2B-blue?logo=python" alt="Python"/>
|
| 29 |
+
<img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License"/>
|
| 30 |
+
</p>
|
| 31 |
+
|
| 32 |
+

|
| 33 |
+
|
| 34 |
+
This model is a fine-tuned [TimeLLM](https://github.com/KimMeen/Time-LLM) (Time Series Large Language Model) for supply chain demand forecasting, trained on AWS SageMaker. TimeLLM is a reprogramming framework that repurposes LLMs for general time series forecasting while keeping the backbone language models intact.
|
| 35 |
+
|
| 36 |
+
**๐ Built for the [GenAI Hackathon by Impetus & AWS](https://impetusawsgenaihackathon.devpost.com/) (TimeLLM Supply Chain Optimization category)**
|
| 37 |
+
|
| 38 |
+
## Model Details
|
| 39 |
+
|
| 40 |
+
- **Model Type**: Time Series Forecasting
|
| 41 |
+
- **Base Model**: Meta LLaMA 3.2-3B
|
| 42 |
+
- **Architecture**: TimeLLM with transformer encoder-decoder
|
| 43 |
+
- **Training Platform**: AWS SageMaker
|
| 44 |
+
- **Training Hardware**: `ml.g5.12xlarge` (4 NVIDIA A10G GPUs, 48 vCPUs, 192 GB RAM)
|
| 45 |
+
- **Inference Hardware**: `ml.g5.xlarge` (1 NVIDIA A10G GPU, 4 vCPUs, 16 GB RAM)
|
| 46 |
+
- **Training Duration**: 1114 seconds (~18.5 minutes)
|
| 47 |
+
- **Training Status**: Completed Successfully
|
| 48 |
+
- **Framework**: PyTorch 2.0.0
|
| 49 |
+
- **Model Size**: 2.2 GB
|
| 50 |
+
|
| 51 |
+
## Training Configuration
|
| 52 |
+
|
| 53 |
+
| Parameter | Value |
|
| 54 |
+
|-----------|-------|
|
| 55 |
+
| **Sequence Length** | 96 timesteps |
|
| 56 |
+
| **Prediction Length** | 96 timesteps |
|
| 57 |
+
| **Label Length** | 48 timesteps |
|
| 58 |
+
| **Features** | 14 supply chain features |
|
| 59 |
+
| **Model Dimensions** | d_model=16, d_ff=32, n_heads=8 |
|
| 60 |
+
| **Architecture** | e_layers=2, d_layers=1, factor=3 |
|
| 61 |
+
| **Patch Configuration** | patch_len=16, stride=8 |
|
| 62 |
+
| **Epochs** | 10 (with early stopping) |
|
| 63 |
+
| **Batch Size** | 32 |
|
| 64 |
+
| **Learning Rate** | 0.0001 |
|
| 65 |
+
| **Optimization** | DeepSpeed ZeRO Stage 2, Mixed Precision |
|
| 66 |
+
|
| 67 |
+
## Supply Chain Features
|
| 68 |
+
|
| 69 |
+
The model forecasts demand using 14 key supply chain features:
|
| 70 |
+
|
| 71 |
+
| Feature Category | Features |
|
| 72 |
+
|------------------|----------|
|
| 73 |
+
| **Sales Metrics** | Quantity, Line Total, Unit Price |
|
| 74 |
+
| **Promotions** | Discount Percentage, Promotion Indicators, Promo Discount |
|
| 75 |
+
| **Returns** | Return Quantity, Return Rate |
|
| 76 |
+
| **Inventory** | Stock Status (Stockout, Low Stock), Stock Coverage |
|
| 77 |
+
| **Temporal** | Day of Week, Month, Quarter |
|
| 78 |
+
|
| 79 |
+
## Use Cases
|
| 80 |
+
|
| 81 |
+
- **๐ฏ Demand Forecasting**: Predict future product demand patterns
|
| 82 |
+
- **๐ฆ Inventory Planning**: Optimize stock levels and procurement
|
| 83 |
+
- **๐ Sales Prediction**: Forecast sales across multiple time horizons
|
| 84 |
+
- **๐ Supply Chain Optimization**: Handle complex temporal dependencies
|
| 85 |
+
|
| 86 |
+
## Quick Start
|
| 87 |
+
|
| 88 |
+
### Prerequisites
|
| 89 |
+
|
| 90 |
+
**โ ๏ธ Important**: This model requires access to Meta LLaMA 3.2-3B, which is a gated model.
|
| 91 |
+
|
| 92 |
+
1. **Request Access**: Visit [meta-llama/Llama-3.2-3B](https://huggingface.co/meta-llama/Llama-3.2-3B) and request access
|
| 93 |
+
2. **Generate Token**: Create a HuggingFace token with "Read" permissions
|
| 94 |
+
3. **Set Environment**: `export HF_TOKEN="hf_your_token_here"`
|
| 95 |
+
|
| 96 |
+
### Installation
|
| 97 |
+
|
| 98 |
+
```bash
|
| 99 |
+
# Clone the repository
|
| 100 |
+
git clone https://github.com/youneslaaroussi/project-nexus
|
| 101 |
+
cd project-nexus/ml
|
| 102 |
+
|
| 103 |
+
# Create virtual environment
|
| 104 |
+
python -m venv .venv
|
| 105 |
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
| 106 |
+
|
| 107 |
+
# Install dependencies
|
| 108 |
+
pip install -r TimeLLM/requirements.txt
|
| 109 |
+
```
|
| 110 |
+
|
| 111 |
+
### Using the Model
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
from modeling_timellm import TimeLLMForecaster
|
| 115 |
+
import numpy as np
|
| 116 |
+
|
| 117 |
+
# Initialize the forecaster
|
| 118 |
+
forecaster = TimeLLMForecaster(
|
| 119 |
+
model_path="model.pth",
|
| 120 |
+
config_path="config.json"
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
# Prepare your data (96 timesteps, 14 features)
|
| 124 |
+
historical_data = np.random.randn(96, 14) # Replace with your actual data
|
| 125 |
+
time_features = np.random.randn(96, 3) # month, day, weekday
|
| 126 |
+
|
| 127 |
+
# Generate forecast
|
| 128 |
+
forecast = forecaster.forecast(historical_data, time_features)
|
| 129 |
+
print(f"Forecast shape: {forecast.shape}") # (96, 14)
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## Training from Scratch
|
| 133 |
+
|
| 134 |
+
### 1. Data Preparation
|
| 135 |
+
|
| 136 |
+
```bash
|
| 137 |
+
# Generate synthetic ERP data
|
| 138 |
+
cd data_schema
|
| 139 |
+
python generate_data.py
|
| 140 |
+
|
| 141 |
+
# Transform to time series format
|
| 142 |
+
cd ../data_preprocessing
|
| 143 |
+
python erp_to_timeseries.py
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
### 2. Configure AWS Environment
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
# Configure AWS credentials
|
| 150 |
+
aws configure
|
| 151 |
+
|
| 152 |
+
# Set environment variables
|
| 153 |
+
export AWS_ACCESS_KEY_ID=your_access_key
|
| 154 |
+
export AWS_SECRET_ACCESS_KEY=your_secret_key
|
| 155 |
+
export AWS_DEFAULT_REGION=us-east-1
|
| 156 |
+
export HF_TOKEN="hf_your_huggingface_token"
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
### 3. Launch Training on SageMaker
|
| 160 |
+
|
| 161 |
+
```bash
|
| 162 |
+
cd sagemaker_deployment
|
| 163 |
+
|
| 164 |
+
# Train the model (uses ml.g5.12xlarge)
|
| 165 |
+
python launch_sagemaker_training.py --model-name Demand_Forecasting
|
| 166 |
+
|
| 167 |
+
# Monitor training progress
|
| 168 |
+
aws sagemaker describe-training-job --training-job-name TimeLLM-training-Demand-Forecasting-YYYY-MM-DD-HH-MM-SS
|
| 169 |
+
```
|
| 170 |
+
|
| 171 |
+
### 4. Deploy for Inference
|
| 172 |
+
|
| 173 |
+
```bash
|
| 174 |
+
# Deploy endpoint (uses ml.g5.xlarge)
|
| 175 |
+
python deploy_endpoint.py
|
| 176 |
+
|
| 177 |
+
# Test the endpoint
|
| 178 |
+
python test_inference.py
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
## Docker Deployment
|
| 182 |
+
|
| 183 |
+
### Build Container
|
| 184 |
+
|
| 185 |
+
```bash
|
| 186 |
+
cd sagemaker_deployment
|
| 187 |
+
|
| 188 |
+
# Build the inference container
|
| 189 |
+
docker build -t timellm-inference:latest --build-arg HF_TOKEN=hf_your_token .
|
| 190 |
+
|
| 191 |
+
# Tag for ECR
|
| 192 |
+
docker tag timellm-inference:latest {account-id}.dkr.ecr.us-east-1.amazonaws.com/timellm-inference:latest
|
| 193 |
+
|
| 194 |
+
# Push to ECR
|
| 195 |
+
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin {account-id}.dkr.ecr.us-east-1.amazonaws.com
|
| 196 |
+
docker push {account-id}.dkr.ecr.us-east-1.amazonaws.com/timellm-inference:latest
|
| 197 |
+
```
|
| 198 |
+
|
| 199 |
+
### Dockerfile Structure
|
| 200 |
+
|
| 201 |
+
```dockerfile
|
| 202 |
+
FROM 763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:2.0.0-gpu-py310
|
| 203 |
+
|
| 204 |
+
# Install dependencies
|
| 205 |
+
COPY requirements.txt /tmp/requirements.txt
|
| 206 |
+
RUN pip install -r /tmp/requirements.txt
|
| 207 |
+
|
| 208 |
+
# Copy model artifacts
|
| 209 |
+
COPY model.tar.gz /opt/ml/model/
|
| 210 |
+
COPY llm_weights /opt/llm_weights
|
| 211 |
+
|
| 212 |
+
# Set up inference handler
|
| 213 |
+
COPY inference.py /opt/ml/model/code/
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
## Performance Optimization
|
| 217 |
+
|
| 218 |
+
### Hardware Specifications
|
| 219 |
+
|
| 220 |
+
| **Component** | **Training (ml.g5.12xlarge)** | **Inference (ml.g5.xlarge)** |
|
| 221 |
+
|---------------|--------------------------------|-------------------------------|
|
| 222 |
+
| **GPUs** | 4x NVIDIA A10G (24GB each) | 1x NVIDIA A10G (24GB) |
|
| 223 |
+
| **vCPUs** | 48 | 4 |
|
| 224 |
+
| **Memory** | 192 GB | 16 GB |
|
| 225 |
+
| **Network** | Up to 50 Gbps | Up to 10 Gbps |
|
| 226 |
+
| **Cost** | ~$7.09/hour | ~$0.526/hour |
|
| 227 |
+
|
| 228 |
+
### Optimization Techniques
|
| 229 |
+
|
| 230 |
+
- **๐ DeepSpeed ZeRO Stage 2**: Reduces memory usage by 50-70%
|
| 231 |
+
- **โก Mixed Precision (FP16)**: Faster training with maintained accuracy
|
| 232 |
+
- **๐ Gradient Accumulation**: Simulates larger batch sizes
|
| 233 |
+
- **๐ Distributed Training**: Multi-GPU acceleration with HuggingFace Accelerate
|
| 234 |
+
|
| 235 |
+
### Cost Analysis
|
| 236 |
+
|
| 237 |
+
| **Operation** | **Cost** | **Duration** |
|
| 238 |
+
|---------------|----------|--------------|
|
| 239 |
+
| **Training** | ~$2.13 | ~18.5 minutes |
|
| 240 |
+
| **Inference** | ~$0.526/hour | Continuous |
|
| 241 |
+
| **Storage (S3)** | ~$0.023/GB/month | Model artifacts |
|
| 242 |
+
|
| 243 |
+
## Data Format
|
| 244 |
+
|
| 245 |
+
### Input Format
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
{
|
| 249 |
+
"x_enc": [
|
| 250 |
+
[ # Timestep 1
|
| 251 |
+
100, # quantity
|
| 252 |
+
1000.0, # line_total
|
| 253 |
+
10.0, # unit_price
|
| 254 |
+
0.05, # discount_percent
|
| 255 |
+
0, # is_promotion
|
| 256 |
+
0.0, # promo_discount
|
| 257 |
+
2, # return_quantity
|
| 258 |
+
0.02, # return_rate
|
| 259 |
+
0, # is_stockout
|
| 260 |
+
0, # is_low_stock
|
| 261 |
+
30, # stock_coverage
|
| 262 |
+
0, # day_of_week
|
| 263 |
+
1, # month
|
| 264 |
+
1 # quarter
|
| 265 |
+
],
|
| 266 |
+
# ... 95 more timesteps
|
| 267 |
+
],
|
| 268 |
+
"x_mark_enc": [
|
| 269 |
+
[1, 1, 0], # month, day, weekday for timestep 1
|
| 270 |
+
# ... 95 more timesteps
|
| 271 |
+
]
|
| 272 |
+
}
|
| 273 |
+
```
|
| 274 |
+
|
| 275 |
+
### Output Format
|
| 276 |
+
|
| 277 |
+
```python
|
| 278 |
+
{
|
| 279 |
+
"predictions": [
|
| 280 |
+
[ # Predicted timestep 1
|
| 281 |
+
105, # forecasted quantity
|
| 282 |
+
1050.0, # forecasted line_total
|
| 283 |
+
# ... 12 more forecasted features
|
| 284 |
+
],
|
| 285 |
+
# ... 95 more predicted timesteps
|
| 286 |
+
]
|
| 287 |
+
}
|
| 288 |
+
```
|
| 289 |
+
|
| 290 |
+
## AWS SageMaker Integration
|
| 291 |
+
|
| 292 |
+
### Training Job Configuration
|
| 293 |
+
|
| 294 |
+
```python
|
| 295 |
+
from sagemaker.pytorch import PyTorch
|
| 296 |
+
|
| 297 |
+
estimator = PyTorch(
|
| 298 |
+
entry_point='train_supply_chain_complete.py',
|
| 299 |
+
source_dir='../TimeLLM',
|
| 300 |
+
role=sagemaker_role,
|
| 301 |
+
instance_type='ml.g5.12xlarge',
|
| 302 |
+
instance_count=1,
|
| 303 |
+
framework_version='2.0.0',
|
| 304 |
+
py_version='py310',
|
| 305 |
+
hyperparameters={
|
| 306 |
+
'model_name': 'Demand_Forecasting',
|
| 307 |
+
'root_path': '/opt/ml/input/data/training'
|
| 308 |
+
}
|
| 309 |
+
)
|
| 310 |
+
```
|
| 311 |
+
|
| 312 |
+
### Endpoint Configuration
|
| 313 |
+
|
| 314 |
+
```python
|
| 315 |
+
from sagemaker.pytorch import PyTorchModel
|
| 316 |
+
|
| 317 |
+
model = PyTorchModel(
|
| 318 |
+
model_data=model_artifacts_uri,
|
| 319 |
+
role=sagemaker_role,
|
| 320 |
+
entry_point='inference.py',
|
| 321 |
+
framework_version='2.0.0',
|
| 322 |
+
py_version='py310'
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
predictor = model.deploy(
|
| 326 |
+
initial_instance_count=1,
|
| 327 |
+
instance_type='ml.g5.xlarge',
|
| 328 |
+
endpoint_name='timellm-demand-forecast-endpoint'
|
| 329 |
+
)
|
| 330 |
+
```
|
| 331 |
+
|
| 332 |
+
## Monitoring and Logging
|
| 333 |
+
|
| 334 |
+
### CloudWatch Integration
|
| 335 |
+
|
| 336 |
+
- **Training Logs**: `/aws/sagemaker/TrainingJobs/{job-name}`
|
| 337 |
+
- **Endpoint Logs**: `/aws/sagemaker/Endpoints/{endpoint-name}`
|
| 338 |
+
- **Custom Metrics**: Model performance, latency, error rates
|
| 339 |
+
|
| 340 |
+
### Performance Metrics
|
| 341 |
+
|
| 342 |
+
| **Metric** | **Description** |
|
| 343 |
+
|------------|-----------------|
|
| 344 |
+
| **MAE** | Mean Absolute Error |
|
| 345 |
+
| **MSE** | Mean Squared Error |
|
| 346 |
+
| **MAPE** | Mean Absolute Percentage Error |
|
| 347 |
+
| **Latency** | Inference response time (~2-3 seconds) |
|
| 348 |
+
|
| 349 |
+
## TimeLLM Framework
|
| 350 |
+
|
| 351 |
+
This implementation is based on the TimeLLM framework, which introduces:
|
| 352 |
+
|
| 353 |
+
1. **๐ Reprogramming**: Converts time series into text prototype representations
|
| 354 |
+
2. **๐ฌ Prompt Augmentation**: Uses declarative prompts for domain knowledge
|
| 355 |
+
3. **๐ฆ LLM Backbone**: Leverages pre-trained language models for forecasting
|
| 356 |
+
|
| 357 |
+
### Key Modifications
|
| 358 |
+
|
| 359 |
+
- **Supply Chain Prompts**: Domain-specific prompts for demand forecasting
|
| 360 |
+
- **HuggingFace Integration**: Seamless model loading and tokenization
|
| 361 |
+
- **AWS Optimization**: SageMaker-specific inference handlers
|
| 362 |
+
- **Performance Tuning**: DeepSpeed and mixed precision support
|
| 363 |
+
|
| 364 |
+
## Model Variants
|
| 365 |
+
|
| 366 |
+
| **Model** | **Purpose** | **Use Case** |
|
| 367 |
+
|-----------|-------------|--------------|
|
| 368 |
+
| **Demand Forecasting** | Predict future product demand | Inventory planning, procurement |
|
| 369 |
+
| **Product Forecasting** | Product-specific metrics | Product lifecycle management |
|
| 370 |
+
| **Category Forecasting** | Electronics category sales | Category management, marketing |
|
| 371 |
+
| **KPI Forecasting** | Key performance indicators | Executive dashboards, strategic planning |
|
| 372 |
+
|
| 373 |
+
## Troubleshooting
|
| 374 |
+
|
| 375 |
+
### Common Issues
|
| 376 |
+
|
| 377 |
+
1. **HuggingFace Access Denied**
|
| 378 |
+
```bash
|
| 379 |
+
# Verify token access
|
| 380 |
+
python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('meta-llama/Llama-3.2-3B')"
|
| 381 |
+
```
|
| 382 |
+
|
| 383 |
+
2. **Training Job Fails**
|
| 384 |
+
```bash
|
| 385 |
+
# Check CloudWatch logs
|
| 386 |
+
aws logs describe-log-groups --log-group-name-prefix "/aws/sagemaker/TrainingJobs"
|
| 387 |
+
```
|
| 388 |
+
|
| 389 |
+
3. **Endpoint Timeout**
|
| 390 |
+
```bash
|
| 391 |
+
# Check endpoint status
|
| 392 |
+
aws sagemaker describe-endpoint --endpoint-name timellm-demand-forecast-endpoint
|
| 393 |
+
```
|
| 394 |
+
|
| 395 |
+
## Citations
|
| 396 |
+
|
| 397 |
+
### This Model
|
| 398 |
+
```bibtex
|
| 399 |
+
@misc{projectnexus-timellm-2025,
|
| 400 |
+
title={TimeLLM Supply Chain Demand Forecasting},
|
| 401 |
+
author={Younes Laaroussi},
|
| 402 |
+
year={2025},
|
| 403 |
+
howpublished={Hugging Face Model Hub},
|
| 404 |
+
url={https://huggingface.co/youneslaaroussi/projectnexus},
|
| 405 |
+
note={Trained on AWS SageMaker ml.g5.12xlarge using TimeLLM framework}
|
| 406 |
+
}
|
| 407 |
+
```
|
| 408 |
+
|
| 409 |
+
### TimeLLM Framework
|
| 410 |
+
```bibtex
|
| 411 |
+
@inproceedings{jin2023time,
|
| 412 |
+
title={{Time-LLM}: Time series forecasting by reprogramming large language models},
|
| 413 |
+
author={Jin, Ming and Wang, Shiyu and Ma, Lintao and Chu, Zhixuan and Zhang, James Y and Shi, Xiaoming and Chen, Pin-Yu and Liang, Yuxuan and Li, Yuan-Fang and Pan, Shirui and Wen, Qingsong},
|
| 414 |
+
booktitle={International Conference on Learning Representations (ICLR)},
|
| 415 |
+
year={2024}
|
| 416 |
+
}
|
| 417 |
+
```
|
| 418 |
+
|
| 419 |
+
## License
|
| 420 |
+
|
| 421 |
+
This model is released under the MIT License, consistent with the TimeLLM framework.
|
| 422 |
+
|
| 423 |
+
## Acknowledgments
|
| 424 |
+
|
| 425 |
+
- **[TimeLLM](https://github.com/KimMeen/Time-LLM)** for the foundational framework
|
| 426 |
+
- **[AWS SageMaker](https://aws.amazon.com/sagemaker/)** for the training infrastructure
|
| 427 |
+
- **[Meta LLaMA](https://huggingface.co/meta-llama/Llama-3.2-3B)** for the base model
|
| 428 |
+
- **[HuggingFace](https://huggingface.co/)** for model hosting and transformers library
|
| 429 |
+
- **[DeepSpeed](https://github.com/microsoft/DeepSpeed)** for optimization techniques
|
media/projectnexus-arch.png
ADDED
|
Git LFS Details
|