Flat logprobs of a request into multiple primitive type lists.
Compared to list[dict[int, Logprob]], this data structure reduced GC overhead significantly. As it flattened logprob information for all positions and ranks in to multiple primitive type lists (i.e. logprobs, token_ids, ranks per token_ids, decoded_tokens). So regardless of the sequence length and top_logprobs setup, FlatLogprobs would only introduce a constant amount of objects.
As each position might contains different amount of ranks, start_indices_per_position would be used to access the logprob ranges for different positions.
NOTE: To reduce the migration overhead and improve backward compatibility, we support the key Sequence APIs of list, so it could act as list[LogprobsOnePosition]
Summary
Functions
Appends the container with logprobs for the next position
Appends logprobs for the next position without creating
S.clear() -> None -- remove all items from S
S.count(value) -> integer -- return number of occurrences of value
Extends the container with logprobs for the next multiple positions
S.index(value, [start, [stop]]) -> integer -- return first index of value.
S.insert(index, value) -- insert value before index
Initialize self. See help(type(self)) for accurate signature.
S.pop([index]) -> item -- remove and return item at index (default last).
S.remove(value) -- remove first occurrence of value.
S.reverse() -- reverse IN PLACE
Types
Functions
@spec append(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, nil} | {:error, Snakepit.Error.t()}
Appends the container with logprobs for the next position
Parameters
logprobs_one_position(term())
Returns
nil
@spec append_fast( SnakeBridge.Ref.t(), [integer()], [float()], term(), term(), keyword() ) :: {:ok, nil} | {:error, Snakepit.Error.t()}
Appends logprobs for the next position without creating
the intermediate logprob dictionary.
Parameters
token_ids(list(integer()))logprobs(list(float()))ranks(term())decoded_tokens(term())
Returns
nil
@spec clear( SnakeBridge.Ref.t(), keyword() ) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.clear() -> None -- remove all items from S
Returns
term()
@spec count(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.count(value) -> integer -- return number of occurrences of value
Parameters
value(term())
Returns
term()
@spec extend(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, nil} | {:error, Snakepit.Error.t()}
Extends the container with logprobs for the next multiple positions
Parameters
logprobs_multi_positions(term())
Returns
nil
@spec index(SnakeBridge.Ref.t(), term(), [term()], keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
Parameters
value(term())start(term() default: 0)stop(term() default: None)
Returns
term()
@spec insert(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, nil} | {:error, Snakepit.Error.t()}
S.insert(index, value) -- insert value before index
Parameters
item(term())
Returns
nil
@spec new( [term()], keyword() ) :: {:ok, SnakeBridge.Ref.t()} | {:error, Snakepit.Error.t()}
Initialize self. See help(type(self)) for accurate signature.
Parameters
start_indices(list(integer()) default: <factory>)end_indices(list(integer()) default: <factory>)token_ids(list(integer()) default: <factory>)logprobs(list(float()) default: <factory>)ranks(list(term()) default: <factory>)decoded_tokens(list(term()) default: <factory>)
@spec pop(SnakeBridge.Ref.t(), [term()], keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.pop([index]) -> item -- remove and return item at index (default last).
Raise IndexError if list is empty or index is out of range.
Parameters
index(term() default: -1)
Returns
term()
@spec remove(SnakeBridge.Ref.t(), term(), keyword()) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.remove(value) -- remove first occurrence of value.
Raise ValueError if the value is not present.
Parameters
value(term())
Returns
term()
@spec reverse( SnakeBridge.Ref.t(), keyword() ) :: {:ok, term()} | {:error, Snakepit.Error.t()}
S.reverse() -- reverse IN PLACE
Returns
term()