Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Trial APIs --local should respect .detignore. [MLG-1352] #8683

Merged
merged 4 commits into from
Jan 12, 2024

Conversation

ioga
Copy link
Contributor

@ioga ioga commented Jan 11, 2024

Description

When trial APIs in --local mode are making checkpoints, they should respect .detignore similar to the usual context directory creation.

Test Plan

  • Added a unit test.
  • Per original OSS complaint, make a directory with some root-only files which are ignored by detignore, and then try a --local run.

For example,

  • det e create ... --local -test— initial state, works ok
  • touch root.txt
  • sudo chown root root.txt
  • sudo chmod 400 root.txt
  • det e create ... --local -test — will fail because of a permission error
  • echo root.txt >> .detignore
  • det e create ... --local -test — now works ok

Commentary (optional)

Checklist

  • Changes have been manually QA'd
  • User-facing API changes need the "User-facing API Change" label.
  • Release notes should be added as a separate file under docs/release-notes/.
    See Release Note for details.
  • Licenses should be included for new code which was copied and/or modified from any external code.

Ticket

@ioga ioga requested a review from a team as a code owner January 11, 2024 21:16
@cla-bot cla-bot bot added the cla-signed label Jan 11, 2024
Copy link

netlify bot commented Jan 11, 2024

Deploy Preview for determined-ui canceled.

Name Link
🔨 Latest commit 35413d7
🔍 Latest deploy log https://app.netlify.com/sites/determined-ui/deploys/65a1a058dc521b0008533d8c

Copy link

codecov bot commented Jan 11, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (38e6825) 51.46% compared to head (35413d7) 51.48%.
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8683      +/-   ##
==========================================
+ Coverage   51.46%   51.48%   +0.01%     
==========================================
  Files         884      886       +2     
  Lines      156121   156170      +49     
  Branches     2088     2088              
==========================================
+ Hits        80352    80397      +45     
- Misses      74282    74286       +4     
  Partials     1487     1487              
Flag Coverage Δ
backend 36.14% <ø> (-0.01%) ⬇️
harness 64.29% <95.83%> (+0.04%) ⬆️
web 53.76% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
harness/determined/common/context.py 91.52% <100.00%> (-1.27%) ⬇️
harness/determined/common/v1file_utils.py 100.00% <100.00%> (ø)
harness/tests/filetree.py 93.54% <100.00%> (+2.63%) ⬆️
harness/tests/test_imports.py 97.95% <100.00%> (-0.23%) ⬇️
harness/tests/test_util.py 100.00% <100.00%> (ø)
harness/determined/util.py 73.75% <75.00%> (-0.17%) ⬇️
harness/determined/common/detignore.py 93.10% <93.10%> (ø)

... and 6 files with indirect coverage changes

@ioga ioga changed the title fix: Trial APIs --local should respect .detignore. [DET-1352] fix: Trial APIs --local should respect .detignore. [MLG-1352] Jan 11, 2024
Comment on lines 54 to 56
# We could use pathlib.Path.rglob for scanning the directory;
# however, the Python documentation claims a warning that rglob may be
# inefficient on large directory trees, so we use the older os.walk().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is ancient, but actually I think the fact that we skip directories is a much better reason to us os.walk.

I recommend just deleting the comment.

if on_cluster:
model_dir = constants.MANAGED_TRAINING_MODEL_COPY
ignore_func = shutil.ignore_patterns("__pycache__")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line.

When we are on-cluster, we get the model definition from a special clean copy of the model definition, which can't have __pycache__ because __pycache__ is part of DEFAULT_DETIGNORE.

This line of code traces back to f14f769 where the src arg to copytree() was os.getcwd(). I don't think it's relevant anymore, and I think it's safe to delete.

try:
entry = v1file_utils.v1File_from_local_file(entry_path, file_path)
except OSError:
print(f"Error reading '{entry_path}', skipping this file.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you set file=sys.stderr on this print statement?

Comment on lines +36 to +41
file_path = pathlib.Path(path) / name
file_rel_path = file_path.relative_to(root_path)

if (
file_path.is_dir() and ignore_spec.match_file(str(file_rel_path) + "/")
) or ignore_spec.match_file(str(file_rel_path)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why bounce back and forth between pathlib.Path and str? Why not just use os.path.join() and os.path.relpath()?

non-blocking; feel free to ignore my inner C programmer which cringes at unnecessary malloc() calls.

Copy link
Member

@rb-determined-ai rb-determined-ai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thank you for refactoring it first.

@ioga ioga merged commit 130ebb7 into main Jan 12, 2024
74 of 85 checks passed
@ioga ioga deleted the detignore-local branch January 12, 2024 22:04
@dannysauer dannysauer modified the milestone: 0.27.1 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants