sampling_params.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. """Sampling parameters for text generation."""
  2. import copy
  3. import os
  4. from enum import IntEnum
  5. from functools import cached_property
  6. from typing import Any, Callable, Dict, List, Optional, Set, Union
  7. import msgspec
  8. import torch
  9. from loguru import logger
  10. from typing_extensions import Annotated
  11. _SAMPLING_EPS = 1e-5
  12. _MAX_TEMP = 1e-2
  13. APHRODITE_NO_DEPRECATION_WARNING = bool(
  14. int(os.environ.get("APHRODITE_NO_DEPRECATION_WARNING", "0")))
  15. class SamplingType(IntEnum):
  16. GREEDY = 0
  17. RANDOM = 1
  18. RANDOM_SEED = 2
  19. BEAM = 3
  20. LogitsProcessorFunc = Union[Callable[[List[int], torch.Tensor], torch.Tensor],
  21. Callable[[List[int], List[int], torch.Tensor],
  22. torch.Tensor]]
  23. """LogitsProcessor is a function that takes a list
  24. of previously generated tokens, the logits tensor
  25. for the next token and, optionally, prompt tokens as a
  26. first argument, and returns a modified tensor of logits
  27. to sample from."""
  28. class SamplingParams(
  29. msgspec.Struct,
  30. omit_defaults=True,
  31. dict=True):
  32. """Sampling parameters for text generation.
  33. Overall, we follow the sampling parameters from the OpenAI text completion
  34. API (https://platform.openai.com/docs/api-reference/completions/create).
  35. In addition, we support multiple additional samplers which are not supported
  36. by OpenAI.
  37. Args:
  38. n: Number of output sequences to return for the given prompt.
  39. best_of: Number of output sequences that are generated from the prompt.
  40. From these `best_of` sequences, the top `n` sequences are returned.
  41. `best_of` must be greater than or equal to `n`. This is treated as
  42. the beam width when `use_beam_search` is True. By default, `best_of`
  43. is set to `n`.
  44. presence_penalty: Float that penalizes new tokens based on whether they
  45. appear in the generated text so far. Values > 0 encourage the model
  46. to use new tokens, while values < 0 encourage the model to repeat
  47. tokens.
  48. frequency_penalty: Float that penalizes new tokens based on their
  49. frequency in the generated text so far. Values > 0 encourage the
  50. model to use new tokens, while values < 0 encourage the model to
  51. repeat tokens.
  52. repetition_penalty: Float that penalizes new tokens based on their
  53. frequency in the generated text so far.
  54. freq_pen is applied additively while
  55. rep_pen is applied multiplicatively.
  56. Must be in [1, inf). Set to 1 to disable the effect.
  57. temperature: Float that controls the randomness of the sampling. Lower
  58. values make the model more deterministic, while higher values make
  59. the model more random. Zero means greedy sampling.
  60. top_p: Float that controls the cumulative probability of the top tokens
  61. to consider. Must be in (0, 1]. Set to 1 to consider all tokens.
  62. top_k: Integer that controls the number of top tokens to consider. Set
  63. to -1 to consider all tokens.
  64. top_a: Float that controls the cutoff for Top-A sampling.
  65. Exact cutoff is top_a*max_prob**2. Must be in [0,inf], 0 to disable.
  66. min_p: Float that controls the cutoff for min-p sampling.
  67. Exact cutoff is min_p*max_prob. Must be in [0,1], 0 to disable.
  68. tfs: Float that controls the cumulative approximate curvature of the
  69. distribution to retain for Tail Free Sampling.
  70. Must be in (0, 1]. Set to 1 to disable
  71. eta_cutoff: Float that controls the cutoff threshold for Eta sampling
  72. (a form of entropy adaptive truncation sampling)
  73. threshold is computed as min(eta, sqrt(eta)*entropy(probs)).
  74. Specified in units of 1e-4. Set to 0 to disable
  75. epsilon_cutoff: Float that controls the cutoff threshold for
  76. Epsilon sampling (simple probability threshold truncation).
  77. Specified in units of 1e-4. Set to 0 to disable.
  78. typical_p: Float that controls the cumulative probability of tokens
  79. closest in surprise to the expected surprise to consider.
  80. Must be in (0, 1]. Set to 1 to disable.
  81. mirostat_mode: Can either be 0 (disabled) or 2 (Mirostat v2).
  82. mirostat_tau: Target "surprisal" that mirostat works towards.
  83. Range [0, inf).
  84. mirostat_eta: Rate at which mirostat updates its internal surprisal
  85. value. Range [0, inf).
  86. dynatemp_min: Minimum temperature for dynatemp sampling.
  87. Range [0, inf).
  88. dynatemp_max: Maximum temperature for dynatemp sampling.
  89. Range [0, inf).
  90. dynatemp_exponent: Exponent for dynatemp sampling. Range [0, inf).
  91. smoothing_factor: Smoothing factor for Quadratic Sampling.
  92. smoothing_curve: Smoothing curve for Quadratic (Cubic) Sampling.
  93. seed: Random seed to use for the generation.
  94. use_beam_search: Whether to use beam search instead of sampling.
  95. length_penalty: Float that penalizes sequences based on their length.
  96. Used in beam search.
  97. early_stopping: Controls the stopping condition for beam search. It
  98. accepts the following values: `True`, where the generation stops as
  99. soon as there are `best_of` complete candidates; `False`, where an
  100. heuristic is applied and the generation stops when is it very
  101. unlikely to find better candidates; `"never"`, where the beam search
  102. procedure only stops when there cannot be better candidates
  103. (canonical beam search algorithm).
  104. stop: List of strings that stop the generation when they are generated.
  105. The returned output will not contain the stop strings.
  106. stop_token_ids: List of tokens that stop the generation when they are
  107. generated. The returned output will contain the stop tokens unless
  108. the stop tokens are special tokens.
  109. include_stop_str_in_output: Whether to include the stop strings in
  110. output text. Defaults to False.
  111. ignore_eos: Whether to ignore the EOS token and continue generating
  112. tokens after the EOS token is generated.
  113. max_tokens: Maximum number of tokens to generate per output sequence.
  114. min_tokens: Minimum number of tokens to generate per output sequence
  115. before EOS or stop tokens are generated.
  116. logprobs: Number of log probabilities to return per output token.
  117. When set to None, no probability is returned. If set to a non-None
  118. value, the result includes the log probabilities of the specified
  119. number of most likely tokens, as well as the chosen tokens.
  120. Note that the implementation follows the OpenAI API: The API will
  121. always return the log probability of the sampled token, so there
  122. may be up to `logprobs+1` elements in the response.
  123. prompt_logprobs: Number of log probabilities to return per prompt token.
  124. detokenize: Whether to detokenize the output. Defaults to True.
  125. custom_token_bans: List of token IDs to ban from generating
  126. skip_special_tokens: Whether to skip special tokens in the output.
  127. defaults to true.
  128. spaces_between_special_tokens: Whether to add spaces between special
  129. tokens in the output. Defaults to True.
  130. logits_processors: List of functions that modify logits based on
  131. previously generated tokens, and optionally prompt tokens as
  132. a first argument.
  133. truncate_prompt_tokens: If set to an integer k, will use only the last
  134. k tokens from the prompt (i.e. left-truncation). Defaults to None
  135. (i.e. no truncation).
  136. xtc_threshold: In XTC sampling, if 2 or more tokens have probability
  137. above this threshold, consider removing all but the last one.
  138. xtc_probability: Probability that the removal will actually happen.
  139. 0 disables the sampler, 1 makes it always happen.
  140. nsigma: Number of standard deviations from the maximum logit to use
  141. as a cutoff threshold. Tokens with logits below
  142. (max_logit - nsgima * std_dev) are filtered out. Higher values
  143. (e.g. 3.0) keep more tokens, lower values (e.g. 1.0) are more
  144. selective. Must be positive. 0 to disable.
  145. dry_multiplier: Float that controls the magnitude of the DRY sampling
  146. penalty. Higher values create stronger penalties against
  147. repetition. The penalty is multiplied by this value before being
  148. applied. Must be non-negative. 0 disables the sampler.
  149. dry_base: Base for the exponential growth of the DRY sampling penalty.
  150. Controls how quickly the penalty increases with longer repeated
  151. sequences. Must be greater than 1. Higher values (e.g. 2.0) create
  152. more aggressive penalties for longer repetitions. Defaults to 1.75.
  153. dry_allowed_length: Maximum number of tokens that can be repeated
  154. without incurring a DRY sampling penalty. Sequences longer than
  155. this will be penalized exponentially. Must be at least 1.
  156. Defaults to 2.
  157. dry_sequence_breaker_ids: List of token IDs that stop
  158. the matching of repeated content. These tokens will break up the
  159. input into sections where repetition is evaluated separately.
  160. Common examples are newlines, quotes, and other structural tokens.
  161. Defaults to None.
  162. """
  163. n: int = 1
  164. best_of: Optional[int] = None
  165. presence_penalty: float = 0.0
  166. frequency_penalty: float = 0.0
  167. repetition_penalty: float = 1.0
  168. temperature: float = 1.0
  169. dynatemp_min: float = 0.0
  170. dynatemp_max: float = 0.0
  171. dynatemp_exponent: float = 1.0
  172. temperature_last: bool = False
  173. top_p: float = 1.0
  174. top_k: int = -1
  175. top_a: float = 0.0
  176. min_p: float = 0.0
  177. tfs: float = 1.0
  178. eta_cutoff: float = 0.0
  179. epsilon_cutoff: float = 0.0
  180. typical_p: float = 1.0
  181. smoothing_factor: float = 0.0
  182. smoothing_curve: float = 1.0
  183. seed: Optional[int] = None
  184. use_beam_search: bool = False
  185. length_penalty: float = 1.0
  186. early_stopping: Union[bool, str] = False
  187. stop: Union[None, str, List[str]] = None
  188. stop_token_ids: Optional[List[int]] = None
  189. include_stop_str_in_output: bool = False
  190. ignore_eos: bool = False
  191. max_tokens: Optional[int] = 16
  192. min_tokens: int = 0
  193. logprobs: Optional[int] = None
  194. prompt_logprobs: Optional[int] = None
  195. detokenize: bool = True
  196. custom_token_bans: Optional[List[int]] = None
  197. skip_special_tokens: bool = True
  198. spaces_between_special_tokens: bool = True
  199. # Optional[List[LogitsProcessorFunc]] type.
  200. # We use Any here because the type above
  201. # is not supported by msgspec.
  202. logits_processors: Optional[Any] = None
  203. truncate_prompt_tokens: Optional[Annotated[int, msgspec.Meta(ge=1)]] = None
  204. xtc_threshold: float = 0.1
  205. xtc_probability: float = 0
  206. nsigma: float = 0.0
  207. dry_multiplier: float = 0.0
  208. dry_base: float = 1.75
  209. dry_allowed_length: int = 2
  210. dry_sequence_breaker_ids: List[int] = []
  211. # The below fields are not supposed to be used as an input.
  212. # They are set in post_init.
  213. output_text_buffer_length: int = 0
  214. _all_stop_token_ids: Set[int] = msgspec.field(default_factory=set)
  215. default_values = {
  216. "n": 1,
  217. "best_of": 1,
  218. "presence_penalty": 0.0,
  219. "frequency_penalty": 0.0,
  220. "repetition_penalty": 1.0,
  221. "temperature": 1.0,
  222. "dynatemp_min": 0.0,
  223. "dynatemp_max": 0.0,
  224. "dynatemp_exponent": 1.0,
  225. "temperature_last": False,
  226. "top_p": 1.0,
  227. "top_k": -1,
  228. "top_a": 0.0,
  229. "min_p": 0.0,
  230. "tfs": 1.0,
  231. "eta_cutoff": 0.0,
  232. "epsilon_cutoff": 0.0,
  233. "typical_p": 1.0,
  234. "smoothing_factor": 0.0,
  235. "smoothing_curve": 1.0,
  236. "seed": None,
  237. "use_beam_search": False,
  238. "length_penalty": 1.0,
  239. "early_stopping": False,
  240. "stop": [],
  241. "stop_token_ids": [],
  242. "ignore_eos": False,
  243. "max_tokens": 16,
  244. "min_tokens": 0,
  245. "logprobs": None,
  246. "prompt_logprobs": None,
  247. "detokenize": True,
  248. "custom_token_bans": [],
  249. "skip_special_tokens": True,
  250. "spaces_between_special_tokens": True,
  251. "include_stop_str_in_output": False,
  252. "truncate_prompt_tokens": None,
  253. "xtc_threshold": 0.1,
  254. "xtc_probability": 0,
  255. "nsigma": 0.0,
  256. "dry_multiplier": 0.0,
  257. "dry_base": 1.75,
  258. "dry_allowed_length": 2,
  259. "dry_sequence_breaker_ids": [],
  260. }
  261. def __post_init__(self) -> None:
  262. self.best_of = self.best_of or self.n
  263. if 0 < self.temperature < _MAX_TEMP:
  264. logger.warning(
  265. f"temperature {self.temperature} is less than {_MAX_TEMP}, "
  266. "which may cause numerical errors NaN or inf in tensors. We "
  267. f"have maxed it out to {_MAX_TEMP}.")
  268. self.temperature = max(self.temperature, _MAX_TEMP)
  269. if self.seed == -1:
  270. self.seed = None
  271. else:
  272. self.seed = self.seed
  273. if self.stop is None:
  274. self.stop = []
  275. elif isinstance(self.stop, str):
  276. self.stop = [self.stop]
  277. else:
  278. self.stop = list(self.stop)
  279. if self.stop_token_ids is None:
  280. self.stop_token_ids = []
  281. else:
  282. self.stop_token_ids = list(self.stop_token_ids)
  283. self.logprobs = 1 if self.logprobs is True else self.logprobs
  284. self.prompt_logprobs = (1 if self.prompt_logprobs is True else
  285. self.prompt_logprobs)
  286. # Number of characters to hold back for stop string evaluation
  287. # until sequence is finished.
  288. if self.stop and not self.include_stop_str_in_output:
  289. self.output_text_buffer_length = max(len(s) for s in self.stop) - 1
  290. self._verify_args()
  291. if self.use_beam_search:
  292. if not APHRODITE_NO_DEPRECATION_WARNING:
  293. logger.warning(
  294. "[IMPORTANT] We plan to discontinue the support for beam "
  295. "search in the next major release. Set "
  296. "APHRODITE_NO_DEPRECATION_WARNING=1 to "
  297. "suppress this warning.")
  298. self._verify_beam_search()
  299. else:
  300. self._verify_non_beam_search()
  301. if self.temperature < _SAMPLING_EPS:
  302. # Zero temperature means greedy sampling.
  303. self.top_p = 1.0
  304. self.top_k = -1
  305. self.min_p = 0.0
  306. self.top_a = 0.0
  307. self._verify_greedy_sampling()
  308. # eos_token_id is added to this by the engine
  309. self._all_stop_token_ids = set(self.stop_token_ids)
  310. def _verify_args(self) -> None:
  311. if self.n < 1:
  312. raise ValueError(f"n must be at least 1, got {self.n}.")
  313. assert isinstance(self.best_of, int)
  314. if self.best_of < self.n:
  315. raise ValueError(f"best_of must be greater than or equal to n, "
  316. f"got n={self.n} and best_of={self.best_of}.")
  317. if not -2.0 <= self.presence_penalty <= 2.0:
  318. raise ValueError("presence_penalty must be in [-2, 2], got "
  319. f"{self.presence_penalty}.")
  320. if not -2.0 <= self.frequency_penalty <= 2.0:
  321. raise ValueError("frequency_penalty must be in [-2, 2], got "
  322. f"{self.frequency_penalty}.")
  323. if self.repetition_penalty < 1.0:
  324. raise ValueError("repetition_penalty must be in [1, inf), got "
  325. f"{self.repetition_penalty}.")
  326. if self.temperature < 0.0:
  327. raise ValueError(
  328. f"temperature must be non-negative, got {self.temperature}.")
  329. if not 0.0 < self.top_p <= 1.0:
  330. raise ValueError(f"top_p must be in (0, 1], got {self.top_p}.")
  331. if self.top_k < -1 or self.top_k == 0:
  332. raise ValueError(f"top_k must be -1 (disable), or at least 1, "
  333. f"got {self.top_k}.")
  334. if self.top_a < 0:
  335. raise ValueError(f"top_a must be non negative, got {self.top_a}.")
  336. if not 0.0 <= self.min_p <= 1.0:
  337. raise ValueError(f"min_p must be in [0, 1], got {self.min_p}.")
  338. if not 0.0 < self.tfs <= 1.0:
  339. raise ValueError(f"tfs must be in (0, 1], got {self.tfs}.")
  340. if self.epsilon_cutoff < 0.0 or self.epsilon_cutoff > 1000.0:
  341. raise ValueError("epsilon_cutoff must be in [0, 1000], got "
  342. f"{self.epsilon_cutoff}.")
  343. # pylint: disable=unneeded-not
  344. if not self.eta_cutoff >= 0:
  345. raise ValueError(
  346. f"eta_cutoff must be non negative, got {self.eta_cutoff}.")
  347. if not 0.0 <= self.typical_p <= 1.0:
  348. raise ValueError(
  349. f"typical_p must be in (0, 1], got {self.typical_p}.")
  350. if self.max_tokens is not None and self.max_tokens < 1:
  351. raise ValueError(
  352. f"max_tokens must be at least 1, got {self.max_tokens}.")
  353. if self.min_tokens < 0:
  354. raise ValueError(f"min_tokens must be greater than or equal to 0, "
  355. f"got {self.min_tokens}.")
  356. if self.max_tokens is not None and self.min_tokens > self.max_tokens:
  357. raise ValueError(
  358. f"min_tokens must be less than or equal to "
  359. f"max_tokens={self.max_tokens}, got {self.min_tokens}.")
  360. if self.logprobs is not None and self.logprobs < 0:
  361. raise ValueError(
  362. f"logprobs must be non-negative, got {self.logprobs}.")
  363. if self.prompt_logprobs is not None and self.prompt_logprobs < 0:
  364. raise ValueError("prompt_logprobs must be non-negative, got "
  365. f"{self.prompt_logprobs}.")
  366. if (self.truncate_prompt_tokens is not None
  367. and self.truncate_prompt_tokens < 1):
  368. raise ValueError(f"truncate_prompt_tokens must be >= 1, "
  369. f"got {self.truncate_prompt_tokens}")
  370. assert isinstance(self.stop, list)
  371. if any(not stop_str for stop_str in self.stop):
  372. raise ValueError("stop cannot contain an empty string.")
  373. if self.stop and not self.detokenize:
  374. raise ValueError(
  375. "stop strings are only supported when detokenize is True. "
  376. "Set detokenize=True to use stop.")
  377. if self.xtc_threshold < 0.0:
  378. raise ValueError(
  379. "xtc_threshold must be non-negative, got "
  380. f"{self.xtc_threshold}.")
  381. if not 0.0 <= self.xtc_probability <= 1.0:
  382. raise ValueError(
  383. "xtc_probability must be in [0, 1], got "
  384. f"{self.xtc_probability}.")
  385. if self.nsigma < 0.0:
  386. raise ValueError(
  387. "nsigma must be non-negative, got "
  388. f"{self.nsigma}.")
  389. if self.dry_multiplier < 0.0:
  390. raise ValueError(
  391. "dry_multiplier must be non-negative, got "
  392. f"{self.dry_multiplier}.")
  393. if self.dry_base <= 1.0:
  394. raise ValueError(
  395. "dry_base must be greater than 1, got "
  396. f"{self.dry_base}.")
  397. if self.dry_allowed_length < 0:
  398. raise ValueError(
  399. "dry_allowed_length must be non-negative, got "
  400. f"{self.dry_allowed_length}.")
  401. def _verify_beam_search(self) -> None:
  402. if self.best_of == 1:
  403. raise ValueError("best_of must be greater than 1 when using beam "
  404. f"search. Got {self.best_of}.")
  405. if self.temperature > _SAMPLING_EPS:
  406. raise ValueError("temperature must be 0 when using beam search.")
  407. if self.top_p < 1.0 - _SAMPLING_EPS:
  408. raise ValueError("top_p must be 1 when using beam search.")
  409. if self.top_k != -1:
  410. raise ValueError("top_k must be -1 when using beam search.")
  411. if self.early_stopping not in [True, False, "never"]:
  412. raise ValueError(
  413. f"early_stopping must be True, False, or 'never', "
  414. f"got {self.early_stopping}.")
  415. def _verify_non_beam_search(self) -> None:
  416. if self.early_stopping is not False:
  417. raise ValueError("early_stopping is not effective and must be "
  418. "False when not using beam search.")
  419. if (self.length_penalty < 1.0 - _SAMPLING_EPS
  420. or self.length_penalty > 1.0 + _SAMPLING_EPS):
  421. raise ValueError(
  422. "length_penalty is not effective and must be the "
  423. "default value of 1.0 when not using beam search.")
  424. def _verify_greedy_sampling(self) -> None:
  425. assert isinstance(self.best_of, int)
  426. if self.best_of > 1:
  427. raise ValueError("best_of must be 1 when using greedy sampling."
  428. f"Got {self.best_of}.")
  429. if self.top_p < 1.0 - _SAMPLING_EPS:
  430. raise ValueError("top_p must be 1 when using greedy sampling.")
  431. if self.top_k != -1:
  432. raise ValueError("top_k must be -1 when using greedy sampling.")
  433. def update_from_generation_config(
  434. self,
  435. generation_config: Dict[str, Any],
  436. model_eos_token_id: Optional[int] = None) -> None:
  437. """Update if there are non-default values from generation_config"""
  438. if model_eos_token_id is not None:
  439. # Add the eos token id into the sampling_params to support
  440. # min_tokens processing.
  441. self._all_stop_token_ids.add(model_eos_token_id)
  442. # Update eos_token_id for generation
  443. if (eos_ids := generation_config.get("eos_token_id")) is not None:
  444. # it can be either int or list of int
  445. eos_ids = {eos_ids} if isinstance(eos_ids, int) else set(eos_ids)
  446. if model_eos_token_id is not None:
  447. # We don't need to include the primary eos_token_id in
  448. # stop_token_ids since it's handled separately for stopping
  449. # purposes.
  450. eos_ids.discard(model_eos_token_id)
  451. if eos_ids:
  452. self._all_stop_token_ids.update(eos_ids)
  453. if not self.ignore_eos:
  454. assert isinstance(self.stop_token_ids, list)
  455. eos_ids.update(self.stop_token_ids)
  456. self.stop_token_ids = list(eos_ids)
  457. @cached_property
  458. def sampling_type(self) -> SamplingType:
  459. if self.use_beam_search:
  460. return SamplingType.BEAM
  461. if self.temperature < _SAMPLING_EPS:
  462. return SamplingType.GREEDY
  463. if self.seed is not None:
  464. return SamplingType.RANDOM_SEED
  465. return SamplingType.RANDOM
  466. @property
  467. def all_stop_token_ids(self) -> Set[int]:
  468. return self._all_stop_token_ids
  469. def clone(self) -> "SamplingParams":
  470. """Deep copy excluding LogitsProcessor objects.
  471. LogitsProcessor objects are excluded because they may contain an
  472. arbitrary, nontrivial amount of data.
  473. """
  474. logit_processor_refs = None if self.logits_processors is None else {
  475. id(lp): lp
  476. for lp in self.logits_processors
  477. }
  478. return copy.deepcopy(self, memo=logit_processor_refs)
  479. def __repr__(self) -> str:
  480. repr_str = "SamplingParams("
  481. for param, default_value in self.default_values.items():
  482. current_value = getattr(self, param)
  483. if current_value != default_value:
  484. repr_str += f"{param}={current_value}, "
  485. repr_str = repr_str.rstrip(', ') + ")"
  486. return repr_str