The preprocessing.py script provides a complete automated pipeline for processing OpGuard callsite data from multiple sources into instrumentation configurations.
The preprocessing pipeline performs the following steps:
-
File Discovery & Combination: Handles both individual JSON files and wildcard patterns (e.g.,
fsdp_callsite_rank*.json), combining multiple files into single traces where needed. -
Compression: Uses
compress_callsite.pyto intelligently compress the combined traces by pruning linear chains and small subtrees, creating compressed versions with_compressed.jsonsuffix. -
Instrumentation Generation: Converts compressed callsite data into instrumentation YAML configurations with
_instrumentation.yamlsuffix. -
Configuration Comparison: If multiple inputs exist, compares configurations between the first entry and others, saving results to log files.
-
Configuration Combination: Uses
combine_configs.pywith a folding approach to combine multiple instrumentation configs: (1+2)+3, then ((1+2)+3)+4, etc. -
Basic Filtering (optional): Applies intelligent filtering to remove common torch utility functions and keep only meaningful function/method entries.
# Process specific files
python3 opguard/preprocessing.py --input fsdp_callsite.json gpt_callsite.json
# Process wildcard patterns
python3 opguard/preprocessing.py --input "fsdp_callsite_rank*.json" "gpt_callsite_rank*.json"
# Process mixed files and patterns
python3 opguard/preprocessing.py --input fsdp_callsite.json "gpt_callsite_rank*.json"# Specify base directory for relative paths
python3 opguard/preprocessing.py --input "*.json" --base-dir /path/to/code
# Enable verbose logging
python3 opguard/preprocessing.py --input "*.json" --verbose
# Apply basic filtering to final output
python3 opguard/preprocessing.py --input "*.json" --basicThe script handles two types of inputs:
- Individual JSON files (e.g.,
fsdp_callsite.json) - Copied directly to work directory with
_combined.jsonsuffix
- Patterns like
fsdp_callsite_rank*.jsonorgpt_callsite_rank*.json - Automatically finds matching files and combines them using
combine_callsites.py - Useful for distributed training traces from multiple ranks
Each preprocessing run creates a unique timestamped directory under the trace output directory:
{et_trace_output_dir}/preprocessing_{YYYYMMDD_HHMMSS}/
├── {name}_combined.json # Combined callsite data
├── {name}_compressed.json # Compressed version (no callstacks)
├── {name}_instrumentation.yaml # Generated instrumentation config
├── comparison_1_vs_2.log # Comparison logs (if multiple inputs)
├── comparison_1_vs_3.log # Additional comparisons
├── temp_combined_1.yaml # Temporary combination files
├── temp_combined_2.yaml
├── final_combined_instrumentation.yaml # Final combined config
├── {name}_filtered_instrumentation.yaml # Filtered output (if --basic used)
└── pipeline_summary.json # Complete pipeline summary
- Single files are copied directly
- Wildcard patterns trigger
combine_callsites.pyto merge multiple files - Each entry gets a
_combined.jsonfile
- Uses
compress_callsite.pywith intelligent pruning - Enables leaf pruning to compress linear chains
- Applies subtree pruning with configurable thresholds
- Creates
_compressed.jsonfiles with optimized structure
- Runs
callsite_to_instrumentation.pyon each compressed file - Generates YAML configurations with proper context and tags
- Outputs
_instrumentation.yamlfiles
- Compares first config against all others
- Uses
compare_configs.pyto generate detailed diffs - Saves comparison results to log files
- Uses
combine_configs.pywith folding approach: (1+2)+3, then ((1+2)+3)+4 - Intelligently merges matching entries and combines ops/stream_counts
- Produces final combined configuration
- Applies
filter_config.pywith--basicflag if requested - Removes common torch utility functions (cat, stack, reshape, etc.)
- Keeps only meaningful function/method entries
- Creates filtered output as the final result
--base-dir: Base directory for preprocessing paths (defaults to the current working directory)OPGUARD_TRACE_OUTPUT_BASE: Override for trace output directory
The script requires the following OpGuard modules:
_running.py: For trace output directory managementcallsite_tracer/combine_callsites.py: For merging multiple filescallsite_to_instrumentation.py: For generating instrumentation configscallsite_tracer/compare_configs.py: For comparing configurationscallsite_tracer/combine_configs.py: For combining instrumentation configscallsite_tracer/filter_config.py: For applying basic filtering
- Comprehensive logging at each step
- Graceful handling of missing files or failed operations
- Detailed error messages and stack traces
- Pipeline continues where possible, with clear failure points
python3 opguard/preprocessing.py --input my_trace.jsonCreates: my_trace_combined.json → my_trace_compressed.json → my_trace_instrumentation.yaml
python3 opguard/preprocessing.py --input "fsdp_callsite_rank*.json"Finds all matching rank files, combines them, then processes through the pipeline.
python3 opguard/preprocessing.py --input fsdp_callsite.json "gpt_callsite_rank*.json"Processes both a single FSDP trace and multiple GPT rank traces, comparing and combining the results.
- No files found: Check wildcard patterns and file existence
- Permission errors: Ensure write access to output directories
- Import errors: Verify OpGuard package structure and dependencies
- Memory issues: Large traces may require significant memory for processing
Use --verbose flag for detailed logging and subprocess output capture.
Check the generated log files in the work directory for detailed operation information and any error messages.