Views
No views yet
glm_asr_vllm/
├── model/ # Model configuration and implementation
│ ├── configuration_glmasr.py # GLM-ASR configuration
│ ├── modeling_glmasr.py # GLM-ASR model implementation
│ ├── modeling_audio.py # Audio encoding/decoding
│ └── processing_glmasr.py # Audio processing utilities
├── server/ # vLLM integration files
│ ├── glmasr_audio.py # Audio processing for vLLM
│ ├── glm_asr.py # GLM-ASR vLLM model wrapper
│ ├── registry.py # Model registry (vLLM)
│ └── server_ws.py # WebSocket server
├── wavs/ # Sample audio files
├── docker-compose.yaml # Docker Compose configuration
├── dockerfile # Docker image build configuration
├── hf_demo.py # HuggingFace Transformers demo
└── test_vllm_api.py # OpenAI API client test script1git clone <repository-url>
2cd glm_asr_vllmpip install torch transformers soundfile librosa openai./model/ directory:1# Download using huggingface-cli (recommended)
2huggingface-cli download bupalinyu/glm-asr-eligant --local-dir ./model
3
4# Or use git lfs
5git lfs install
6git clone https://huggingface.co/bupalinyu/glm-asr-eligant ./modelbupalinyu/glm-asr-eligant. After downloading, ensure all model files are in the ./model/ directory.docker build -t vllm-glmasr:latest .docker-compose up -d1import torch
2from transformers import AutoModelForCausalLM, AutoProcessor
3
4# Load model
5model = AutoModelForCausalLM.from_pretrained(
6 "./model/",
7 trust_remote_code=True,
8 torch_dtype=torch.bfloat16
9).to("cuda")
10
11processor = AutoProcessor.from_pretrained("./model/", trust_remote_code=True)
12
13# Define conversations
14conversations = [
15 [
16 {
17 "role": "user",
18 "content": [
19 {"type": "audio", "path": "./wavs/dufu.wav"},
20 {"type": "text", "text": "Please transcribe this audio."},
21 ],
22 }
23 ],
24]
25
26# Process and generate
27inputs = processor.apply_chat_template(
28 conversations,
29 return_tensors="pt",
30 sampling_rate=16000,
31 audio_padding="longest",
32).to("cuda")
33
34with torch.no_grad():
35 outputs = model.generate(**inputs, max_new_tokens=100, do_sample=False)
36
37print(processor.decode(outputs[0][len(inputs["input_ids"][0]):], skip_special_tokens=True))python hf_demo.pydocker-compose up -d1docker run -d \
2 --name vllm-glmasr \
3 --gpus all \
4 --ipc host \
5 --shm-size 8gb \
6 -p 8300:8300 \
7 -e CUDA_VISIBLE_DEVICES=2 \
8 vllm-glmasr:latesthttp://localhost:83001import base64
2import io
3import soundfile as sf
4import librosa
5import numpy as np
6from openai import OpenAI
7
8# Configure client
9client = OpenAI(
10 api_key="EMPTY",
11 base_url="http://localhost:8300/v1"
12)
13
14# Load and prepare audio
15def load_wav_16k(path: str):
16 audio, sr = sf.read(path)
17 if audio.ndim > 1:
18 audio = audio.mean(axis=1)
19 audio = audio.astype(np.float32)
20 if sr != 16000:
21 audio = librosa.resample(audio, orig_sr=sr, target_sr=16000).astype(np.float32)
22 return audio, sr
23
24# Convert to base64
25def wav_to_base64(wav: np.ndarray, sr: int) -> str:
26 buf = io.BytesIO()
27 sf.write(buf, wav, sr, format="WAV", subtype="PCM_16")
28 return base64.b64encode(buf.getvalue()).decode("utf-8")
29
30# Transcribe
31pcm, sr = load_wav_16k("path/to/audio.wav")
32audio_b64 = wav_to_base64(pcm, sr)
33
34resp = client.chat.completions.create(
35 model="glm-asr-eligant",
36 max_completion_tokens=256,
37 temperature=0.0,
38 messages=[
39 {
40 "role": "user",
41 "content": [
42 {"type": "text", "text": "Please transcribe this audio.<|audio|>"},
43 {
44 "type": "input_audio",
45 "input_audio": {
46 "data": audio_b64,
47 "format": "wav",
48 },
49 },
50 ],
51 }
52 ],
53)
54
55print(resp.choices[0].message.content)python test_vllm_api.pyCUDA_VISIBLE_DEVICES environment variableports mapping (default: 8300:8300)gpu-memory-utilization parameter (default: 0.1)max-model-len parameter (default: 4096)--host: Server host address (default: 0.0.0.0)--port: Server port (default: 8300)--served-model-name: Model name for API calls (default: glm-asr-eligant)--dtype: Data type (default: auto)--tensor-parallel-size: Tensor parallelism size (default: 1)--max-model-len: Maximum model sequence length (default: 4096)--trust-remote-code: Allow remote code execution--gpu-memory-utilization: GPU memory utilization 0-1 (default: 0.1)--api-key: API key for authentication (default: EMPTY)max_model_len parameterPOST /v1/chat/completions1{
2 "model": "glm-asr-eligant",
3 "max_completion_tokens": 256,
4 "temperature": 0.0,
5 "messages": [
6 {
7 "role": "user",
8 "content": [
9 {
10 "type": "text",
11 "text": "Please transcribe this audio.<|audio|>"
12 },
13 {
14 "type": "input_audio",
15 "input_audio": {
16 "data": "<base64_encoded_audio>",
17 "format": "wav"
18 }
19 }
20 ]
21 }
22 ]
23}GlmasrForConditionalGeneration in vLLM's model registry--tensor-parallel-sizeCUDA_VISIBLE_DEVICESnvidia-smidocker ps./model/)trust_remote_code is enabled