Skip to content

exp run: python: can't open file 'src/train.py' #6465

Closed

Description

@mmeendez8

Bug Report

Description

I added a couple of experiments with different parameters to queue. I wanted to run them sequentially with dvc exp run --run-all but I got some unexpected results:

  1. I realize dvc checkout is runned automatically for each experiment. I think this is bad since I have to wait all my images and annotations were "checkout" once per experiment. I did not know why this was happening until I read this line in the source code:
    https://github.com/iterative/dvc/blob/master/dvc/command/experiments.py#L1293
    That implies --temp means that "each exp is runned in a separate temporary directory instead of your workspace". I guess this is related with parallelizing different runs... but I consider it should be possible to avoid it since it does not scale with large datasets.

  2. The error I am pointing in the issue name python: can't open file 'src/train.py' is appearing because of --temp parameters that forces to commit in both dvc and git the src/train.py so file is present later in the tmp copy (this is only my current belief, I could not confirm this yet) Everything works fine with dvc repro.

Reproduce

  1. dvc init
  2. import and add dataset
  3. create src/train.py script
  4. dvc exp run --queue
  5. dvc exp run --queue -S optimizer.lr=0.1
  6. dvc exp run --run-all

Expected

I expected that my experiment runned in sequential order without duplicating my data in another tmp directory.

Environment information

Output of dvc doctor:

$ dvc doctor

DVC version: 2.5.4 (conda)
---------------------------------
Platform: Python 3.8.10 on Linux-4.15.0-96-generic-x86_64-with-glibc2.10
Supports:
        gdrive (pydrive2 = 1.9.1),
        http (requests = 2.26.0),
        https (requests = 2.26.0)
Cache types: hardlink, symlink
Cache directory: ext4 on /dev/sdb1
Caches: local
Remotes: None
Workspace directory: ext4 on /dev/sdb1
Repo: dvc, git

Additional Information (if any):

$ dvc exp show 
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓               
┃ Experiment   ┃ Created      ┃ test_split.split ┃ optimizer.lr ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ workspace    │ -            │ -                │ -            │
│ main         │ Aug 19, 2021 │ -                │ -            │
│ ├── *098b5bc │ 01:07 PM     │ 0.1              │ 0.1          │
│ └── *6980253 │ 01:06 PM     │ -                │ -            │
└──────────────┴──────────────┴──────────────────┴──────────────┘

Activity

  1. pmrowla commented on Aug 23, 2021

    @pmrowla
    Contributor

    This is expected behavior since src/train.py is not tracked by git - from the exp run docs (https://dvc.org/doc/command-reference/exp/run#queueing-and-parallel-execution):

    ⚠️ Note that only tracked files and directories will be included in --queue/temp experiments. To include untracked files, stage them with git add first (before dvc exp run).

    As you noted, the --queue/--run-all functionality is limited right now, and only supports running experiments in their own separate tempdir workspaces. This this behavior is also documented:

    Use dvc exp run --run-all to process the queue. This is done outside your workspace (in temporary dirs in .dvc/tmp/exps) to preserve any changes between/after queueing runs.

    To run an experiment in your main repo working directory, currently you cannot use the --queue/--run-all functionality. But if you just do

    dvc exp run -S optimizer.lr=0.1
    

    it will run in your workspace the same way as dvc repro (and it will work properly even with an untracked src/train.py file).

  2. pmrowla commented on Aug 23, 2021

    @pmrowla
    Contributor

    Regarding:

    I realize dvc checkout is runned automatically for each experiment... I consider it should be possible to avoid it since it does not scale with large datasets.

    This can be mitigated depending on the link type you have configured for your cache. It sounds like DVC is copying files on checkout in your configuration which, as you noted, will be slow. But if you are able to configure DVC to use reflinks/symlinks/hardlinks (depending on your environment), the checkout step would be much faster, and is recommended when you are working with large datasets (see: https://dvc.org/doc/user-guide/large-dataset-optimization#file-link-types-for-the-dvc-cache)

  3. pmrowla commented on Aug 23, 2021

    @pmrowla
    Contributor

    Closing this as expected behavior

  4. mmeendez8 commented on Aug 24, 2021

    @mmeendez8
    ContributorAuthor

    Hi @pmrowla, sorry but I have been playing with dvc exp trying to understand what is going on and I cannot figure out what is happening.

    To run an experiment in your main repo working directory, currently you cannot use the --queue/--run-all functionality. But if you just do

    Following your suggestion I have done the following:

    $ time dvc repro
    real    1m35,137s
    user    4m42,039s
    sys     1m45,475s
    $ time dvc exp run
    Computing file/dir hashes (only done once)                     |10.0 [00:01,   9.47md5/s]
    ...
    real    10m31,892s
    user    1m22,773s
    sys     0m9,889s

    Note those large differences in time are due to that "computing file/dir hashes" step. Furthermore, if I once again run dvc exp run, even though Computing file/dir hashes (only done once) clearly says this is only done once, dvc is again hashing my files so it spends a large time before actually running my task.

    I might be missing something but I really cannot understand what is going on here and I would appretiate any orientation with this. Thanks!

  5. pmrowla commented on Aug 25, 2021

    @pmrowla
    Contributor

    It's hard to tell what's going on just from that. I wouldn't expect DVC to be recomputing hashes on exp run in this case, so it's possible there's a separate bug/issue there, but without more information I can't really say what might be causing it.

    If you just run dvc checkout in your usual workspace, what happens?

  6. mmeendez8 commented on Aug 25, 2021

    @mmeendez8
    ContributorAuthor

    dvc checkout needs one second to finish.

    $ time dvc checkout                                                                                                                                                                                                                                       
    real    0m1,451s
    user    0m1,033s
    sys     0m0,342s

    If I run dvc exp run aftewards, it agains shows:

    Cloning..........
    Computing file/dir hashes (only done once)
    

    This cloning step and the hashing that happens inmediately after it seems to contradict what you said before:

    To run an experiment in your main repo working directory, currently you cannot use the --queue/--run-all functionality. But if you just do

    dvc exp run -S optimizer.lr=0.1
    

    it will run in your workspace the same way as dvc repro (and it will work properly even with an untracked src/train.py file).

  7. daavoo commented on Aug 25, 2021

    @daavoo
    Contributor

    This might be related: #6490

  8. mmeendez8 commented on Aug 25, 2021

    @mmeendez8
    ContributorAuthor

    Oh, yes that might be definetely related. I forgot to mention that I used dvc import for attaching my data. I didn't think it was relevant 🙃

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions