Skip to content

Make sure TensorFlow also works on offline machines - #275

Merged
casparvl merged 26 commits into
EESSI:mainfrom
laraPPr:TensorFlow_offline
Nov 6, 2025
Merged

casparvl merged 26 commits into
EESSI:mainfrom
laraPPr:TensorFlow_offline

Conversation

@laraPPr

@laraPPr laraPPr commented Jul 10, 2025 •

Copy link
Copy Markdown
Collaborator

@laraPPr
laraPPr marked this pull request as draft July 10, 2025 14:04
laraPPr added 2 commits July 14, 2025 11:06
Signed-off-by: laraPPr <[email protected]>
@laraPPr laraPPr changed the title [WIP] Make sure TensorFlow also works on offline machines Make sure TensorFlow also works on offline machines Jul 14, 2025
@laraPPr
laraPPr marked this pull request as ready for review July 14, 2025 09:51
@smoors

smoors commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator

@laraPPr why not first download the dataset in a local test, i.e. not on the compute nodes but on the node where reframe is launched?
the only requirement is that this node has internet access, which is usually the case, as most people will launch reframe on a login node.
an added benefit is that the dataset is download only once for all the concrete test cases.

running a test locally should be doable with the local parameter, see:
https://reframe-hpc.readthedocs.io/en/stable/regression_test_api.html#reframe.core.pipeline.RegressionTest.local

@laraPPr

laraPPr commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

Mare Nostrum does not have login nodes with internet access. Which is a real pita.

@laraPPr

laraPPr commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

And tensorflow redowloads everytime even when it is cashed.

@smoors

smoors commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator

And tensorflow redowloads everytime even when it is cashed.

did you try adding the path parameter to tf.keras.datasets.mnist.load_data?

@laraPPr

laraPPr commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

And tensorflow redowloads everytime even when it is cashed.

did you try adding the path parameter to tf.keras.datasets.mnist.load_data?

No I did not try that. Will try it after the meeting.

@laraPPr

laraPPr commented Jul 31, 2025

Copy link
Copy Markdown
Collaborator Author

I think we need to update that CI because it is not testing the TensorFlow tests not sure why Tests for EESSI test suite, using EESSI production repo / test_with_eessi_pilot (2023.06)

@laraPPr
laraPPr marked this pull request as draft August 14, 2025 10:42
@laraPPr

laraPPr commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator Author

Converted to draft because I've now switched the other prs to use features instead of extras

@laraPPr
laraPPr marked this pull request as ready for review August 14, 2025 10:55
if 'offline' in self.current_partition.features:
resourcesdir = self.current_system.resourcesdir
data = os.path.join(resourcesdir, self.module_name, 'datasets/mnist.npz')
if os.path.exists(data):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

See if we can move this check to the after_init state. If so, and if this path does not exist, add -offline to the valid_systems.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've now split the funtion up in two. The first runs after init to check if the data is their and will set the necessary environment variable if it is. If not valid_systems gets edited with the new hook from #279. The other function is still required to run after setup because we need self.current_partition.features.

@casparvl casparvl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added

FEATURES.OFFLINE,

to our local config. Then, the test got skipped. From the logs:

[2025-10-23T21:45:07] debug: reframe: [check_files_for_offline_run]: Warning: will exclude TensorFlow/2.13.0-foss-2023a tests on offline partitions.
Because reframe could not find ./TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz.
You can download the file running tf.keras.datasets.mnist.load_data() with TensorFlow/2.13.0-foss-2023a on a system with internet access.

Then, I downloaded the dataset. Since I don't set a resourcesdir explicitly in my ReFrame config, it's using the current directory as default. Unfortunately, in load_data(path=...) the path is relative to the .keras/datasets folder according to the documentation https://www.tensorflow.org/api_docs/python/tf/keras/datasets/mnist/load_data#args. Fortunately, a full path is respected, so I could download it using:

mkdir -p TensorFlow/2.13.0-foss-2023a/datasets
python -c "import tensorflow as tf; tf.keras.datasets.mnist.load_data(path='/home/casparl/EESSI/test-suite/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz')"

Note the mkdir -p: the directory needs to exist, otherwise you get a FileNotFoundError.

I think we should improve the instruction so that it prints these exact commands. ReFrame knows what it's own resourcesdir is, we can print that as part of the path.

Now the bad news: rerunning still gives me:

debug: reframe: [check_files_for_offline_run]: Warning: will exclude TensorFlow/2.13.0-foss-2023a tests on offline partitions.
Because reframe could not find ./TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz.
You can download the file running tf.keras.datasets.mnist.load_data() with TensorFlow/2.13.0-foss-2023a on a system with internet access.

Reason is that the current working dir for a test is the location of the test file:

[2025-10-23T22:13:16] debug: reframe: [check_files_for_offline_run]: Current working dir: /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow
[2025-10-23T22:13:16] debug: reframe: [check_files_for_offline_run]: Warning: will exclude TensorFlow/2.13.0-foss-2023a tests on offline partitions.

That's another reason why it's useful if it gets printed from the test itself: if the resourcesdir is ., it can use os.getcwd() instead.

…e warning visible on stdout, not just in the log - because there it is too hidden. Finally, make sure to _only_ print the warning if there is _at least_ one offline partition
@casparvl

Copy link
Copy Markdown
Collaborator

After 1019f21 I now ran again and got:

WARNING: Will exclude EESSI_TensorFlow %scale=16_nodes %module_name=TensorFlow/2.13.0-foss-2023a %device_type=gpu tests on offline partitions.
Because reframe could not find /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz.
The download the data, please run:.
mkdir -p /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets && module load TensorFlow/2.13.0-foss-2023a && python -c "import tensorflow as tf; tf.keras.datasets.mnist.load_data('/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz')"
on a system with internet access.

Then, I copy-pasted the instructions:

(eessi_test_venv) [casparl@int6 test-suite]$ mkdir -p /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets && module load TensorFlow/2.13.0-foss-2023a && python -c "import tensorflow as tf; tf.keras.datasets.mnist.load_data('/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz')"
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11490434/11490434 [==============================] - 1s 0us/step

and ran again:

(eessi_test_venv) [casparl@int6 test-suite]$ reframe -c eessi/testsuite/tests/apps/tensorflow/ -t 1_node -t CI --run --system snellius:rome
...
[ RUN      ] EESSI_TensorFlow %scale=1_node %module_name=TensorFlow/2.13.0-foss-2023a %device_type=cpu /9864d0f5 @snellius:rome+default
[       OK ] (1/1) EESSI_TensorFlow %scale=1_node %module_name=TensorFlow/2.13.0-foss-2023a %device_type=cpu /9864d0f5 @snellius:rome+default
P: perf: 59760.135314296705 img/s (r:0, l:None, u:None)

I also checked that the warning does not get printed if none of the partitions in the current system have FEATURES.OFFLINE.

I do wonder two things:

  1. It would be nice if we can only print the warning once. Now, we get it printed for every test instance, that is not really needed and very verbose. It also doesn't scale very well if we get more of such tests. Maybe we can make a utils function that keeps some global state that 'this error' has already printed. Of course, that means 'this error' needs some kind of unique signature, I'm not immediately sure how to do that. But if we have something like that, we could make (and call) a utils or hooks function to print the error, and then implement the logic there so that it only gets done once.
  2. We now do the warning in the init stage, and use a feature to make sure the test doesn't get generated. Should we push it to the setup stage, so that we can query if the current_partition has an offline feature, and then use a skip-if? The test instance then gets generated, but in the skip-if we can easily print the instruction. This ensures that it only gets printed if we are actually trying to schedule the test on an offline partition. The current logic will -also- print it if the system contains one offline partition, but we current try to schedule to another partition. That may be slightly confusing.

@casparvl

Copy link
Copy Markdown
Collaborator

I'm also not sure why I get this redefinition issue in flake8. The line number seems wrong, and I really don't see a redefinition?

@laraPPr

laraPPr commented Oct 28, 2025

Copy link
Copy Markdown
Collaborator Author

On suggestion number 2. That is what I had in the first place. Than you suggested that we should do it as is now. I think I'm fine with both but I'd rather not go back and forth.

@smoors

smoors commented Oct 28, 2025 •

Copy link
Copy Markdown
Collaborator

to avoid the verbosity, maybe we should only print the instructions when --verbose is set?
then, if we go for number 2, if it's not set, we could print something like this:

f'Excluding {self.name} on offline partition {self.current_partition.name}, use `--verbose` for pre-download instructions'

as another alternative, we could add a variable, say print_download_instructions, and if set on the cmd line, it will print the download instructions and immediately exit.

@casparvl

Copy link
Copy Markdown
Collaborator

On suggestion number 2. That is what I had in the first place. Than you suggested that we should do it as is now. I think I'm fine with both but I'd rather not go back and forth.

I know you did and I hate reviewers that keep changing their mind ;-) The issue that I have now - and did not foresee - is: how do you make sure that warning is visible when it's needed (i.e. not hidden in the logs), but not spammed when it's not needed? With the current setup, it'll warn you if there is an offline partition in your system even if that's not the one you've told reframe to run on. The easiest solution is to print it only if the current partition is offline, but that would require going back to the skip_if. And there was a reason we typically don't like that: we don't want every test suite run to just show a gazzillion 'skipped' messages, overshadowing everything else.

to avoid the verbosity, maybe we should only print the instructions when --verbose is set?

I like this, but it's irrespective of whether we should move back to a 'skip_if' or not. But it's a good way to make the default message shorter.

What I was really hoping @smoors would say is that 'yes, printing it once is easy with globals'. Then, I'd do that and keep the current approach. XD

I'm really on the fence between moving back to a skip_if... I guess on most systems on which one partition is offline, all partitions are (probably) offline, so then the current approach (i.e. as it is in 5e73445) is fine: that warning is practically always relevant whenver it is printed. I think we should just do it: too bad for people that have only some of their partitions offline, they see a few too many warnings. It still annoys me thought that you'd see this warning being repeated for all scales...

@casparvl

Copy link
Copy Markdown
Collaborator

How about we make something like this

# utils.py
def print_once(test, identifier, msg, level=info):
"""
This function only prints the message in msg to the reframe logger once for a given unique combination of test and identifier. In other words: for a given test, one can use come up with an identifier, and call the `print_once` function multiple times with the same identifier - yet only one message will be logged. This is useful in e.g. making sure the logging output doesn't get flooded when a highly parameterized test has many different test instances.
"""

global unique_message_table
unique_id = test.unique_name + identifier
if unique_id in unique_message_table:
    return
else:
    unique_message_table[unique_id]
    rflog.getlogger().log(level, msg)
fi

@smoors

smoors commented Oct 30, 2025

Copy link
Copy Markdown
Collaborator

i've implemented a log_once function, inspired by @casparvl 's suggestion.

note that i had to use test.__class__.__name__, because test.unique_name was too unique :), i.e. it would still log every test instance.

@casparvl

casparvl commented Nov 5, 2025

Copy link
Copy Markdown
Collaborator

note that i had to use test.class.name, because test.unique_name was too unique :), i.e. it would still log every test instance.

Oh good point, forgot about that... But I'd say indeed test.__class__.__name__ is the level of deduplication between log messages we were looking for.

@casparvl casparvl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

TLDR: approved!

Tested that the warning only gets printed once:

(eessi_test_venv) [casparl@int6 test-suite]$ reframe -c eessi/testsuite/tests/apps/tensorflow/ --run --system snellius:rome

[ReFrame Setup]
  version:           4.7.0-dev.3+20ccf7af
  command:           '/gpfs/home4/casparl/EESSI/eessi_test_venv/bin/reframe -c eessi/testsuite/tests/apps/tensorflow/ --run --system snellius:rome'
  launched by:       [email protected]
  working directory: '/gpfs/home4/casparl/EESSI/test-suite'
  settings files:    '<builtin>', '/gpfs/home4/casparl/EESSI/test-suite/config/surf_snellius.py'
  check search path: (R) '/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow'
  stage directory:   '/scratch-shared/casparl/reframe_output/staging'
  output directory:  '/gpfs/home4/casparl/EESSI/reframe_runs/output'
  log files:         '/gpfs/home4/casparl/EESSI/reframe_runs/logs/reframe_20251106_133851.log'

