⚡️ Speed up function create_finetune_request by 15%
          #8
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
📄 15% (0.15x) speedup for
create_finetune_requestinsrc/together/resources/finetune.py⏱️ Runtime :
2.26 milliseconds→1.97 milliseconds(best of88runs)📝 Explanation and details
The optimized code achieves a 15% speedup through two key optimizations:
1. Fast-path optimization in
log_warn_once:msg_candidate) before expensivelogfmtformattinglogfmtcalls from 44 to 1, saving ~550μs per duplicate warning2. Reduced attribute lookups in
create_finetune_request:model_limits.lora_trainingandmodel_limits.full_trainingin local variables (lora_cfg,full_cfg)Performance characteristics by test case:
log_warn_onceoptimization only helps on repeated callsThe optimizations maintain identical behavior while eliminating redundant work - particularly effective for the common path of successful request creation and duplicate warning suppression.
✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
unit/test_finetune_resources.py::test_bad_max_grad_normunit/test_finetune_resources.py::test_bad_min_lr_ratiounit/test_finetune_resources.py::test_bad_training_methodunit/test_finetune_resources.py::test_bad_warmupunit/test_finetune_resources.py::test_bad_weight_decayunit/test_finetune_resources.py::test_batch_size_limitunit/test_finetune_resources.py::test_both_from_checkpoint_model_nameunit/test_finetune_resources.py::test_dpo_requestunit/test_finetune_resources.py::test_dpo_request_loraunit/test_finetune_resources.py::test_from_checkpoint_requestunit/test_finetune_resources.py::test_lora_requestunit/test_finetune_resources.py::test_lora_request_with_lora_dropoutunit/test_finetune_resources.py::test_no_from_checkpoint_no_model_nameunit/test_finetune_resources.py::test_no_training_fileunit/test_finetune_resources.py::test_non_full_modelunit/test_finetune_resources.py::test_non_lora_modelunit/test_finetune_resources.py::test_simple_requestunit/test_finetune_resources.py::test_train_on_inputs_for_sftunit/test_finetune_resources.py::test_train_on_inputs_not_supported_for_dpounit/test_finetune_resources.py::test_validation_file🌀 Generated Regression Tests and Runtime
⏪ Replay Tests and Runtime
To edit these changes
git checkout codeflash/optimize-create_finetune_request-mgzsj4q6and push.