mstar.engine.resources.position.config#

What a model declares about positions: its scheme, its spec, its step.

Kept free of the manager and its kernels so a submodule can declare a step without pulling FlashInfer in behind it.

Classes

LongRoPE(short_factor, long_factor, ...)

LongRoPE scaling (Phi-3, Phi-4-mini): every rotary frequency divided by a per-dimension factor, from a short set or a long set, and cos/sin scaled by sqrt(1 + ln(max / original) / ln(original)).

PosBackend(*values)

PosScheme(*values)

PositionConfig(kv_cache, backend, scheme, ...)

PositionReqConfig(max_position)

The length a resource that picks its rotary table per request (PositionConfig.longrope) chooses by: the one the model's reference chooses by, which for Phi-3 and Phi-4 is the prompt's (LongRoPE).

PositionSpec(resource_key, nodes, config)

PositionStep(segments, ...] | None = None, ...)

class mstar.engine.resources.position.config.LongRoPE(short_factor, long_factor, original_max_position_embeddings, max_position_embeddings)[source]#

Bases: object

LongRoPE scaling (Phi-3, Phi-4-mini): every rotary frequency divided by a per-dimension factor, from a short set or a long set, and cos/sin scaled by sqrt(1 + ln(max / original) / ln(original)).

A request rotates under one set for its whole life, chosen from the length the model passes (PositionReqConfig.max_position): the long set past original_max_position_embeddings. Pass the length the model’s reference chooses by: for Phi-3 and Phi-4 that is the prompt’s, since the reference picks by the positions in its forward. Prompt plus max_tokens would put prompts the reference runs short on the long set. The reference switches mid-request, once its output crosses the threshold, and recomputes its cache; holding one set keeps a request’s KV consistent without that.

Parameters:
  • short_factor (tuple[float, ...])

  • long_factor (tuple[float, ...])

  • original_max_position_embeddings (int)

  • max_position_embeddings (int)

property attention_scale: float#
classmethod from_hf(config)[source]#

From a Hugging Face config with rope_scaling.type == "longrope".

Parameters:

config (Mapping[str, Any])

Return type:

LongRoPE

is_long(max_position)[source]#

Whether a request whose table is chosen by max_position rotates with the long factors.

Parameters:

max_position (int)

Return type:

bool

long_factor: tuple[float, ...]#
max_position_embeddings: int#
original_max_position_embeddings: int#
short_factor: tuple[float, ...]#
class mstar.engine.resources.position.config.PosBackend(*values)[source]#

Bases: Enum

ROPE = 'rope'#
class mstar.engine.resources.position.config.PosScheme(*values)[source]#

Bases: Enum

BLOCK = 'block'#
SEQUENTIAL = 'sequential'#
class mstar.engine.resources.position.config.PositionConfig(kv_cache: str, backend: mstar.engine.resources.position.config.PosBackend = <PosBackend.ROPE: 'rope'>, scheme: mstar.engine.resources.position.config.PosScheme = <PosScheme.SEQUENTIAL: 'sequential'>, block_step: int = 1, rotary_dim: int | None = None, interleave: bool = False, rope_scale: float = 1.0, rope_theta: float = 10000.0, rope_dtype: torch.dtype | None = None, rope_table_dtype: torch.dtype | None = None, low_freq_factor: float | None = None, high_freq_factor: float | None = None, old_context_len: int | None = None, longrope: mstar.engine.resources.position.config.LongRoPE | None = None)[source]#

Bases: object

Parameters:
backend: PosBackend = 'rope'#
block_step: int = 1#
high_freq_factor: float | None = None#
interleave: bool = False#
kv_cache: str#
property llama31_params: dict[str, float]#
longrope: LongRoPE | None = None#
low_freq_factor: float | None = None#
old_context_len: int | None = None#
rope_dtype: dtype | None = None#
rope_scale: float = 1.0#
rope_table_dtype: dtype | None = None#
rope_theta: float = 10000.0#
rotary_dim: int | None = None#
scheme: PosScheme = 'sequential'#
class mstar.engine.resources.position.config.PositionReqConfig(max_position)[source]#

Bases: ResourceReqConfig

The length a resource that picks its rotary table per request (PositionConfig.longrope) chooses by: the one the model’s reference chooses by, which for Phi-3 and Phi-4 is the prompt’s (LongRoPE).

Parameters:

max_position (int)

max_position: int#
validate(spec=None)[source]#

Raise ValueError if a client-supplied value is out of range, or one the resource built from spec cannot honour.

The conductor calls it at admission, so a bad request is a 400 before any worker sees it.

Parameters:

spec (NodeResourceSpec | None)

Return type:

None

class mstar.engine.resources.position.config.PositionSpec(resource_key: str, nodes: set[str], config: mstar.engine.resources.position.config.PositionConfig)[source]#

Bases: NodeResourceSpec

Parameters:
config: PositionConfig#
depends_on()[source]#

Keys whose specs this one builds against; the engine resolves them into EngineResourceInfo.dependencies.

Return type:

set[str]

derive(specs)[source]#

Set what this spec takes from the specs that read it (a KV pool keeps the window its attentions declare), after a deployment’s overrides; return what is wrong with it. Idempotent: it runs wherever the specs resolve (resolve_spec_dependencies).

Parameters:

specs (Mapping[str, NodeResourceSpec])

Return type:

list[str]

prefix_variant(model_kwargs)[source]#

The long table gives other KV than the short one for the same tokens, so a request on it keys its prefix apart; derived from the same kwarg as its config, so the two cannot disagree.

Parameters:

model_kwargs (dict | None)

Return type:

bytes | None

request_config(model_kwargs)[source]#

Under LongRoPE, the length the request’s table is chosen by, from MAX_POSITION_KWARG, which a model sets in process_prompt (the data worker drops a client’s); without it, the short table.

Parameters:

model_kwargs (dict | None)

Return type:

PositionReqConfig | None

property resource_class: type[Resource]#

What builds this spec. Imported inside the property, so declaring a resource stays free of the manager and its kernels.

The builder, not necessarily the class built: an attention spec names AttentionManager, whose build picks a backend subclass.

shard_key: str | None = None#
class mstar.engine.resources.position.config.PositionStep(segments: tuple[mstar.engine.resources.step.Segment, ...] | None = None, pos_ids: 'dict[str, torch.Tensor] | torch.Tensor | None' = None, advance: tuple[int, ...] | None = None, *, combined_labels: dict[tuple[str, ...], str] = <factory>)[source]#

Bases: ResourceStep

Parameters:
advance: tuple[int, ...] | None = None#
pos_ids: dict[str, Tensor] | Tensor | None = None#