Skip to content

fix: normalize path separators for cross-platform model loading#818

Open
TheChyeahhh wants to merge 1 commit into
mljar:masterfrom
TheChyeahhh:fix/path-normalization
Open

fix: normalize path separators for cross-platform model loading#818
TheChyeahhh wants to merge 1 commit into
mljar:masterfrom
TheChyeahhh:fix/path-normalization

Conversation

@TheChyeahhh

Copy link
Copy Markdown

Summary

When a model is trained on Windows and loaded on Linux, learner_subpath paths contain backslash separators. On Linux, os.path.join does not normalize backslashes, producing malformed paths like:

experiments_dir/model_1/100_LightGBM\\learner_fold_0.lightgbm

This causes model loading to fail.

Changes

Added os.path.normpath() call to normalize path separators in learner_subpath before joining with results_path in the load method. This handles both directions:

  • Windows → Linux: backslashes converted to forward slashes
  • Linux → Windows: forward slashes converted to backslashes

Test Plan

  • Train a model on Windows, copy to Linux, verify it loads
  • Train a model on Linux, copy to Windows, verify it loads

Closes #541

When a model is trained on Windows, learner_subpath paths contain
backslash separators. On Linux, os.path.join does not normalize
backslashes, causing malformed paths like:
  'model_1/100_LightGBM\learner_fold_0.lightgbm'

Add os.path.normpath() to normalize path separators before joining,
handling both Windows-to-Linux and Linux-to-Windows transfers.

Fixes mljar#541
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Path normalization (train on Windows and deploy on Linux)

1 participant