コード例 #1
0
 def schedule(step):
     nonlocal init_val  # need this to prevent UnboundLocalError: local variable 'init_val' referenced before assignment
     pct = step / num_steps
     ind, branches, prev_pct = 0, [], 0.
     for val, stage_pct in vals_and_pcts:
         ind = ind + jnp.uint8(pct > stage_pct)
         branches.append(
             _get_branch_fn(anneal_fn, init_val, val, stage_pct, prev_pct))
         init_val, prev_pct = val, stage_pct
     branches.append(lambda p: val)
     return jax.lax.switch(ind, branches, pct)
コード例 #2
0
ファイル: ppo.py プロジェクト: steins024/tensor2tensor
def get_padding_value(dtype):
    """Returns the padding value given a dtype."""
    padding_value = None
    if dtype == np.uint8:
        padding_value = np.uint8(0)
    elif dtype == np.uint16:
        padding_value = np.uint16(0)
    elif dtype == np.float32 or dtype == np.float64:
        padding_value = 0.0
    else:
        padding_value = 0
    assert padding_value is not None
    return padding_value