== Temporary log file in case of crash /scratch-local/45397/eb-8joat2kq/easybuild-4w0hya03.log
WARNING: Some partitions are labeled offline and will be excluded from EESSI_TensorFlow,
because ReFrame could not find the data at /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz.
To pre-download the data, please run (on a system with internet access):
mkdir -p /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets
module load TensorFlow/2.13.0-foss-2023a
python -c "import tensorflow as tf; tf.keras.datasets.mnist.load_data('/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz')"
[==========] Running 0 check(s)
[==========] Started on Thu Nov  6 13:38:53 2025+0100

[----------] start processing checks
[----------] all spawned checks have finished

[  PASSED  ] Ran 0/0 test case(s) from 0 check(s) (0 failure(s), 0 skipped, 0 aborted)
[==========] Finished on Thu Nov  6 13:38:53 2025+0100
Log file(s) saved in '/gpfs/home4/casparl/EESSI/reframe_runs/logs/reframe_20251106_133851.log'

Tested the download instructions and then rerunning:

$ mkdir -p /gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets
module load TensorFlow/2.13.0-foss-2023a
python -c "import tensorflow as tf; tf.keras.datasets.mnist.load_data('/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow/TensorFlow/2.13.0-foss-2023a/datasets/mnist.npz')"
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11490434/11490434 [==============================] - 1s 0us/step
$ module purge
$ module load EESSI
Module for EESSI/2023.06 loaded successfully
$ reframe -c eessi/testsuite/tests/apps/tensorflow/ --run --system snellius:rome -t 1_node

[ReFrame Setup]
  version:           4.7.0-dev.3+20ccf7af
  command:           '/gpfs/home4/casparl/EESSI/eessi_test_venv/bin/reframe -c eessi/testsuite/tests/apps/tensorflow/ --run --system snellius:rome -t 1_node'
  launched by:       [email protected]
  working directory: '/gpfs/home4/casparl/EESSI/test-suite'
  settings files:    '<builtin>', '/gpfs/home4/casparl/EESSI/test-suite/config/surf_snellius.py'
  check search path: (R) '/gpfs/home4/casparl/EESSI/test-suite/eessi/testsuite/tests/apps/tensorflow'
  stage directory:   '/scratch-shared/casparl/reframe_output/staging'
  output directory:  '/gpfs/home4/casparl/EESSI/reframe_runs/output'
  log files:         '/gpfs/home4/casparl/EESSI/reframe_runs/logs/reframe_20251106_133701.log'

== Temporary log file in case of crash /scratch-local/45397/eb-9sbjju2p/easybuild-rkfbtw2u.log
[==========] Running 1 check(s)
[==========] Started on Thu Nov  6 13:37:04 2025+0100

[----------] start processing checks
[ RUN      ] EESSI_TensorFlow %scale=1_node %module_name=TensorFlow/2.13.0-foss-2023a %device_type=cpu /9864d0f5 @snellius:rome+default
[       OK ] (1/1) EESSI_TensorFlow %scale=1_node %module_name=TensorFlow/2.13.0-foss-2023a %device_type=cpu /9864d0f5 @snellius:rome+default
P: perf: 60312.18172813244 img/s (r:0, l:None, u:None)
[----------] all spawned checks have finished

[  PASSED  ] Ran 1/1 test case(s) from 1 check(s) (0 failure(s), 0 skipped, 0 aborted)
[==========] Finished on Thu Nov  6 13:37:55 2025+0100
Log file(s) saved in '/gpfs/home4/casparl/EESSI/reframe_runs/logs/reframe_20251106_133701.log'

Perfect!

@casparvl
casparvl merged commit b0f05aa into EESSI:main Nov 6, 2025
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.

3 participants