guidellm 0.3.1__py3-none-any.whl → 0.6.0a5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. guidellm/__init__.py +5 -2
  2. guidellm/__main__.py +524 -255
  3. guidellm/backends/__init__.py +33 -0
  4. guidellm/backends/backend.py +109 -0
  5. guidellm/backends/openai.py +340 -0
  6. guidellm/backends/response_handlers.py +428 -0
  7. guidellm/benchmark/__init__.py +69 -39
  8. guidellm/benchmark/benchmarker.py +160 -316
  9. guidellm/benchmark/entrypoints.py +560 -127
  10. guidellm/benchmark/outputs/__init__.py +24 -0
  11. guidellm/benchmark/outputs/console.py +633 -0
  12. guidellm/benchmark/outputs/csv.py +721 -0
  13. guidellm/benchmark/outputs/html.py +473 -0
  14. guidellm/benchmark/outputs/output.py +169 -0
  15. guidellm/benchmark/outputs/serialized.py +69 -0
  16. guidellm/benchmark/profiles.py +718 -0
  17. guidellm/benchmark/progress.py +553 -556
  18. guidellm/benchmark/scenarios/__init__.py +40 -0
  19. guidellm/benchmark/scenarios/chat.json +6 -0
  20. guidellm/benchmark/scenarios/rag.json +6 -0
  21. guidellm/benchmark/schemas/__init__.py +66 -0
  22. guidellm/benchmark/schemas/base.py +402 -0
  23. guidellm/benchmark/schemas/generative/__init__.py +55 -0
  24. guidellm/benchmark/schemas/generative/accumulator.py +841 -0
  25. guidellm/benchmark/schemas/generative/benchmark.py +163 -0
  26. guidellm/benchmark/schemas/generative/entrypoints.py +381 -0
  27. guidellm/benchmark/schemas/generative/metrics.py +927 -0
  28. guidellm/benchmark/schemas/generative/report.py +158 -0
  29. guidellm/data/__init__.py +34 -4
  30. guidellm/data/builders.py +541 -0
  31. guidellm/data/collators.py +16 -0
  32. guidellm/data/config.py +120 -0
  33. guidellm/data/deserializers/__init__.py +49 -0
  34. guidellm/data/deserializers/deserializer.py +141 -0
  35. guidellm/data/deserializers/file.py +223 -0
  36. guidellm/data/deserializers/huggingface.py +94 -0
  37. guidellm/data/deserializers/memory.py +194 -0
  38. guidellm/data/deserializers/synthetic.py +246 -0
  39. guidellm/data/entrypoints.py +52 -0
  40. guidellm/data/loaders.py +190 -0
  41. guidellm/data/preprocessors/__init__.py +27 -0
  42. guidellm/data/preprocessors/formatters.py +410 -0
  43. guidellm/data/preprocessors/mappers.py +196 -0
  44. guidellm/data/preprocessors/preprocessor.py +30 -0
  45. guidellm/data/processor.py +29 -0
  46. guidellm/data/schemas.py +175 -0
  47. guidellm/data/utils/__init__.py +6 -0
  48. guidellm/data/utils/dataset.py +94 -0
  49. guidellm/extras/__init__.py +4 -0
  50. guidellm/extras/audio.py +220 -0
  51. guidellm/extras/vision.py +242 -0
  52. guidellm/logger.py +2 -2
  53. guidellm/mock_server/__init__.py +8 -0
  54. guidellm/mock_server/config.py +84 -0
  55. guidellm/mock_server/handlers/__init__.py +17 -0
  56. guidellm/mock_server/handlers/chat_completions.py +280 -0
  57. guidellm/mock_server/handlers/completions.py +280 -0
  58. guidellm/mock_server/handlers/tokenizer.py +142 -0
  59. guidellm/mock_server/models.py +510 -0
  60. guidellm/mock_server/server.py +238 -0
  61. guidellm/mock_server/utils.py +302 -0
  62. guidellm/scheduler/__init__.py +69 -26
  63. guidellm/scheduler/constraints/__init__.py +49 -0
  64. guidellm/scheduler/constraints/constraint.py +325 -0
  65. guidellm/scheduler/constraints/error.py +411 -0
  66. guidellm/scheduler/constraints/factory.py +182 -0
  67. guidellm/scheduler/constraints/request.py +312 -0
  68. guidellm/scheduler/constraints/saturation.py +722 -0
  69. guidellm/scheduler/environments.py +252 -0
  70. guidellm/scheduler/scheduler.py +137 -368
  71. guidellm/scheduler/schemas.py +358 -0
  72. guidellm/scheduler/strategies.py +617 -0
  73. guidellm/scheduler/worker.py +413 -419
  74. guidellm/scheduler/worker_group.py +712 -0
  75. guidellm/schemas/__init__.py +65 -0
  76. guidellm/schemas/base.py +417 -0
  77. guidellm/schemas/info.py +188 -0
  78. guidellm/schemas/request.py +235 -0
  79. guidellm/schemas/request_stats.py +349 -0
  80. guidellm/schemas/response.py +124 -0
  81. guidellm/schemas/statistics.py +1018 -0
  82. guidellm/{config.py → settings.py} +31 -24
  83. guidellm/utils/__init__.py +71 -8
  84. guidellm/utils/auto_importer.py +98 -0
  85. guidellm/utils/cli.py +132 -5
  86. guidellm/utils/console.py +566 -0
  87. guidellm/utils/encoding.py +778 -0
  88. guidellm/utils/functions.py +159 -0
  89. guidellm/utils/hf_datasets.py +1 -2
  90. guidellm/utils/hf_transformers.py +4 -4
  91. guidellm/utils/imports.py +9 -0
  92. guidellm/utils/messaging.py +1118 -0
  93. guidellm/utils/mixins.py +115 -0
  94. guidellm/utils/random.py +3 -4
  95. guidellm/utils/registry.py +220 -0
  96. guidellm/utils/singleton.py +133 -0
  97. guidellm/utils/synchronous.py +159 -0
  98. guidellm/utils/text.py +163 -50
  99. guidellm/utils/typing.py +41 -0
  100. guidellm/version.py +2 -2
  101. guidellm-0.6.0a5.dist-info/METADATA +364 -0
  102. guidellm-0.6.0a5.dist-info/RECORD +109 -0
  103. guidellm/backend/__init__.py +0 -23
  104. guidellm/backend/backend.py +0 -259
  105. guidellm/backend/openai.py +0 -708
  106. guidellm/backend/response.py +0 -136
  107. guidellm/benchmark/aggregator.py +0 -760
  108. guidellm/benchmark/benchmark.py +0 -837
  109. guidellm/benchmark/output.py +0 -997
  110. guidellm/benchmark/profile.py +0 -409
  111. guidellm/benchmark/scenario.py +0 -104
  112. guidellm/data/prideandprejudice.txt.gz +0 -0
  113. guidellm/dataset/__init__.py +0 -22
  114. guidellm/dataset/creator.py +0 -213
  115. guidellm/dataset/entrypoints.py +0 -42
  116. guidellm/dataset/file.py +0 -92
  117. guidellm/dataset/hf_datasets.py +0 -62
  118. guidellm/dataset/in_memory.py +0 -132
  119. guidellm/dataset/synthetic.py +0 -287
  120. guidellm/objects/__init__.py +0 -18
  121. guidellm/objects/pydantic.py +0 -89
  122. guidellm/objects/statistics.py +0 -953
  123. guidellm/preprocess/__init__.py +0 -3
  124. guidellm/preprocess/dataset.py +0 -374
  125. guidellm/presentation/__init__.py +0 -28
  126. guidellm/presentation/builder.py +0 -27
  127. guidellm/presentation/data_models.py +0 -232
  128. guidellm/presentation/injector.py +0 -66
  129. guidellm/request/__init__.py +0 -18
  130. guidellm/request/loader.py +0 -284
  131. guidellm/request/request.py +0 -79
  132. guidellm/request/types.py +0 -10
  133. guidellm/scheduler/queues.py +0 -25
  134. guidellm/scheduler/result.py +0 -155
  135. guidellm/scheduler/strategy.py +0 -495
  136. guidellm-0.3.1.dist-info/METADATA +0 -329
  137. guidellm-0.3.1.dist-info/RECORD +0 -62
  138. {guidellm-0.3.1.dist-info → guidellm-0.6.0a5.dist-info}/WHEEL +0 -0
  139. {guidellm-0.3.1.dist-info → guidellm-0.6.0a5.dist-info}/entry_points.txt +0 -0
  140. {guidellm-0.3.1.dist-info → guidellm-0.6.0a5.dist-info}/licenses/LICENSE +0 -0
  141. {guidellm-0.3.1.dist-info → guidellm-0.6.0a5.dist-info}/top_level.txt +0 -0
