skills/skillxiv-v0.0.2-claude-opus-4.6/beyond-real-imaginary-rope/SKILL.md
Improve long-context performance by incorporating imaginary components discarded in standard RoPE implementations. Use phase information from complex-valued attention for richer positional encoding—especially valuable as context length increases beyond normal ranges.
npx skillsauth add ADu2021/skillXiv beyond-real-imaginary-ropeInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Standard RoPE implementations discard the imaginary component of complex-valued dot products during attention calculations. This work leverages that discarded phase information to create improved position encodings, capturing additional positional details essential for modeling long-range dependencies in language models.
Dual-component attention leveraging complex-valued representations:
# Imaginary extension of RoPE
class ExtendedRotaryEmbedding:
def __init__(self, dim, max_seq_len=2048, base=10000.0):
self.dim = dim
self.max_seq_len = max_seq_len
self.base = base
def compute_frequencies(self):
"""
Compute frequency components for rotation matrices.
Uses exponential scaling for long-context handling.
"""
# Frequency scaling for each dimension
inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
return inv_freq
def apply_rope(self, x, seq_positions):
"""
Apply rotary embeddings with both real and imaginary components.
Preserves phase information discarded in standard RoPE.
"""
batch_size, seq_len, dim = x.shape
inv_freq = self.compute_frequencies()
# Compute position-dependent rotation angles
# t is position index, dimension-specific frequency inv_freq[i]
angles = torch.einsum('i, j -> ij', seq_positions, inv_freq)
# Create complex rotation matrices
# Standard RoPE uses: cos(angles) - i*sin(angles)
real_part = torch.cos(angles)
imag_part = torch.sin(angles)
# Create complex representation
complex_rotation = torch.complex(real_part, imag_part)
# Apply to input (treating as complex values)
# Split input into real and imaginary parts
x_real = x[..., :dim//2]
x_imag = x[..., dim//2:]
x_complex = torch.complex(x_real, x_imag)
# Multiply: (a+bi)(cos+i*sin) preserves phase information
rotated_complex = x_complex * complex_rotation.unsqueeze(0)
# Extract both components - don't discard imaginary!
output = torch.cat([
rotated_complex.real,
rotated_complex.imag
], dim=-1)
return output
def compute_dual_component_attention(self, q, k, v):
"""
Dual-component attention using both real and imaginary parts.
Captures phase information for enhanced positional awareness.
"""
# Apply rotary embeddings preserving imaginary component
q_rotated = self.apply_rope(q, positions=torch.arange(q.shape[1]))
k_rotated = self.apply_rope(k, positions=torch.arange(k.shape[1]))
# Compute attention with full complex representation
# Standard attention: (Q @ K^T) / sqrt(d)
# Enhanced: uses both magnitude and phase of Q @ K^T
attention_scores = torch.einsum('bqd, bkd -> bqk', q_rotated, k_rotated)
attention_scores = attention_scores / math.sqrt(q.shape[-1])
# Softmax along sequence dimension
attention_weights = torch.softmax(attention_scores, dim=-1)
# Apply to values
output = torch.einsum('bqk, bkd -> bqd', attention_weights, v)
return output
The approach reconstructs complete complex-valued attention, theoretically providing richer positional encoding for extended sequences.
testing
Uses flow maps as look-ahead operators to enable principled reward-guided diffusion by predicting trajectory endpoints at any denoising step. Deploy when applying rewards or preferences to diffusion trajectories with meaningful gradients throughout generation.
testing
Train language models where each expert learns independently on closed datasets, enabling flexible inference with selective data inclusion or exclusion. 41% performance improvement while allowing users to opt out of specific data sources without retraining.
data-ai
Understand how token generation flexibility in diffusion LMs paradoxically constrains reasoning, as models exploit ordering flexibility to avoid uncertain tokens, and apply simplified approaches that preserve parallel decoding benefits. Use when optimizing diffusion-based language models for reasoning tasks.
devops
Enable LLM agents to improve continuously during deployment by constructing structured experience libraries through self-reflection on successes and failures—achieving 23% improvement on reasoning without gradient-based parameter updates or external training.