SELD233 Spatial Implementation Guide
Purpose
This document is the implementation guide for the independent SELD233 spatial modality.
It answers four questions:
- which classes and functions were implemented for the core path
- which classes are already scaffolded and should be reused as-is
- what each interface accepts and returns
- what concrete code is still deferred outside the current scope
This guide should be read together with:
docs/spatial_encoder_plan.mddocs/seld233_spatial_scaffold.md
Fixed Constraints
- Do not modify the DCASE baseline repository.
- Do not modify the original QwenOmni main classes for this feature; use the new spatial subclasses.
- A batch must be either all mono or all FOA.
- Mono batch:
- must contain exactly one
<|AUDIO|> - must not contain
<|spatial|> - only the original audio path is active
- must contain exactly one
- FOA batch:
- must contain exactly one
<|AUDIO|> - must contain exactly one
<|spatial|> - both audio and spatial paths are active
- must contain exactly one
- Audio is clipped to
0-20s. - Sample rate is
16kHz. - Spatial token rate target is
2.5 Hz. - Full
20slimits:- max samples:
320000 - max feature frames:
1000 - max SELD frames:
200 - max spatial tokens:
50
- max samples:
Status Summary
Already scaffolded and reusable
qwen2_5_omni_spur/spatial_seld233_utils.pyqwen2_5_omni_spur/modules/seldnet233_spatial_adapter.pyqwen2_5_omni_spur/modules/spatial_token_projector.pyqwen2_5_omni_spur/processing_qwen2_5_omni_spatial.pyqwen2_5_omni_spur/modeling_qwen2_5_omni_spatial.py- config additions in
qwen2_5_omni_spur/configuration_qwen2_5_omni.py
Must still be implemented
- training script migration to the new spatial subclasses
- inference script migration to the new spatial subclasses
Explicitly deferred for now
image + spatialjoint RoPEuse_audio_in_video=Truereturn_audio=Truetalker path with spatial modality
Implementation Inventory
| Priority | File | Symbol | Current State | Required Action |
|---|---|---|---|---|
| P0 | qwen2_5_omni_spur/modules/seldnet233_feature_bridge.py |
SeldNet233FeatureBridge._extract_online_features |
implemented | no further action for the current scope |
| P0 | qwen2_5_omni_spur/modules/seldnet233_backbone.py |
SeldNet233Backbone._run_seldnet_backbone |
implemented | no further action for the current scope |
| P1 | training-qwen-omni/train_spur_spatial_only_hf.py |
main() and config wiring |
legacy | migrate only if this script is needed for training runs |
| P1 | qwen-omni-inference.py |
script body | legacy | migrate only if this script is needed for ad hoc inference |
| P2 | qwen2_5_omni_spur/modeling_qwen2_5_omni_spatial.py |
get_rope_index |
partial | only needed later if image + spatial is required |
| P2 | qwen2_5_omni_spur/modeling_qwen2_5_omni_spatial.py |
generate(return_audio=True) path |
partial | only needed if talker output is required later |
Detailed Interface Guide
1. SeldNet233FeatureBridge
File:
qwen2_5_omni_spur/modules/seldnet233_feature_bridge.py
Class:
SeldNet233FeatureBridge
Already implemented:
- constructor
- input validation
- waveform mask -> valid length conversion
- waveform length -> feature length conversion
- output mask bookkeeping
- online baseline-aligned STFT / log-mel / intensity-vector extraction
- baseline
foa_wtsnormalization
Input contract:
spatial_audio:torch.Tensor, shape[B, T_audio_max, 4]spatial_audio_lengths:torch.LongTensor, shape[B]feature_lengths:torch.LongTensor, shape[B]feature_attention_mask:torch.BoolTensor, shape[B, T_feat_max]
Output contract:
SeldNet233FeatureBridgeOutput.features:[B, 7, T_feat_max, 64]SeldNet233FeatureBridgeOutput.feature_attention_mask:[B, T_feat_max]SeldNet233FeatureBridgeOutput.feature_lengths:[B]
Required implementation content:
- Load or derive the exact task-233 feature configuration.
- Reproduce the baseline feature math for FOA:
4chlog-mel3chFOA intensity vector
- Use the task-233 normalization weights.
- Keep output frame count aligned with
feature_lengths. - Zero-fill padded tail frames only after valid frames are computed.
Recommended private helpers to add inside this file:
_load_task233_feature_config()_load_feature_stats()_compute_stft(...)_compute_logmel_channels(...)_compute_intensity_vector_channels(...)_normalize_feature_tensor(...)
Important shape transitions:
- raw FOA waveform:
[B, T_audio_max, 4] - internal channels-first view:
[B, 4, T_audio_max] - mel-like features before stacking:
[B, 4, T_feat_max, 64] - intensity-vector features:
[B, 3, T_feat_max, 64] - final baseline tensor:
[B, 7, T_feat_max, 64]
Validation checklist:
- same sample length gives same
T_featassamples_to_feature_frames - values match offline baseline extraction on the same clip
- normalization path is identical to baseline task
233
2. SeldNet233Backbone
File:
qwen2_5_omni_spur/modules/seldnet233_backbone.py
Class:
SeldNet233Backbone
Already implemented:
- constructor
- input validation
- feature length -> SELD length conversion
- output mask bookkeeping
- dynamic baseline loading
- checkpoint restore with shape-compatible filtering
- last MHSA LayerNorm hidden capture
Input contract:
seld233_features:torch.Tensor, shape[B, 7, T_feat_max, 64]seld233_feature_lengths:torch.LongTensor, shape[B]hidden_lengths:torch.LongTensor, shape[B]hidden_attention_mask:torch.BoolTensor, shape[B, T_seld_max]
Output contract:
SeldNet233BackboneOutput.hidden_states:[B, T_seld_max, 128]SeldNet233BackboneOutput.hidden_attention_mask:[B, T_seld_max]SeldNet233BackboneOutput.hidden_lengths:[B]
Required implementation content:
- Dynamically load
parameters.pyandseldnet_model.pyfrom the baseline repo path. - Build the task-233 baseline model.
- Restore the pretrained checkpoint from
seld233_checkpoint_path. - Freeze the backbone if
seld233_freeze_backbone=True. - Register a hook at the final MHSA shared representation.
- Feed the baseline-compatible features into the model.
- Return the captured hidden tensor, not accdoa heads and not sed logits.
Recommended private helpers to add inside this file:
_load_baseline_modules()_build_seld233_model()_load_checkpoint_weights()_register_hidden_hook()_prepare_baseline_input_layout(...)
Important shape transitions:
- model input for this wrapper:
[B, 7, T_feat_max, 64] - likely baseline internal flattened layout:
[B, T_feat_max, 448] - captured MHSA hidden:
[B, T_seld_max, 128]
Validation checklist:
- checkpoint path exists
- hook fires exactly once per forward
- hidden dim is exactly
128 - hidden length matches
feature_frames_to_seld_frames
3. SeldNet233SpatialAdapter
File:
qwen2_5_omni_spur/modules/seldnet233_spatial_adapter.py
Class:
SeldNet233SpatialAdapter
Status:
- already usable once feature bridge and backbone are implemented
Input modes already supported:
- raw audio path:
spatial_audio [B, T_audio_max, 4]
- offline feature path:
seld233_features [B, 7, T_feat_max, 64]
- direct hidden path:
seld233_hidden_states [B, T_seld_max, 128]
Output:
spatial_tokens [B, T_spat_max, 256]spatial_token_attention_mask [B, T_spat_max]spatial_token_lengths [B]
No new implementation is required here unless you want to change:
- downsampling rule
- token MLP architecture
- token dimension
Current downsampling rule:
T_spat = ceil(T_seld / 4)- effective rate:
10 Hz -> 2.5 Hz
4. SpatialTokenProjector
File:
qwen2_5_omni_spur/modules/spatial_token_projector.py
Class:
SpatialTokenProjector
Status:
- already implemented
Input:
spatial_tokens [B, T_spat, D_in]
Output:
- projected tokens
[B, T_spat, D_llm]
No further code is required here unless model capacity needs tuning.
5. Qwen2_5OmniSpatialProcessor
File:
qwen2_5_omni_spur/processing_qwen2_5_omni_spatial.py
Class:
Qwen2_5OmniSpatialProcessor
Status:
- implemented scaffold
- should be reused, not rewritten
Important public interfaces:
__call__(...)sync_spatial_tokenizer_with_model(model)
Input behavior:
- mono batch:
- prompt must include one
<|AUDIO|> - prompt must not include
<|spatial|>
- prompt must include one
- FOA batch:
- prompt must include one
<|AUDIO|> - prompt must include one
<|spatial|>
- prompt must include one
Output keys already supported:
input_idsinput_featuresfeature_attention_maskspatial_audiospatial_audio_attention_maskspatial_audio_lengthsspatial_tokensseld233_featuresseld233_feature_attention_maskseld233_feature_lengthsspatial_token_lengths
No core algorithm is missing here.
What still needs to happen outside this file:
- training script must actually instantiate this processor
- inference script must actually instantiate this processor
- both scripts must call
processor.sync_spatial_tokenizer_with_model(model)
6. Qwen2_5OmniSpatialThinkerForConditionalGeneration
File:
qwen2_5_omni_spur/modeling_qwen2_5_omni_spatial.py
Class:
Qwen2_5OmniSpatialThinkerForConditionalGeneration
Status:
- spatial injection path is implemented
- tokenizer sync helper is implemented
- prefill spatial routing is implemented
- video + audio + spatial RoPE is implemented for
use_audio_in_video=False
Important public interfaces:
forward(...)prepare_inputs_for_generation(...)sync_spatial_tokenizer(...)
Input contract:
- normal Qwen text/audio inputs
- optional spatial inputs:
spatial_audio [B, T_audio_max, 4]seld233_features [B, 7, T_feat_max, 64]spatial_tokens [B, T_spat_max, D_spat]- matching length or mask tensors
Output behavior:
- if no spatial input is provided, it falls back to the base thinker
- if spatial input is provided, it injects projected spatial embeddings at
<|spatial|>positions
Still missing only if scope expands later:
- true multimodal RoPE for
image + spatial - talker/audio-output path
7. Qwen2_5OmniSpatialForConditionalGeneration
File:
qwen2_5_omni_spur/modeling_qwen2_5_omni_spatial.py
Class:
Qwen2_5OmniSpatialForConditionalGeneration
Status:
- implemented scaffold
Important public interfaces:
sync_spatial_tokenizer(...)generate(...)
No core code is missing for text-only generation with audio/spatial input.
Still deferred:
return_audio=Truepath
Script-Level Work
8. Training Script
File:
training-qwen-omni/train_spur_spatial_only_hf.py
Current issue:
- it still uses the old SPUR audio-fusion line
Minimum required changes:
- Replace imports:
- old:
Qwen2_5OmniProcessorQwen2_5OmniForConditionalGeneration
- new:
Qwen2_5OmniSpatialProcessorQwen2_5OmniSpatialForConditionalGeneration
- old:
- Replace old SPUR config overrides with new
seld233_*thinker config fields. - After loading processor and model, call:
processor.sync_spatial_tokenizer_with_model(model)
- Update prompt construction:
- mono batch prompt: includes
<|AUDIO|>only - FOA batch prompt: includes
<|AUDIO|><|spatial|>
- mono batch prompt: includes
- Ensure collator preserves mono or FOA batch homogeneity.
- Ensure audio clips are clipped to
20s. - Ensure training batch uses the new processor output keys.
Functions that most likely need modification:
apply_spur_config_overrides(...)main()
9. Inference Script
File:
qwen-omni-inference.py
Current issue:
- it still uses the old processor/model path
Minimum required changes:
- Replace imports with the new spatial subclasses.
- Load FOA audio without collapsing channels.
- Build prompt with canonical tokens:
- FOA:
<|AUDIO|><|spatial|> ... - mono:
<|AUDIO|> ...
- FOA:
- Call:
processor.sync_spatial_tokenizer_with_model(model)
- Print or assert:
spatial_token_lengths- number of
<|spatial|>token positions after tokenization
- Run one prefill/generation sanity check.
There is no reusable function boundary in the current script; the top-level script body itself needs to be migrated.
Suggested Implementation Order
- Implement
SeldNet233FeatureBridge._extract_online_features. - Implement
SeldNet233Backbone._run_seldnet_backbone. - Run a direct module test:
spatial_audio -> feature bridge -> backbone -> adapter
- Migrate
training-qwen-omni/train_spur_spatial_only_hf.py. - Migrate
qwen-omni-inference.py. - Only after that, consider optional RoPE/talker extensions.
Required Checks After Each Stage
After feature bridge
- same clip gives matching online vs offline task-233 features
- feature tensor is
[B, 7, T_feat_max, 64] - feature mask matches
feature_lengths
After backbone
- checkpoint loads successfully
- captured hidden is
[B, T_seld_max, 128] - hidden length matches derived
T_seld
After end-to-end spatial adapter
spatial_tokensis[B, T_spat_max, 256]spatial_token_lengthsequalsceil(T_seld / 4)- no placeholder count mismatch
After training/inference migration
<|spatial|>is present in tokenizer vocabconfig.thinker_config.spatial_token_indexis set- thinker embedding size matches tokenizer size
- mono batch runs without spatial injection
- FOA batch runs with spatial injection
Out of Scope For The Next Coding Stage
- support mixed mono/FOA batches
- support image/video + spatial at the same time
- support talker audio generation with spatial tokens
- change the task-233 feature definition or baseline architecture