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

Method sample

benchmarks/benchmark_dataset.py:775–820  ·  view source on GitHub ↗
(
        self,
        num_requests: int,
        lora_path: Optional[str] = None,
        max_loras: Optional[int] = None,
        random_input_len: Optional[int] = None,
        random_output_len: Optional[int] = None,
        random_range_ratio: Optional[float] = None,
        enable_multimodal_chat: bool = False,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

773 super().__init__(**kwargs)
774
775 def sample(
776 self,
777 num_requests: int,
778 lora_path: Optional[str] = None,
779 max_loras: Optional[int] = None,
780 random_input_len: Optional[int] = None,
781 random_output_len: Optional[int] = None,
782 random_range_ratio: Optional[float] = None,
783 enable_multimodal_chat: bool = False,
784 **kwargs,
785 ) -> list:
786 samples = []
787
788 def sample_len(base_len: int, ratio: float) -> int:
789 if base_len is None:
790 return None
791 if ratio is None or ratio <= 0:
792 return base_len
793 lo = max(1, int(base_len * (1 - ratio)))
794 hi = int(base_len * (1 + ratio))
795 return random.randint(lo, hi)
796
797 for i in range(1, num_requests + 1):
798 # [length * (1 - range_ratio), length * (1 + range_ratio)]
799 sampled_input_len = sample_len(random_input_len, random_range_ratio)
800 sampled_output_len = sample_len(random_output_len, random_range_ratio)
801
802 words = [random.choice(self.COMMON_WORDS) for _ in range(sampled_input_len)]
803 prompt_text = " ".join(words)
804
805 data = {
806 "messages": [{"role": "user", "content": prompt_text}],
807 }
808
809 samples.append(
810 SampleRequest(
811 no=i,
812 json_data=data,
813 prompt=prompt_text,
814 prompt_len=sampled_input_len,
815 history_QA=data["messages"],
816 expected_output_len=sampled_output_len,
817 random_flag=True,
818 )
819 )
820 return samples

Callers

nothing calls this directly

Calls 2

joinMethod · 0.80
SampleRequestClass · 0.70

Tested by

no test coverage detected