ding.rl_utils.log_prob_utils¶
ding.rl_utils.log_prob_utils
¶
naive_method(logits, index)
¶
Calculate per-token log probabilities using naive method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Token logits of shape [B, S, V] or [S, V] where: B = batch size S = sequence length V = vocabulary size |
required |
index
|
Tensor
|
Selected token indices of shape [B, S] or [S] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Log probabilities for selected tokens of shape [B, S] or [S] |
efficient_method(logits, index)
¶
Calculate per-token log probabilities efficiently.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Token logits of shape [B, S, V] or [S, V] where: B = batch size S = sequence length V = vocabulary size |
required |
index
|
Tensor
|
Selected token indices of shape [B, S] or [S] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Log probabilities for selected tokens of shape [B, S] or [S] |
less_efficient_method(logits, index)
¶
Calculate per-token log probabilities using categorical distribution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Token logits of shape [B, S, V] or [S, V] where: B = batch size S = sequence length V = vocabulary size |
required |
index
|
Tensor
|
Selected token indices of shape [B, S] or [S] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tensor |
Tensor
|
Log probabilities for selected tokens of shape [B, S] or [S] |
Full Source Code
../ding/rl_utils/log_prob_utils.py