(params, rng, batch, n_tokens, cfg_scale, top_k, temperature)
| 104 | params = tree_apply(shard_fns, params) |
| 105 | |
| 106 | def _forward_generate(params, rng, batch, n_tokens, cfg_scale, top_k, temperature): |
| 107 | batch = with_sharding_constraint(batch, PS(('dp', 'fsdp'), 'sp')) |
| 108 | cfg_scales = jnp.ones((batch['input_ids'].shape[0] // 2,), dtype=jnp.float32) * cfg_scale |
| 109 | cfg_scales = with_sharding_constraint(cfg_scales, PS(('dp', 'fsdp'))) |
| 110 | rng_generator = JaxRNG(rng) |
| 111 | output = model.generate_vision( |
| 112 | batch['input_ids'], |
| 113 | cfg_scales, |
| 114 | attention_mask=batch['attention_mask'], |
| 115 | vision_masks=batch['vision_masks'], |
| 116 | params=params['params'], |
| 117 | prng_key=rng_generator(), |
| 118 | generation_config=GenerationConfig( |
| 119 | max_new_tokens=n_tokens, |
| 120 | min_new_tokens=n_tokens, |
| 121 | pad_token_id=tokenizer.pad_token_id, |
| 122 | temperature=temperature, |
| 123 | do_sample=True, |
| 124 | top_k=top_k, |
| 125 | ) |
| 126 | ).sequences[:, batch['input_ids'].shape[1]:] |
| 127 | return output, rng_generator() |
| 128 | _sharded_forward_generate = pjit( |
| 129 | _forward_generate, |
| 130 | in_shardings=(model_ps, PS(), PS()), |
nothing calls this directly
no test coverage detected