Text Generation
Transformers
PyTorch
Safetensors
English
lightning
conversational
generative
custom_code
Instructions to use Aobangaming/lightning-30m-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Aobangaming/lightning-30m-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Aobangaming/lightning-30m-ft", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Aobangaming/lightning-30m-ft", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Aobangaming/lightning-30m-ft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Aobangaming/lightning-30m-ft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Aobangaming/lightning-30m-ft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Aobangaming/lightning-30m-ft
- SGLang
How to use Aobangaming/lightning-30m-ft 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 "Aobangaming/lightning-30m-ft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Aobangaming/lightning-30m-ft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Aobangaming/lightning-30m-ft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Aobangaming/lightning-30m-ft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Aobangaming/lightning-30m-ft with Docker Model Runner:
docker model run hf.co/Aobangaming/lightning-30m-ft
Upload folder using huggingface_hub
Browse files- config.json +18 -0
- configuration_lightning.py +27 -0
- modeling_lightning.py +61 -0
- pytorch_model.bin +3 -0
config.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"LightningForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"d_model": 256,
|
| 6 |
+
"dropout": 0.1,
|
| 7 |
+
"dtype": "float32",
|
| 8 |
+
"max_seq_len": 160,
|
| 9 |
+
"model_type": "lightning",
|
| 10 |
+
"nhead": 4,
|
| 11 |
+
"num_layers": 4,
|
| 12 |
+
"transformers_version": "4.57.3",
|
| 13 |
+
"vocab_size": 50000,
|
| 14 |
+
"auto_map": {
|
| 15 |
+
"AutoConfig": "configuration_lightning.LightningConfig",
|
| 16 |
+
"AutoModelForCausalLM": "modeling_lightning.LightningForCausalLM"
|
| 17 |
+
}
|
| 18 |
+
}
|
configuration_lightning.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class LightningConfig(PretrainedConfig):
|
| 5 |
+
model_type = "lightning"
|
| 6 |
+
|
| 7 |
+
def __init__(
|
| 8 |
+
self,
|
| 9 |
+
vocab_size=50000,
|
| 10 |
+
d_model=256,
|
| 11 |
+
nhead=4,
|
| 12 |
+
num_layers=4,
|
| 13 |
+
dropout=0.1,
|
| 14 |
+
max_seq_len=160,
|
| 15 |
+
**kwargs
|
| 16 |
+
):
|
| 17 |
+
super().__init__(
|
| 18 |
+
tie_word_embeddings=False,
|
| 19 |
+
**kwargs
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
self.vocab_size = vocab_size
|
| 23 |
+
self.d_model = d_model
|
| 24 |
+
self.nhead = nhead
|
| 25 |
+
self.num_layers = num_layers
|
| 26 |
+
self.dropout = dropout
|
| 27 |
+
self.max_seq_len = max_seq_len
|
modeling_lightning.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
|
| 4 |
+
from transformers import PreTrainedModel
|
| 5 |
+
from transformers.modeling_outputs import CausalLMOutput
|
| 6 |
+
|
| 7 |
+
from configuration_lightning import LightningConfig
|
| 8 |
+
from model import TransformerLanguageModel
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class LightningForCausalLM(PreTrainedModel):
|
| 12 |
+
|
| 13 |
+
config_class = LightningConfig
|
| 14 |
+
base_model_prefix = "lightning"
|
| 15 |
+
|
| 16 |
+
def __init__(self, config):
|
| 17 |
+
super().__init__(config)
|
| 18 |
+
|
| 19 |
+
self.lightning = TransformerLanguageModel(
|
| 20 |
+
vocab_size=config.vocab_size,
|
| 21 |
+
d_model=config.d_model,
|
| 22 |
+
nhead=config.nhead,
|
| 23 |
+
num_layers=config.num_layers,
|
| 24 |
+
dropout=config.dropout,
|
| 25 |
+
max_seq_len=config.max_seq_len
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
self.post_init()
|
| 29 |
+
|
| 30 |
+
def forward(self, input_ids=None, labels=None, **kwargs):
|
| 31 |
+
logits = self.lightning(input_ids)
|
| 32 |
+
|
| 33 |
+
loss = None
|
| 34 |
+
|
| 35 |
+
if labels is not None:
|
| 36 |
+
shift_logits = logits[..., :-1, :].contiguous()
|
| 37 |
+
shift_labels = labels[..., 1:].contiguous()
|
| 38 |
+
|
| 39 |
+
loss_fn = nn.CrossEntropyLoss()
|
| 40 |
+
|
| 41 |
+
loss = loss_fn(
|
| 42 |
+
shift_logits.view(-1, shift_logits.size(-1)),
|
| 43 |
+
shift_labels.view(-1)
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
return CausalLMOutput(
|
| 47 |
+
loss=loss,
|
| 48 |
+
logits=logits
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def get_input_embeddings(self):
|
| 52 |
+
return self.lightning.token_embedding
|
| 53 |
+
|
| 54 |
+
def set_input_embeddings(self, value):
|
| 55 |
+
self.lightning.token_embedding = value
|
| 56 |
+
|
| 57 |
+
def get_output_embeddings(self):
|
| 58 |
+
return self.lightning.output_layer
|
| 59 |
+
|
| 60 |
+
def set_output_embeddings(self, new_embeddings):
|
| 61 |
+
self.lightning.output_layer = new_embeddings
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2f13c912ae94bf1109ab3662c42fd4358a020dfa5e03bfc9f7d9571e9e925582
|
| 3 |
+
size 115219558
|