MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / EBChatDataset

Class EBChatDataset

fastdeploy/benchmarks/datasets.py:265–322  ·  view source on GitHub ↗

Implements the ShareGPT dataset. Loads data from a JSON file and generates sample requests based on conversation turns.

Source from the content-addressed store, hash-verified

263
264
265class EBChatDataset(BenchmarkDataset):
266 """
267 Implements the ShareGPT dataset. Loads data from a JSON file and generates
268 sample requests based on conversation turns.
269 """
270
271 prompt_len: int
272
273 def __init__(self, **kwargs) -> None:
274 super().__init__(**kwargs)
275 self.load_data()
276
277 def load_data(self) -> None:
278 if self.dataset_path is None:
279 raise ValueError("dataset_path must be provided for loading data.")
280
281 with open(self.dataset_path, encoding="utf-8") as f:
282 self.data = [json.loads(i.strip()) for i in f.readlines()]
283
284 if self.shuffle:
285 random.seed(self.random_seed)
286 random.shuffle(self.data)
287
288 def sample(
289 self,
290 num_requests: int,
291 lora_path: Optional[str] = None,
292 max_loras: Optional[int] = None,
293 output_len: Optional[int] = None,
294 enable_multimodal_chat: bool = False,
295 **kwargs,
296 ) -> list:
297 samples: list = []
298 cnt = 1
299 for entry in self.data:
300 if len(samples) >= num_requests:
301 break
302 json_data = entry
303 prompt = entry["messages"][-1].get("content", "")
304 history_QA = entry.get("messages", [])
305 new_output_len = int(entry.get("max_tokens", 12288))
306
307 if enable_multimodal_chat:
308 prompt = self.apply_multimodal_chat_transformation(prompt, None)
309 samples.append(
310 SampleRequest(
311 no=cnt,
312 json_data=json_data,
313 prompt=prompt,
314 prompt_len=0,
315 history_QA=history_QA,
316 expected_output_len=new_output_len,
317 )
318 )
319 cnt += 1
320
321 self.maybe_oversample_requests(samples, num_requests)
322 return samples

Callers 1

get_samplesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected