MCPcopy Create free account
hub / github.com/AI-Hypercomputer/maxtext / generate

Method generate

src/MaxText/maxengine.py:915–951  ·  view source on GitHub ↗

Public API for generate that updates page state outside JIT.

(
      self,
      params: Params,
      decode_state: DecodeState,
      sampler: Callable[[Any], Any] | None = None,  # pylint: disable=unused-argument
      rng: PRNGKeyType | None = None,
      algorithm: str | None = None,
      topk: int | None = None,
      nucleus_topp: float | None = None,
      temperature: float | None = None,
  )

Source from the content-addressed store, hash-verified

913
914 # Public non-JIT generate method that updates page state
915 def generate(
916 self,
917 params: Params,
918 decode_state: DecodeState,
919 sampler: Callable[[Any], Any] | None = None, # pylint: disable=unused-argument
920 rng: PRNGKeyType | None = None,
921 algorithm: str | None = None,
922 topk: int | None = None,
923 nucleus_topp: float | None = None,
924 temperature: float | None = None,
925 ) -> tuple[DecodeState, engine_api.ResultTokens]:
926 """Public API for generate that updates page state outside JIT."""
927
928 # Update page state before JIT call
929 if self.page_manager is not None and self.page_state is not None:
930 self.page_state = self.page_manager.update_decode_pages(self.page_state)
931
932 # Sample rng before JIT call
933 if rng is None:
934 if self.rng is None:
935 self.rng = jax.random.PRNGKey(0)
936 self.rng, rng = jax.random.split(self.rng)
937
938 # Call JIT-compiled version with current state
939 new_state, result = self._generate_jit(
940 params=params,
941 decode_state=decode_state,
942 sampler=sampler,
943 page_state=self.page_state,
944 rng=rng,
945 algorithm=algorithm,
946 topk=topk,
947 nucleus_topp=nucleus_topp,
948 temperature=temperature,
949 )
950
951 return max_utils.unbox_logicallypartioned(new_state), result
952
953 @functools.partial(
954 jax.jit, static_argnums=(0,), donate_argnums=(2,), static_argnames=("algorithm", "topk", "nucleus_topp")

Callers 12

mainFunction · 0.95
generate_aotMethod · 0.95
mainFunction · 0.95
mainFunction · 0.95
test_basic_decodeMethod · 0.95
mainFunction · 0.95
decode_with_vllmFunction · 0.80
decode_with_tunixFunction · 0.80
_jitted_generate_fnMethod · 0.80
generate_responsesFunction · 0.80
evaluate_modelFunction · 0.80
_run_generation_loopMethod · 0.80

Calls 2

_generate_jitMethod · 0.95
update_decode_pagesMethod · 0.80

Tested by 1

test_basic_decodeMethod · 0.76