Views
No views yet
| Quantization | Standard PPL | DynamicGate PPL | Δ PPL | Std Size | DG Size | Δ Size | Std Speed | DG Speed |
|---|---|---|---|---|---|---|---|---|
| IQ2_XXS | 11.30 | 9.84 | -12.9% | 2.5G | 2.6G | +0.1G | 234s | 246s |
| IQ2_XS | 11.72 | 11.63 | -0.8% | 2.7G | 2.8G | +0.1G | 242s | 246s |
| IQ2_S | 14.31 | 9.02 | -36.9% | 2.7G | 2.9G | +0.2G | 238s | 244s |
| IQ1_M | 27.46 | 15.41 | -43.9% | 2.2G | 2.5G | +0.3G | 206s | 212s |
| IQ1_S | 53.07 | 32.00 | -39.7% | 2.1G | 2.4G | +0.3G | 184s | 209s |
| Model Format | Precision | Memory Usage | Device Requirements | Best Use Case |
|---|---|---|---|---|
| BF16 | Highest | High | BF16-supported GPU/CPUs | High-speed inference with reduced memory |
| F16 | High | High | FP16-supported devices | GPU inference when BF16 isn't available |
| Q4_K | Medium Low | Low | CPU or Low-VRAM devices | Best for memory-constrained environments |
| Q6_K | Medium | Moderate | CPU with more memory | Better accuracy while still being quantized |
| Q8_0 | High | Moderate | CPU or GPU with enough VRAM | Best accuracy among quantized models |
| IQ3_XS | Very Low | Very Low | Ultra-low-memory devices | Extreme memory efficiency and low accuracy |
| Q4_0 | Low | Low | ARM or low-memory devices | llama.cpp can optimize for ARM devices |
LiveCC-7B-Instruct-bf16.ggufLiveCC-7B-Instruct-f16.ggufLiveCC-7B-Instruct-bf16-q8_0.ggufLiveCC-7B-Instruct-f16-q8_0.ggufLiveCC-7B-Instruct-q4_k.ggufLiveCC-7B-Instruct-q4_k_s.ggufLiveCC-7B-Instruct-q6_k.ggufLiveCC-7B-Instruct-q8_0.ggufLiveCC-7B-Instruct-iq3_xs.ggufLiveCC-7B-Instruct-iq3_m.ggufLiveCC-7B-Instruct-q4_0.ggufTurboLLM (GPT-4-mini)FreeLLM (Open-source)TestLLM (Experimental CPU-only)"Give me info on my websites SSL certificate""Check if my server is using quantum safe encyption for communication""Run a quick Nmap vulnerability test"[!Important] This is the SFT model. The base model is at LiveCC-7B-Base.


