Text Generation
Transformers
Safetensors
lafa
feature-extraction
qwen2
flow-matching
speculative-decoding
custom_code
conversational
Instructions to use lafa-hf/lafa-7B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lafa-hf/lafa-7B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lafa-hf/lafa-7B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("lafa-hf/lafa-7B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lafa-hf/lafa-7B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lafa-hf/lafa-7B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lafa-hf/lafa-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lafa-hf/lafa-7B
- SGLang
How to use lafa-hf/lafa-7B 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 "lafa-hf/lafa-7B" \ --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": "lafa-hf/lafa-7B", "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 "lafa-hf/lafa-7B" \ --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": "lafa-hf/lafa-7B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use lafa-hf/lafa-7B with Docker Model Runner:
docker model run hf.co/lafa-hf/lafa-7B
Download base_wrapper.py from lafa-hf/lafa-7B: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/lafa-hf/lafa-7B/resolve/main/base_wrapper.py
- Command line
-
hf download hf://lafa-hf/lafa-7B/base_wrapper.py
-
curl -L -o base_wrapper.py https://huggingface.co/lafa-hf/lafa-7B/resolve/main/base_wrapper.py
1.94 kB
| """ | |
| Base wrapper for HF Trainer compatibility. | |
| Inherits PreTrainedModel so Trainer gets save_pretrained, from_pretrained, | |
| tied weight handling, gradient checkpointing — all for free. | |
| Subclasses store the backbone as `self.backbone` and must implement | |
| forward() and generate(). | |
| """ | |
| from abc import abstractmethod | |
| from transformers import PreTrainedModel | |
| class BaseModelWrapper(PreTrainedModel): | |
| """Abstract base that wraps a CausalLM backbone for HF Trainer. | |
| Uses the backbone's config. The default state_dict strips the backbone | |
| prefix for AR checkpoints; FlowModelWrapper overrides it to retain flow | |
| layers in its checkpoints. | |
| Subclasses must implement forward() and generate(). | |
| """ | |
| base_model_prefix = "backbone" | |
| supports_gradient_checkpointing = True | |
| def __init__(self, backbone: PreTrainedModel): | |
| import copy | |
| config = copy.deepcopy(backbone.config) | |
| config._attn_implementation_internal = "eager" | |
| super().__init__(config) | |
| self.backbone = backbone | |
| if backbone._tied_weights_keys is not None: | |
| self._tied_weights_keys = backbone._tied_weights_keys | |
| def _init_weights(self, module): | |
| pass | |
| def forward(self, **kwargs): ... | |
| def generate(self, **kwargs): ... | |
| def state_dict(self, *args, **kwargs): | |
| """Strip 'backbone.' prefix so checkpoints are loadable by AutoModel.""" | |
| sd = super().state_dict(*args, **kwargs) | |
| return {k.removeprefix("backbone."): v for k, v in sd.items()} | |
| def load_state_dict(self, state_dict, *args, **kwargs): | |
| """Load into backbone directly (handles keys with or without prefix).""" | |
| if any(k.startswith("backbone.") for k in state_dict): | |
| state_dict = {k.removeprefix("backbone."): v for k, v in state_dict.items()} | |
| return self.backbone.load_state_dict(state_dict, *args, **kwargs) | |