Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU] Add native LTX-Video RoPE kernel and enable the fusion (#37141)

Aditya Goyal64e3ba32b0cd
diff --git a/src/plugins/intel_cpu/src/nodes/rope.cpp b/src/plugins/intel_cpu/src/nodes/rope.cpp
index 688f1bceacd..d41d72f446c 100644
--- a/src/plugins/intel_cpu/src/nodes/rope.cpp
+++ b/src/plugins/intel_cpu/src/nodes/rope.cpp
@@ -244,6 +244,46 @@ struct RoPE::RoPEExecutorInterleaved : public RoPE::Executor {
}
};
+// LTX-Video 3D spatial-temporal RoPE: x [batch, seq, rotary_ndims] with separate full-width cos/sin
+// tables. Interleaved complex pairs; each element keeps its own cos/sin (the two halves of a pair
+// need not share an angle). Accumulated in f32 (cos/sin ports are f32) and rounded once on store,
+// so bf16 stays as precise as PyTorch.
+template <typename T>
+struct RoPE::RoPEExecutorLtxVideo : public RoPE::Executor {
+ const op::internal::RoPE::Config& m_config;
+
+ explicit RoPEExecutorLtxVideo(const op::internal::RoPE::Config& config) : m_config(config) {}
+
+ void execute([[maybe_unused]] const dnnl::stream& strm,
+ const std::vector<MemoryPtr>& inputs,
+ const std::vector<MemoryPtr>& outputs,
+ const CpuParallelPtr& cpu_parallel) override {
+ ov::intel_cpu::PlainTensor t_src(inputs[0]);
+ ov::intel_cpu::PlainTensor t_cos(inputs[1]);
+ ov::intel_cpu::PlainTensor t_sin(inputs[2]);
+ ov::intel_cpu::PlainTensor t_dst(outputs[0]);
+
+ auto batch_size = t_src.size(0);
+ auto seq_len = t_src.size(1);
+ auto rotary_dims = m_config.rotary_ndims;
+
+ cpu_parallel->parallel_for2d(batch_size, seq_len, [&](size_t b, size_t p) {
+ auto* x = t_src.ptr<T>(b, p);
+ // allow_broadcast handles size-1 cos/sin batch/seq natively
+ const float* cos = &t_cos.at<float>({b, p, 0}, true);
+ const float* sin = &t_sin.at<float>({b, p, 0}, true);
+ auto* dst = t_dst.ptr<T>(b, p);
+
+ for (size_t r = 0; r < rotary_dims; r += 2) {
+ auto real = static_cast<float>(x[r]);
+ auto imag = static_cast<float>(x[r + 1]);
+ dst[r] = static_cast<T>(cos[r] * real - sin[r] * imag);
+ dst[r + 1] = static_cast<T>(sin[r + 1] * real + cos[r + 1] * imag);
+ }
+ });
+ }
+};
+
template <typename T>
struct RoPE::RoPEExecutorChatGLM : public RoPE::Executor {
const op::internal::RoPE::Config& m_config;
@@ -470,6 +510,17 @@ void RoPE::initSupportedPrimitiveDescriptors() {
m_executor = std::make_shared<RoPEExecutorChatGLM<float>>(m_config);
rtPrecision = ov::element::f32;
}
+ } else if (m_config.is_ltx_video) {
+ CPU_NODE_ASSERT(m_config.rotary_ndims % 2 == 0, "rotary_ndims must be even for LTX RoPE");
+ // LTX sets both is_interleaved and is_ltx_video, so this must be checked first
+ if (rtPrecision == ov::element::f16) {
+ m_executor = std::make_shared<RoPEExecutorLtxVideo<ov::float16>>(m_config);
+ } else if (rtPrecision == ov::element::bf16) {
+ m_executor = std::make_shared<RoPEExecutorLtxVideo<ov::bfloat16>>(m_config);
+ } else {
+ m_executor = std::make_shared<RoPEExecutorLtxVideo<float>>(m_config);
+ rtPrecision = ov::element::f32;
+ }
} else if (m_config.is_interleaved) {
CPU_NODE_ASSERT(m_config.slice_start == 0, "slice_start must be 0 for interleaved mode");
CPU_NODE_ASSERT(m_config.slice_stop == 0, "slice_stop must be 0 for interleaved mode");
diff --git a/src/plugins/intel_cpu/src/nodes/rope.h b/src/plugins/intel_cpu/src/nodes/rope.h
index c8115b41465..051933819a3 100644
--- a/src/plugins/intel_cpu/src/nodes/rope.h
+++ b/src/plugins/intel_cpu/src/nodes/rope.h
@@ -49,6 +49,8 @@ private:
template <typename T>
struct RoPEExecutorInterleaved;
template <typename T>
+ struct RoPEExecutorLtxVideo;
+ template <typename T>
struct RoPEExecutorChatGLM;
template <typename T>
struct RoPEExecutorQwen;
diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
index a8899d8a635..3d0275a98c6 100644
--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp
@@ -1139,7 +1139,6 @@ void Transformations::PostLpt() {
CPU_REGISTER_PASS_X64(postLPTPassManager, ov::pass::RoPEFusion, true);
CPU_REGISTER_PASS_ARM64(postLPTPassManager, ov::pass::RoPEFusion, true);
CPU_DISABLE_PASS_COMMON(postLPTPassManager, ov::pass::RoPEFusionFlux);
- CPU_DISABLE_PASS_COMMON(postLPTPassManager, ov::pass::RoPEFusionLtxVideo);
CPU_REGISTER_PASS_X64(postLPTPassManager, CausalMaskPreprocessFusion);
#if defined(OPENVINO_ARCH_X86_64)
diff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp
index a87d809b286..ea0e20f4a1e 100644
--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp
+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/subgraph_tests/rotary_pos_emb.cpp
@@ -93,5 +93,11 @@ INSTANTIATE_TEST_SUITE_P(smoke_RoPETestGPTOSS,
::testing::Values(ov::test::utils::DEVICE_CPU)),
RoPETestGPTOSS::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(smoke_RoPETestLtxVideo,
+ RoPETestLtxVideo,
+ ::testing::Combine(::testing::Values(ov::element::f32),
+ ::testing::Values(ov::test::utils::DEVICE_CPU)),
+ RoPETestLtxVideo::getTestCaseName);
+
} // namespace test
} // namespace ov