pip install qwen-vl-utils livecc-utils liger_kerneltransformers and the above utils:1import functools, torch, os, tqdm
2from liger_kernel.transformers import apply_liger_kernel_to_qwen2_vl
3apply_liger_kernel_to_qwen2_vl() # important. our model is trained with this. keep consistency
4from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, LogitsProcessor, logging
5from livecc_utils import prepare_multiturn_multimodal_inputs_for_generation, get_smart_resized_clip, get_smart_resized_video_reader
6from qwen_vl_utils import process_vision_info
7
8class LiveCCDemoInfer:
9 fps = 2
10 initial_fps_frames = 6
11 streaming_fps_frames = 2
12 initial_time_interval = initial_fps_frames / fps
13 streaming_time_interval = streaming_fps_frames / fps
14 frame_time_interval = 1 / fps
15 def __init__(self, model_path: str = None, device_id: int = 0):
16 self.model = Qwen2VLForConditionalGeneration.from_pretrained(
17 model_path, torch_dtype="auto",
18 device_map=f'cuda:{device_id}',
19 attn_implementation='flash_attention_2'
20 )
21 self.processor = AutoProcessor.from_pretrained(model_path, use_fast=False)
22 self.model.prepare_inputs_for_generation = functools.partial(prepare_multiturn_multimodal_inputs_for_generation, self.model)
23 message = {
24 "role": "user",
25 "content": [
26 {"type": "text", "text": 'livecc'},
27 ]
28 }
29 texts = self.processor.apply_chat_template([message], tokenize=False)
30 self.system_prompt_offset = texts.index('<|im_start|>user')
31 self._cached_video_readers_with_hw = {}
32
33
34 def live_cc(
35 self,
36 query: str,
37 state: dict,
38 max_pixels: int = 384 * 28 * 28,
39 default_query: str = 'Please describe the video.',
40 do_sample: bool = True,
41 repetition_penalty: float = 1.05,
42 **kwargs,
43 ):
44 """
45 state: dict, (maybe) with keys:
46 video_path: str, video path
47 video_timestamp: float, current video timestamp
48 last_timestamp: float, last processed video timestamp
49 last_video_pts_index: int, last processed video frame index
50 video_pts: np.ndarray, video pts
51 last_history: list, last processed history
52 past_key_values: llm past_key_values
53 past_ids: past generated ids
54 """
55 # 1. preparation: video_reader, and last processing info
56 video_timestamp, last_timestamp = state.get('video_timestamp', 0), state.get('last_timestamp', -1 / self.fps)
57 video_path = state['video_path']
58 if video_path not in self._cached_video_readers_with_hw:
59 self._cached_video_readers_with_hw[video_path] = get_smart_resized_video_reader(video_path, max_pixels)
60 video_reader = self._cached_video_readers_with_hw[video_path][0]
61 video_reader.get_frame_timestamp(0)
62 state['video_pts'] = torch.from_numpy(video_reader._frame_pts[:, 1])
63 state['last_video_pts_index'] = -1
64 video_pts = state['video_pts']
65 if last_timestamp + self.frame_time_interval > video_pts[-1]:
66 state['video_end'] = True
67 return
68 video_reader, resized_height, resized_width = self._cached_video_readers_with_hw[video_path]
69 last_video_pts_index = state['last_video_pts_index']
70
71 # 2. which frames will be processed
72 initialized = last_timestamp >= 0
73 if not initialized:
74 video_timestamp = max(video_timestamp, self.initial_time_interval)
75 if video_timestamp <= last_timestamp + self.frame_time_interval:
76 return
77 timestamps = torch.arange(last_timestamp + self.frame_time_interval, video_timestamp, self.frame_time_interval) # add compensation
78
79 # 3. fetch frames in required timestamps
80 clip, clip_timestamps, clip_idxs = get_smart_resized_clip(video_reader, resized_height, resized_width, timestamps, video_pts, video_pts_index_from=last_video_pts_index+1)
81 state['last_video_pts_index'] = clip_idxs[-1]
82 state['last_timestamp'] = clip_timestamps[-1]
83
84 # 4. organize to interleave frames
85 interleave_clips, interleave_timestamps = [], []
86 if not initialized:
87 interleave_clips.append(clip[:self.initial_fps_frames])
88 interleave_timestamps.append(clip_timestamps[:self.initial_fps_frames])
89 clip = clip[self.initial_fps_frames:]
90 clip_timestamps = clip_timestamps[self.initial_fps_frames:]
91 if len(clip) > 0:
92 interleave_clips.extend(list(clip.split(self.streaming_fps_frames)))
93 interleave_timestamps.extend(list(clip_timestamps.split(self.streaming_fps_frames)))
94
95 # 5. make conversation and send to model
96 for clip, timestamps in zip(interleave_clips, interleave_timestamps):
97 start_timestamp, stop_timestamp = timestamps[0].item(), timestamps[-1].item() + self.frame_time_interval
98 message = {
99 "role": "user",
100 "content": [
101 {"type": "text", "text": f'Time={start_timestamp:.1f}-{stop_timestamp:.1f}s'},
102 {"type": "video", "video": clip}
103 ]
104 }
105 if not query and not state.get('query', None):
106 query = default_query
107 print(f'No query provided, use default_query={default_query}')
108 if query and state.get('query', None) != query:
109 message['content'].append({"type": "text", "text": query})
110 state['query'] = query
111 texts = self.processor.apply_chat_template([message], tokenize=False, add_generation_prompt=True, return_tensors='pt')
112 past_ids = state.get('past_ids', None)
113 if past_ids is not None:
114 texts = '<|im_end|>\n' + texts[self.system_prompt_offset:]
115 inputs = self.processor(
116 text=texts,
117 images=None,
118 videos=[clip],
119 return_tensors="pt",
120 return_attention_mask=False
121 )
122 inputs.to('cuda')
123 if past_ids is not None:
124 inputs['input_ids'] = torch.cat([past_ids, inputs.input_ids], dim=1)
125 outputs = self.model.generate(
126 **inputs, past_key_values=state.get('past_key_values', None),
127 return_dict_in_generate=True, do_sample=do_sample,
128 repetition_penalty=repetition_penalty,
129 )
130 state['past_key_values'] = outputs.past_key_values
131 state['past_ids'] = outputs.sequences[:, :-1]
132 yield (start_timestamp, stop_timestamp), self.processor.decode(outputs.sequences[0, inputs.input_ids.size(1):], skip_special_tokens=True), state
133
134model_path = 'chenjoya/LiveCC-7B-Instruct'
135# download a test video at: https://github.com/showlab/livecc/blob/main/demo/sources/howto_fix_laptop_mute_1080p.mp4
136video_path = "demo/sources/howto_fix_laptop_mute_1080p.mp4"
137query = "Please describe the video."
138
139infer = LiveCCDemoInfer(model_path=model_path)
140state = {'video_path': video_path}
141commentaries = []
142t = 0
143for t in range(31):
144 state['video_timestamp'] = t
145 for (start_t, stop_t), response, state in infer.live_cc(
146 query=query, state=state,
147 max_pixels = 384 * 28 * 28, repetition_penalty=1.05,
148 streaming_eos_base_threshold=0.0, streaming_eos_threshold_step=0
149 ):
150 print(f'{start_t}s-{stop_t}s: {response}')
151 commentaries.append([start_t, stop_t, response])
152 if state.get('video_end', False):
153 break
154 t += 1transformers and the above utils:1import functools, torch
2from liger_kernel.transformers import apply_liger_kernel_to_qwen2_vl
3apply_liger_kernel_to_qwen2_vl() # important. our model is trained with this. keep consistency
4from transformers import Qwen2VLForConditionalGeneration, AutoProcessor, LogitsProcessor, logging
5from livecc_utils import prepare_multiturn_multimodal_inputs_for_generation, get_smart_resized_clip, get_smart_resized_video_reader
6from qwen_vl_utils import process_vision_info
7
8class LiveCCDemoInfer:
9 fps = 2
10 initial_fps_frames = 6
11 streaming_fps_frames = 2
12 initial_time_interval = initial_fps_frames / fps
13 streaming_time_interval = streaming_fps_frames / fps
14 frame_time_interval = 1 / fps
15
16 def __init__(self, model_path: str = None, device: str = 'cuda'):
17 self.model = Qwen2VLForConditionalGeneration.from_pretrained(
18 model_path, torch_dtype="auto",
19 device_map=device,
20 attn_implementation='flash_attention_2'
21 )
22 self.processor = AutoProcessor.from_pretrained(model_path, use_fast=False)
23 self.streaming_eos_token_id = self.processor.tokenizer(' ...').input_ids[-1]
24 self.model.prepare_inputs_for_generation = functools.partial(prepare_multiturn_multimodal_inputs_for_generation, self.model)
25 message = {
26 "role": "user",
27 "content": [
28 {"type": "text", "text": 'livecc'},
29 ]
30 }
31 texts = self.processor.apply_chat_template([message], tokenize=False)
32 self.system_prompt_offset = texts.index('<|im_start|>user')
33
34 def video_qa(
35 self,
36 message: str,
37 state: dict,
38 do_sample: bool = True,
39 repetition_penalty: float = 1.05,
40 **kwargs,
41 ):
42 """
43 state: dict, (maybe) with keys:
44 video_path: str, video path
45 video_timestamp: float, current video timestamp
46 last_timestamp: float, last processed video timestamp
47 last_video_pts_index: int, last processed video frame index
48 video_pts: np.ndarray, video pts
49 last_history: list, last processed history
50 past_key_values: llm past_key_values
51 past_ids: past generated ids
52 """
53 video_path = state.get('video_path', None)
54 conversation = []
55 past_ids = state.get('past_ids', None)
56 content = [{"type": "text", "text": message}]
57 if past_ids is None and video_path: # only use once
58 content.insert(0, {"type": "video", "video": video_path})
59 conversation.append({"role": "user", "content": content})
60 image_inputs, video_inputs = process_vision_info(conversation)
61 texts = self.processor.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True, return_tensors='pt')
62 if past_ids is not None:
63 texts = '<|im_end|>\n' + texts[self.system_prompt_offset:]
64 inputs = self.processor(
65 text=texts,
66 images=image_inputs,
67 videos=video_inputs,
68 return_tensors="pt",
69 return_attention_mask=False
70 )
71 inputs.to(self.model.device)
72 if past_ids is not None:
73 inputs['input_ids'] = torch.cat([past_ids, inputs.input_ids], dim=1)
74 outputs = self.model.generate(
75 **inputs, past_key_values=state.get('past_key_values', None),
76 return_dict_in_generate=True, do_sample=do_sample,
77 repetition_penalty=repetition_penalty,
78 max_new_tokens=512,
79 )
80 state['past_key_values'] = outputs.past_key_values
81 state['past_ids'] = outputs.sequences[:, :-1]
82 response = self.processor.decode(outputs.sequences[0, inputs.input_ids.size(1):], skip_special_tokens=True)
83 return response, state
84
85model_path = 'chenjoya/LiveCC-7B-Instruct'
86# download a test video at: https://github.com/showlab/livecc/blob/main/demo/sources/howto_fix_laptop_mute_1080p.mp4
87video_path = "demo/sources/howto_fix_laptop_mute_1080p.mp4"
88
89infer = LiveCCDemoInfer(model_path=model_path)
90state = {'video_path': video_path}
91# first round
92query1 = 'What is the video?'
93response1, state = infer.video_qa(message=query1, state=state)
94print(f'Q1: {query1}\nA1: {response1}')
95# second round
96query2 = 'How do you know that?'
97response2, state = infer.video_qa(message=query2, state=state)
98print(f'Q2: {query2}\nA2: {response2}')

@article{livecc,
author = {Joya Chen and Ziyun Zeng and Yiqi Lin and Wei Li and Zejun Ma and Mike Zheng Shou},
title = {LiveCC: Learning Video LLM with Streaming Speech Transcription at Scale},
journal = {arXiv preprint arXiv:2504.16030}
year = {2025},
}