(P: MLXProgramBuilder, n: Node)
| 2179 | |
| 2180 | @REGISTRY.register(target=[torch.ops.mlx.rope.default]) |
| 2181 | def _rope_handler(P: MLXProgramBuilder, n: Node) -> Slot: |
| 2182 | args = P.args(n) |
| 2183 | require_args(args, 3, 7, "mlx.rope") |
| 2184 | require_kwargs(P.kwargs(n), set(), "mlx.rope") |
| 2185 | x, dims, pos = args[0], args[1], args[2] |
| 2186 | traditional = args[3] if len(args) > 3 else False |
| 2187 | base = args[4] if len(args) > 4 else 500000.0 |
| 2188 | scale = args[5] if len(args) > 5 else 1.0 |
| 2189 | freqs = args[6] if len(args) > 6 else None |
| 2190 | out = P.make_or_get_slot(n) |
| 2191 | |
| 2192 | # pos must be a Slot (SymInt) from input_pos.item() during tracing |
| 2193 | # The schema supports both Vid (scalar) and Tid (tensor) for offset |
| 2194 | if not isinstance(pos, Slot): |
| 2195 | raise ValueError( |
| 2196 | f"RopeNode.offset must be a SymInt (traced via tensor.item()), got {type(pos)}. " |
| 2197 | "Make sure input_pos is a tensor and you call input_pos.item() to get a SymInt." |
| 2198 | ) |
| 2199 | |
| 2200 | P.emit( |
| 2201 | RopeNode( |
| 2202 | x=P.slot_to_tid(x), |
| 2203 | out=P.slot_to_tid(out), |
| 2204 | dims=dims, |
| 2205 | offset=VidOrTid.from_vid(P.slot_to_vid(pos)), |
| 2206 | freqs=P.slot_to_tid(freqs) if freqs else None, |
| 2207 | traditional=traditional, |
| 2208 | base=base, |
| 2209 | scale=scale, |
| 2210 | ) |
| 2211 | ) |
| 2212 | |
| 2213 | return out |
| 2214 | |
| 2215 | |
| 2216 | def _emit_channel_last_weight(P: MLXProgramBuilder, w_node: Node, perm: list) -> Slot: |
nothing calls this directly
no test coverage detected