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 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 |
|
|
|
|
|
|
|
The length a resource that picks its rotary table per request ( |
|
|
|
- class mstar.engine.resources.position.config.LongRoPE(short_factor, long_factor, original_max_position_embeddings, max_position_embeddings)[source]#
Bases:
objectLongRoPE 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 pastoriginal_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 plusmax_tokenswould 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:
- classmethod from_hf(config)[source]#
From a Hugging Face config with
rope_scaling.type == "longrope".
- 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:
kv_cache (str)
backend (PosBackend)
scheme (PosScheme)
block_step (int)
rotary_dim (int | None)
interleave (bool)
rope_scale (float)
rope_theta (float)
rope_dtype (dtype | None)
rope_table_dtype (dtype | None)
low_freq_factor (float | None)
high_freq_factor (float | None)
old_context_len (int | None)
longrope (LongRoPE | None)
- backend: PosBackend = 'rope'#
- class mstar.engine.resources.position.config.PositionReqConfig(max_position)[source]#
Bases:
ResourceReqConfigThe 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)
- validate(spec=None)[source]#
Raise
ValueErrorif a client-supplied value is out of range, or one the resource built fromspeccannot 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:
resource_key (str)
config (PositionConfig)
- config: PositionConfig#
- depends_on()[source]#
Keys whose specs this one builds against; the engine resolves them into
EngineResourceInfo.dependencies.
- 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:
- 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.
- request_config(model_kwargs)[source]#
Under LongRoPE, the length the request’s table is chosen by, from
MAX_POSITION_KWARG, which a model sets inprocess_prompt(the data worker drops a client’s); without it, the short table.- Parameters:
model_kwargs (dict | None)
- Return type:
PositionReqConfig | 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: