Add Codespace for running FTorch Online
This PR adds integration with GitHub Codespaces for running demonstrations and workshops.
Done via a devcontainer and Dockerfile
To launch go to this branch on the FTorch page, click "code" -> "Codespaces" -> "Create Codespace on codespace"
This will drop you into a codespace session within VSCode in browser.
From here we can build FTorch using:
mkdir build
cd build
python3 -m venv venv
source venv/bin/activate
pip install torch --index-url https://download.pytorch.org/whl/cpu
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=/workspaces/FTorch/build/venv/lib/python3.10/site-packages/torch \
-DCMAKE_INSTALL_PREFIX=/workspaces/FTorch/bin
cmake --build . --target install
Note we need to specify the CPU wheel for pytorch, otherwise we get a bunch of CUDA infrastructure and then complaints about missing cuda when trying to build and link against libtorch.
I can then build and run exercise 1 with:
export LD_LIBRARY_PATH=/workspaces/FTorch/build/venv/lib/python3.10/site-packages/torch/lib
cd /workspaces/FTorch/examples/1_Tensor/
mkdir build && cd build
cmake .. -DCMAKE_PREFIX_PATH=/workspaces/FTorch/bin -DCMAKE_BUILD_TYPE=Release
cmake --build .
./tensor_manipulation
Note that I seem to need to set the LD_LIBRARY_PATH, otherwise I am unable to locate the libtorch.so and others when building exercises. Relates to issues seen elsewhere by myself and @niccolozanotti
This seems to be a viable option for teaching (assuming all students and teachers have sufficient hours on codespaces 120 default, 180 pro). Further questions:
- How much do we pre-install?
- we could install torch in a venv and even pre-build FTorch if we wished to dive direct into the exercises.
- Other devcontainer options?
- currently I have it very minimal.
- Do we also place this in the workshop repo, or just teach directly from here?
- I think all the workshop examples are now here, so probably best to teach from here.
If we merge this I need to:
- [x] Explore further options
- [x] Add docs on how to run in a codespace
@jwallwork23 @dorchard If you have a chance to look at this and let me know if we want to take this route for summer school (and HPC days etc?) please let me know and I will add docs etc.
Yep, that's my thoughts, just wanted to check if this was a way to go before I delved too deep! I'll try and schedule time to look at that this week.
I could cat it to a script that users run, or could just make building FTorch part of the setup so that it's ready to use on load. Any preferences either way?
I could cat it to a script that users run, or could just make building FTorch part of the setup so that it's ready to use on load. Any preferences either way?
I have a local build.sh script that I use all the time.
For tutorials, I think it'd be instructive to have attendees install FTorch and then the examples themselves in the Codespace, even if this just amounts to running a script.
For tutorials, I think it'd be instructive to have attendees install FTorch and then the examples themselves in the Codespace, even if this just amounts to running a script.
Agreed
Yep, that's my thoughts, just wanted to check if this was a way to go before I delved too deep! I'll try and schedule time to look at that this week.
I could cat it to a script that users run, or could just make building FTorch part of the setup so that it's ready to use on load. Any preferences either way?
If it's easier you can just git add it to the .devcontainer folder in a tutorial folder or something. Then it will be in the repo and we can version control it
good start @jatkinson1000 . In terms of your questions:
- How much do we pre-install?
Think you and @jwallwork23 have already covered it. There's a balance between pre-installing everything to make it quick and taking too much away from the user's learning. Probs keep as you have now.
- Other devcontainer options?
I am looking at this for my summer school debugging container too. You might want to install a fortran plugin and a python one too.
- Do we also place this in the workshop repo, or just teach directly from here?
I think it's nice to have one here for FTorch users in future who may want to give it a test ride :rocket:
Note to self have been trying to update this for some time and getting network issues and failure to connect.
Turns out you need to turn Enhanced Tracking Protection off in FF Worth remembering for secure-browsing participants that might also run into this @TomMelt
I am looking at this for my summer school debugging container too. You might want to install a fortran plugin and a python one too.
I tried this in https://github.com/Cambridge-ICCS/FTorch/pull/346/commits/2dc94ca032090059b445aaca593c32fac5cc2044 but afaict the plugins are not installed when I fire-up the codespace. Any advice @TomMelt? I am going based off of https://containers.dev/supporting.html
OK, I have added a script to build FTorch to a codespace/ directory, and associated instructions in a README.
The codespace will:
- Boot up a docker image with cmake, gfortran, python installed
- Drop the user into VSCode with the codespace README open
Hopefully this can be trialled at the HPCDays.
@TomMelt and @jwallwork23 please could you take a look, see if you can follow this and get it to work, and make any suggestions?
@jwallwork23 shellcheck requested I do a few things to appease it that I am not really sure we want in a script that users are looking at (cd || exit) and noqa statements. I wonder if we ignore this file for static analysis purposes?
@TomMelt I tried to get the linters to auto-install, but I don't think it works, so if you have any advice lmk!
I am looking at this for my summer school debugging container too. You might want to install a fortran plugin and a python one too.
I tried this in 2dc94ca but afaict the plugins are not installed when I fire-up the codespace. Any advice @TomMelt? I am going based off of https://containers.dev/supporting.html
I think this feature is not supported in codespaces. So, if the plugin is from an "untrusted" publisher you will most likely need to install it manually. At least that's my understanding (see here for more info).
@jwallwork23 shellcheck requested I do a few things to appease it that I am not really sure we want in a script that users are looking at (cd || exit) and noqa statements. I wonder if we ignore this file for static analysis purposes?
Yeah I think it's fine to not apply static analysis here.
Thanks for that catch @jwallwork23! Applied those suggestions.