File size: 6,138 Bytes
0fc11f4
1
2
{"domain":"com.microsoft","name":"MRotaryEmbedding","sinceVersion":1,"inputs":{"x":{"onnx":"input","dtype":"T"},"positionIds":{"onnx":"position_ids","dtype":"M","rank":3,"storage":"int32","narrowing":"saturating"},"cos":{"onnx":"cos_cache","dtype":"T","rank":2},"sin":{"onnx":"sin_cache","dtype":"T","rank":2}},"outputs":{"y":{"onnx":"output","dtype":"T","rank":"ranks.x","shape":"shapes.x"}},"attributes":{"interleaved":{"default":0},"is_packed_batching":{"default":0},"mrope_layout":{"default":0},"num_heads":{"default":0},"rotary_embedding_dim":{"default":0},"scale":{"default":1},"mrope_section":{}},"attributeConstraints":{"interleaved":{"values":[0,1]},"is_packed_batching":{"values":[0]},"mrope_layout":{"values":[0,1]},"mrope_section":{"required":true}},"typeConstraints":{"T":["float32","float16"],"M":["int64"]},"tunables":{"WORKGROUP_SIZE":{"default":256}},"derive":{"rank3HeadSize":"dim(shapes.x, 2) / attrs.num_heads if attrs.num_heads is defined and attrs.num_heads > 0 else 0","headSize":"rank3HeadSize if ranks.x == 3 else dim(shapes.x, 3)","effectiveRotaryDim":"attrs.rotary_embedding_dim if attrs.rotary_embedding_dim != 0 else headSize","tasksPerHead":"ceilDiv(headSize, 2)","pairCount":"(numel(shapes.x) / max(1, headSize)) * tasksPerHead","pairDispatchOk":"ceilDiv(pairCount, tunables.WORKGROUP_SIZE) <= min(device.limits.maxComputeWorkgroupsPerDimension, 65535) * min(device.limits.maxComputeWorkgroupsPerDimension, 65535)","halfRotaryDim":"dim(shapes.cos, 1)","sectionsDefined":"attrs.mrope_section is defined and (attrs.mrope_section | length) == 3","sectionsValid":"sectionsDefined and attrs.mrope_section[0] >= 0 and attrs.mrope_section[1] >= 0 and attrs.mrope_section[2] >= 0 and attrs.mrope_section[0] + attrs.mrope_section[1] + attrs.mrope_section[2] == halfRotaryDim","commonContract":"f16Ok(dtypes.T) and sameShape(shapes.x, shapes.y) and (attrs.interleaved == 0 or attrs.interleaved == 1) and (attrs.mrope_layout == 0 or attrs.mrope_layout == 1) and attrs.num_heads >= 0 and attrs.rotary_embedding_dim >= 0 and (attrs.rotary_embedding_dim == 0 or attrs.num_heads > 0) and sameShape(shapes.cos, shapes.sin) and ranks.cos == 2 and ranks.sin == 2 and sectionsValid and ranks.positionIds == 3 and dim(shapes.positionIds, 0) == 3 and dim(shapes.positionIds, 1) == dim(shapes.x, 0) and dim(shapes.positionIds, 2) == dim(shapes.x, 1 if ranks.x == 3 else 2)","rank3Contract":"commonContract and ranks.x == 3 and ranks.y == 3 and attrs.num_heads is defined and attrs.num_heads >= 1 and dim(shapes.x, 2) % attrs.num_heads == 0 and (rank3HeadSize > 0 or numel(shapes.x) == 0) and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= rank3HeadSize) and halfRotaryDim * 2 == effectiveRotaryDim","rank4Contract":"commonContract and ranks.x == 4 and ranks.y == 4 and dim(shapes.x, 3) > 0 and effectiveRotaryDim % 2 == 0 and (attrs.rotary_embedding_dim == 0 or attrs.rotary_embedding_dim <= dim(shapes.x, 3)) and halfRotaryDim * 2 == effectiveRotaryDim"},"when":["pairDispatchOk","rank3Contract or rank4Contract"],"bindings":{"x":{"elementType":"$T"},"position_ids":{"arg":"positionIds","elementType":"i32"},"cos_cache":{"arg":"cos","elementType":"$T"},"sin_cache":{"arg":"sin","elementType":"$T"},"y":{"elementType":"$T"},"params":{"struct":[{"name":"pairCount","type":"u32","value":"pairCount"},{"name":"batchSize","type":"u32","value":"dim(shapes.x, 0)"},{"name":"sequenceLength","type":"u32","value":"dim(shapes.x, 1 if ranks.x == 3 else 2)"},{"name":"numHeads","type":"u32","value":"attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)"},{"name":"headSize","type":"u32","value":"headSize"},{"name":"rotaryDim","type":"u32","value":"halfRotaryDim * 2"},{"name":"halfRotaryDim","type":"u32","value":"halfRotaryDim"},{"name":"section0","type":"u32","value":"attrs.mrope_section[0]"},{"name":"section1","type":"u32","value":"attrs.mrope_section[1]"},{"name":"section2","type":"u32","value":"attrs.mrope_section[2]"},{"name":"scale","type":"f32","value":"attrs.scale"},{"name":"maxSequenceLength","type":"u32","value":"dim(shapes.cos, 0)"}]},"x_vector":{"arg":"x","name":"x","elementType":"$vectorScalar"},"y_vector":{"arg":"y","name":"y","elementType":"$vectorScalar"},"params_vector":{"struct":[{"name":"pairCount","type":"u32","value":"pairCount"},{"name":"batchSize","type":"u32","value":"dim(shapes.x, 0)"},{"name":"sequenceLength","type":"u32","value":"dim(shapes.x, 1 if ranks.x == 3 else 2)"},{"name":"numHeads","type":"u32","value":"attrs.num_heads if ranks.x == 3 else dim(shapes.x, 1)"},{"name":"headSize","type":"u32","value":"headSize"},{"name":"halfRotaryDim","type":"u32","value":"halfRotaryDim"},{"name":"section0","type":"u32","value":"attrs.mrope_section[0]"},{"name":"section1","type":"u32","value":"attrs.mrope_section[1]"},{"name":"section2","type":"u32","value":"attrs.mrope_section[2]"},{"name":"scale","type":"f32","value":"attrs.scale"},{"name":"maxSequenceLength","type":"u32","value":"dim(shapes.cos, 0)"}],"name":"params"}},"variants":[{"id":"pairs4","when":["headSize % 8 == 0","effectiveRotaryDim == headSize","attrs.interleaved == 0"],"derive":{"mropeSectioned":"attrs.mrope_layout == 0","pairWidth":"4","vectorScalar":"\"vec4<\" ~ dtypes.T ~ \">\"","scalar":"dtypes.T"},"passes":[{"id":"main","name":"MRotaryEmbedding.Vector","shader":"mrotary-embedding-vector.wgsl.jinja","derive":{"rank":"ranks.x"},"bindings":["x_vector","position_ids","cos_cache","sin_cache","y_vector","params_vector"],"dispatch":{"x":"min(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((pairCount / 4), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}],"priority":10},{"id":"pairs","derive":{"interleaved":"attrs.interleaved != 0","mropeSectioned":"attrs.mrope_layout == 0","scalar":"dtypes.T"},"passes":[{"id":"main","name":"MRotaryEmbedding","shader":"mrotary-embedding.wgsl.jinja","derive":{"rank":"ranks.x"},"bindings":["x","position_ids","cos_cache","sin_cache","y","params"],"dispatch":{"x":"min(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)","y":"ceilDiv(ceilDiv((pairCount), (tunables.WORKGROUP_SIZE)), 65535)","z":1}}]}]}