"" if topk <= 0: raise ValueError("Can't apply algorithm topk with parameter {topk=} <= 0") topk_logits, topk_idxs = jax.lax.top_k(logits, topk) topk_token = jnp.expand_dims( jax.random.categorical(rng, topk_logits / temperature).astype(jnp.int32), axis=-1, ) sampled_tokens...
import jax; import jax.numpy as jnp; from jax.scipy.special import logit; init_dist = jnp.array([0.8, 0.2]); rng_key = jax.random.PRNGKey(0);initial_state = jax.random.categorical(rng_key, logits=logit(init_dist), shape=(1,)) ...
# 需要导入模块: import jax [as 别名]# 或者: from jax importvalue_and_grad[as 别名]deftest_categorical_log_prob_grad():data = jnp.repeat(jnp.arange(3),10)deff(x):returndist.Categorical(jax.nn.softmax(x * jnp.arange(1,4))).log_prob(data).sum()defg(x):returndist.Categorical(log...
(logits=jax.random.normal(key=rng,shape=(3,4)),dtype=jax.numpy.float32).sample(seed=rng)/home/user/anaconda3/envs/ml_exp/lib/python3.9/site-packages/jax/_src/numpy/array_methods.py:68:UserWarning:Explicitlyrequesteddtype<class'jax.numpy.int64'>requestedinastypeisnotavailable,andwillbe...
target = jax.random.randint(rng, shape=(2, 3), minval=0, maxval=2) preds = jax.random.uniform(rng, shape=(2, 3)) loss = jm.losses.mean_absolute_error(target, preds) loss = mtx.losses.mean_absolute_error(target, preds) assert loss.shape == (2,) Expand Down Expand Up @@ -58...