@@ -1,287 +0,0 @@
1
- import json
2
- import random
3
- from collections.abc import Iterable, Iterator
4
- from itertools import cycle
5
- from pathlib import Path
6
- from typing import Any, Literal, Optional, Union
7
-
8
- import yaml
9
- from datasets import (
10
- Dataset,
11
- DatasetDict,
12
- IterableDataset,
13
- IterableDatasetDict,
14
- )
15
- from pydantic import BaseModel, Field
16
- from transformers import PreTrainedTokenizerBase # type: ignore[import]
17
-
18
- from guidellm.dataset.creator import ColumnInputTypes, DatasetCreator
19
- from guidellm.utils import EndlessTextCreator, IntegerRangeSampler, check_load_processor
20
-
21
- __all__ = [
22
- "SyntheticDatasetConfig",
23
- "SyntheticDatasetCreator",
24
- "SyntheticTextItemsGenerator",
25
- ]
26
-
27
-
28
- class SyntheticDatasetConfig(BaseModel):
29
- prefix_tokens: int = Field(
30
- description="The number of shared prefix tokens to prepend to each prompt.",
31
- ge=0,
32
- default=0,
33
- )
34
- prompt_tokens: int = Field(
35
- description="The average number of text tokens generated for prompts.",
36
- gt=0,
37
- )
38
- prompt_tokens_stdev: Optional[int] = Field(
39
- description="The standard deviation of the tokens generated for prompts.",
40
- gt=0,
41
- default=None,
42
- )
43
- prompt_tokens_min: Optional[int] = Field(
44
- description="The minimum number of text tokens generated for prompts.",
45
- gt=0,
46
- default=None,
47
- )
48
- prompt_tokens_max: Optional[int] = Field(
49
- description="The maximum number of text tokens generated for prompts.",
50
- gt=0,
51
- default=None,
52
- )
53
- output_tokens: int = Field(
54
- description="The average number of text tokens generated for outputs.",
55
- gt=0,
56
- )
57
- output_tokens_stdev: Optional[int] = Field(
58
- description="The standard deviation of the tokens generated for outputs.",
59
- gt=0,
60
- default=None,
61
- )
62
- output_tokens_min: Optional[int] = Field(
63
- description="The minimum number of text tokens generated for outputs.",
64
- gt=0,
65
- default=None,
66
- )
67
- output_tokens_max: Optional[int] = Field(
68
- description="The maximum number of text tokens generated for outputs.",
69
- gt=0,
70
- default=None,
71
- )
72
- samples: int = Field(
73
- description="The number of samples to generate for the dataset.",
74
- gt=0,
75
- default=1000,
76
- )
77
- source: str = Field(
78
- description="The source of the text data to be used for generation.",
79
- default="data:prideandprejudice.txt.gz",
80
- )
81
-
82
- @staticmethod
83
- def parse_str(data: Union[str, Path]) -> "SyntheticDatasetConfig":
84
- if (
85
- isinstance(data, Path)
86
- or data.strip().endswith(".config")
87
- or data.strip().endswith(".yaml")
88
- ):
89
- return SyntheticDatasetConfig.parse_config_file(data)
90
-
91
- if data.strip().startswith("{"):
92
- return SyntheticDatasetConfig.parse_json(data)
93
-
94
- if data.count("=") > 1:
95
- return SyntheticDatasetConfig.parse_key_value_pairs(data)
96
-
97
- raise ValueError(
98
- f"Unsupported data format. Expected JSON or key-value pairs, got {data}"
99
- )
100
-
101
- @staticmethod
102
- def parse_json(data: str) -> "SyntheticDatasetConfig":
103
- config_dict = json.loads(data.strip())
104
-
105
- return SyntheticDatasetConfig(**config_dict)
106
-
107
- @staticmethod
108
- def parse_key_value_pairs(data: str) -> "SyntheticDatasetConfig":
109
- config_dict = {}
110
- items = data.strip().split(",")
111
- for item in items:
112
- key, value = item.split("=")
113
- config_dict[key.strip()] = (
114
- int(value.strip()) if value.strip().isnumeric() else value.strip()
115
- )
116
-
117
- return SyntheticDatasetConfig(**config_dict) # type: ignore[arg-type]
118
-
119
- @staticmethod
120
- def parse_config_file(data: Union[str, Path]) -> "SyntheticDatasetConfig":
121
- with Path(data).open("r") as file:
122
- config_dict = yaml.safe_load(file)
123
-
124
- return SyntheticDatasetConfig(**config_dict)
125
-
126
-
127
- class SyntheticTextItemsGenerator(
128
- Iterable[
129
- dict[
130
- Literal["prompt", "prompt_tokens_count", "output_tokens_count"],
131
- Union[str, int],
132
- ]
133
- ]
134
- ):
135
- def __init__(
136
- self,
137
- config: SyntheticDatasetConfig,
138
- processor: PreTrainedTokenizerBase,
139
- random_seed: int,
140
- ):
141
- self.config = config
142
- self.processor = processor
143
- self.random_seed = random_seed
144
- self.text_creator = EndlessTextCreator(
145
- data=config.source,
146
- )
147
-
148
- def __iter__(
149
- self,
150
- ) -> Iterator[
151
- dict[
152
- Literal["prompt", "prompt_tokens_count", "output_tokens_count"],
153
- Union[str, int],
154
- ]
155
- ]:
156
- prompt_tokens_sampler = IntegerRangeSampler(
157
- average=self.config.prompt_tokens,
158
- variance=self.config.prompt_tokens_stdev,
159
- min_value=self.config.prompt_tokens_min,
160
- max_value=self.config.prompt_tokens_max,
161
- random_seed=self.random_seed,
162
- )
163
- output_tokens_sampler = IntegerRangeSampler(
164
- average=self.config.output_tokens,
165
- variance=self.config.output_tokens_stdev,
166
- min_value=self.config.output_tokens_min,
167
- max_value=self.config.output_tokens_max,
168
- random_seed=self.random_seed + 1, # ensure diff dist from prompts
169
- )
170
- # ensure diff distribution from output tokens
171
- rand = random.Random(self.random_seed + 2) # noqa: S311
172
- unique_prefix_iter = cycle(self.processor.get_vocab().values())
173
-
174
- prefix_index = rand.randint(0, len(self.text_creator.words))
175
- prefix_tokens = self._create_prompt(self.config.prefix_tokens, prefix_index)
176
-
177
- for _, prompt_tokens, output_tokens in zip(
178
- range(self.config.samples),
179
- prompt_tokens_sampler,
180
- output_tokens_sampler,
181
- ):
182
- start_index = rand.randint(0, len(self.text_creator.words))
183
- prompt_text = self.processor.decode(
184
- prefix_tokens
185
- + self._create_prompt(
186
- prompt_tokens, start_index, next(unique_prefix_iter)
187
- ),
188
- skip_special_tokens=True,
189
- )
190
- yield {
191
- "prompt": prompt_text,
192
- "prompt_tokens_count": self.config.prefix_tokens + prompt_tokens,
193
- "output_tokens_count": output_tokens,
194
- }
195
-
196
- def _create_prompt(
197
- self, prompt_tokens: int, start_index: int, unique_prefix: Optional[int] = None
198
- ) -> list[int]:
199
- if prompt_tokens <= 0:
200
- return []
201
-
202
- left = start_index
203
- right = start_index + 4 * prompt_tokens
204
- start_tokens = [unique_prefix] if unique_prefix else []
205
-
206
- while left < right:
207
- mid = (left + right) // 2
208
- test_prompt = self.text_creator.create_text(start_index, mid - start_index)
209
- test_tokens = start_tokens + self.processor.encode(test_prompt)
210
-
211
- if len(test_tokens) == prompt_tokens:
212
- return test_tokens
213
- elif len(test_tokens) < prompt_tokens:
214
- left = mid + 1
215
- else:
216
- right = mid
217
-
218
- final_text = self.text_creator.create_text(start_index, left - start_index)
219
- return start_tokens + self.processor.encode(final_text)
220
-
221
-
222
- class SyntheticDatasetCreator(DatasetCreator):
223
- @classmethod
224
- def is_supported(
225
- cls,
226
- data: Any,
227
- data_args: Optional[dict[str, Any]], # noqa: ARG003
228
- ) -> bool:
229
- if (
230
- isinstance(data, Path)
231
- and data.exists()
232
- and data.suffix in {".config", ".yaml"}
233
- ):
234
- return True
235
-
236
- if isinstance(data, str):
237
- data_str: str = data.strip()
238
- if (
239
- data_str.startswith("{")
240
- or data_str.count("=") > 1
241
- or data_str.endswith((".config", ".yaml"))
242
- ):
243
- return True
244
-
245
- return False
246
-
247
- @classmethod
248
- def handle_create(
249
- cls,
250
- data: Any,
251
- data_args: Optional[dict[str, Any]],
252
- processor: Optional[Union[str, Path, PreTrainedTokenizerBase]],
253
- processor_args: Optional[dict[str, Any]],
254
- random_seed: int,
255
- ) -> Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
256
- processor = check_load_processor(
257
- processor,
258
- processor_args,
259
- error_msg=(
260
- "Processor/tokenizer required for synthetic dataset generation."
261
- ),
262
- )
263
-
264
- config = SyntheticDatasetConfig.parse_str(data)
265
- generator = SyntheticTextItemsGenerator(config, processor, random_seed)
266
- items = list(generator)
267
-
268
- return Dataset.from_list(items, **(data_args or {}))
269
-
270
- @classmethod
271
- def extract_args_column_mappings(
272
- cls,
273
- data_args: Optional[dict[str, Any]],
274
- ) -> dict[ColumnInputTypes, str]:
275
- data_args_columns = super().extract_args_column_mappings(data_args)
276
-
277
- if data_args_columns:
278
- raise ValueError(
279
- f"Column mappings are not supported for synthetic datasets. "
280
- f"Got {data_args_columns}"
281
- )
282
-
283
- return {
284
- "prompt_column": "prompt",
285
- "prompt_tokens_count_column": "prompt_tokens_count",
286
- "output_tokens_count_column": "output_tokens_count",
287
- }
@@ -1,18 +0,0 @@
1
- from .pydantic import StandardBaseModel, StatusBreakdown
2
- from .statistics import (
3
- DistributionSummary,
4
- Percentiles,
5
- RunningStats,
6
- StatusDistributionSummary,
7
- TimeRunningStats,
8
- )
9
-
10
- __all__ = [
11
- "DistributionSummary",
12
- "Percentiles",
13
- "RunningStats",
14
- "StandardBaseModel",
15
- "StatusBreakdown",
16
- "StatusDistributionSummary",
17
- "TimeRunningStats",
18
- ]
@@ -1,89 +0,0 @@
1
- import json
2
- from pathlib import Path
3
- from typing import Any, Generic, Optional, TypeVar
4
-
5
- import yaml
6
- from loguru import logger
7
- from pydantic import BaseModel, ConfigDict, Field
8
-
9
- __all__ = ["StandardBaseModel", "StatusBreakdown"]
10
-
11
- T = TypeVar("T", bound="StandardBaseModel")
12
-
13
-
14
- class StandardBaseModel(BaseModel):
15
- """
16
- A base class for Pydantic models throughout GuideLLM enabling standard
17
- configuration and logging.
18
- """
19
-
20
- model_config = ConfigDict(
21
- extra="ignore",
22
- use_enum_values=True,
23
- validate_assignment=True,
24
- from_attributes=True,
25
- )
26
-
27
- def __init__(self, /, **data: Any) -> None:
28
- super().__init__(**data)
29
- logger.debug(
30
- "Initialized new instance of {} with data: {}",
31
- self.__class__.__name__,
32
- data,
33
- )
34
-
35
- @classmethod
36
- def get_default(cls: type[T], field: str) -> Any:
37
- """Get default values for model fields"""
38
- return cls.model_fields[field].default
39
-
40
- @classmethod
41
- def from_file(cls: type[T], filename: Path, overrides: Optional[dict] = None) -> T:
42
- """
43
- Attempt to create a new instance of the model using
44
- data loaded from json or yaml file.
45
- """
46
- try:
47
- with filename.open() as f:
48
- if str(filename).endswith(".json"):
49
- data = json.load(f)
50
- else: # Assume everything else is yaml
51
- data = yaml.safe_load(f)
52
- except (json.JSONDecodeError, yaml.YAMLError) as e:
53
- logger.error(f"Failed to parse {filename} as type {cls.__name__}")
54
- raise ValueError(f"Error when parsing file: {filename}") from e
55
-
56
- data.update(overrides)
57
- return cls.model_validate(data)
58
-
59
-
60
- SuccessfulT = TypeVar("SuccessfulT")
61
- ErroredT = TypeVar("ErroredT")
62
- IncompleteT = TypeVar("IncompleteT")
63
- TotalT = TypeVar("TotalT")
64
-
65
-
66
- class StatusBreakdown(BaseModel, Generic[SuccessfulT, ErroredT, IncompleteT, TotalT]):
67
- """
68
- A base class for Pydantic models that are separated by statuses including
69
- successful, incomplete, and errored. It additionally enables the inclusion
70
- of total, which is intended as the combination of all statuses.
71
- Total may or may not be used depending on if it duplicates information.
72
- """
73
-
74
- successful: SuccessfulT = Field(
75
- description="The results with a successful status.",
76
- default=None, # type: ignore[assignment]
77
- )
78
- errored: ErroredT = Field(
79
- description="The results with an errored status.",
80
- default=None, # type: ignore[assignment]
81
- )
82
- incomplete: IncompleteT = Field(
83
- description="The results with an incomplete status.",
84
- default=None, # type: ignore[assignment]
85
- )
86
- total: TotalT = Field(
87
- description="The combination of all statuses.",
88
- default=None, # type: ignore[assignment]
89
- )