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

working image for pymc-marketing pre installed env #341

Closed

Conversation

michaelraczycki
Copy link
Contributor

@michaelraczycki michaelraczycki commented Aug 5, 2023

This PR includes a Dockerfile to the repo, which allows users to build an image with working jupyter lab environment, pre-installed with all necessary libraries in order to run the tutorial notebooks. Because of that no local environment creation is needed.


📚 Documentation preview 📚: https://pymc-marketing--341.org.readthedocs.build/en/341/

@michaelraczycki
Copy link
Contributor Author

now users can spin up the container using :
docker run -u root -p 8888:8888 -v .:/home/jovyan/work tutorial_env
command, after building the image locally.

@maresb
Copy link
Contributor

maresb commented Aug 5, 2023

I think you only need two lines in the Dockerfile:

FROM jupyter/minimal-notebook:latest
RUN mamba install pymc-marketing

And you don't need -u root in the Docker command.

@michaelraczycki
Copy link
Contributor Author

oh, actually it does work with the 2 liner, now thinking about it I don't know why I was creating virtualenv for installation within the container :)

@codecov
Copy link

codecov bot commented Aug 5, 2023

Codecov Report

Merging #341 (4aeaf82) into main (12b56e2) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #341   +/-   ##
=======================================
  Coverage   95.85%   95.85%           
=======================================
  Files          19       19           
  Lines        1447     1447           
=======================================
  Hits         1387     1387           
  Misses         60       60           

@maresb
Copy link
Contributor

maresb commented Aug 5, 2023

One thing to note here is that this won't give you any sort of reproducibility. You might want to consider building the Docker image in CI. This has the bonus that downloading is much faster than building.

You might also consider some CI to ensure that the notebooks all execute without error. (As dependencies update, things sometimes break.) Then at least you'd know when things stop working.

@michaelraczycki
Copy link
Contributor Author

Do you mean like creating a CI that would build and push the image to the dockerhub and then get the users to pull and spin that up?

@maresb
Copy link
Contributor

maresb commented Aug 5, 2023

Ya. I'd probably recommend GitHub Container Registry over DockerHub though.

Copy link
Contributor Author

@michaelraczycki michaelraczycki left a comment

Choose a reason for hiding this comment

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

@maresb did you have something like this in mind?

@maresb
Copy link
Contributor

maresb commented Aug 8, 2023

Yes, that looks about right, at least for the tricky half of it. Great work!

The other half which I'd suggest implementing is to push to GHCR (GitHub Container Registry) after the "Check for errors" step succeeds.

I'd recommend adding an on-trigger for pull requests and also a schedule so that it runs periodically (like maybe once per day) so that you stay on top of breakage due to dependency updates. For these two cases you should skip the "Push to GHCR" step. (Note: "on push branches main" means "when you either directly push to main or when you merge a PR into main.)

Finally, regarding the scheduled tests, I believe that when they fail they will do so silently, so you will probably want to look into some notification mechanism, e.g. open an issue when the workflow fails.

@maresb
Copy link
Contributor

maresb commented Aug 8, 2023

Ah, I'd also add a "workflow dispatch" (i.e. a button) trigger so that you can kick things off manually.

@michaelraczycki
Copy link
Contributor Author

@ricardoV94 , @twiecki so far I'm including only the latest deployment notebook in the CI (I assume that the env requirements should be the same for all of the notebooks in the repo) but if my assumption is incorrect please list the notebooks we should be checking in here (I think we should avoid checking every single notebook in one job as it would make the runtime very long)

@maresb
Copy link
Contributor

maresb commented Aug 8, 2023

I don't know offhand how to open an issue on failure, but this looks promising. You'll need an if clause which looks something like:

if: failure() && (github.event_name == 'schedule')

@BBDS-Colt
Copy link

Can we confirm this has been tested for compilation errors?

https://discourse.pymc.io/t/pytensor-compilation-error/11047

WARNING (pytensor.tensor.blas): Using NumPy C-API based implementation for BLAS functions.
Running on PyMC v5.0.0

If the above message appears when pytensor (or any of its dependencies like pymc or pymc-marketing are loaded into the notebook, at best it will slow down sampling performance. At worst, it won't run anything at all:

Output exceeds the size limit. Open the full output data in a text editor
ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (pytensor.graph.rewriting.basic): node: InplaceDimShuffle{}(TensorConstant{(1,) of 3})
ERROR (pytensor.graph.rewriting.basic): TRACEBACK:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1933, in process_node
    replacements = node_rewriter.transform(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1092, in transform
    return self.fn(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/tensor/rewriting/basic.py", line 1141, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 131, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 96, in make_c_thunk
    outputs = cl.make_thunk(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1202, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1122, in __compile__
    thunk, module = self.cthunk_factory(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1647, in cthunk_factory
    module = cache.module_from_key(key=key, lnk=self)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 1229, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1546, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 2641, in compile_str
...
ld: library not found for -lSystem
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)



You can find the C code in this temporary file: /var/folders/nv/ntvjypdj4tqbgznkrcfhzm240000gn/T/pytensor_compilation_error_osgnqwmm
library System is not found.
Output exceeds the size limit. Open the full output data in a text editor
ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (pytensor.graph.rewriting.basic): node: InplaceDimShuffle{}(TensorConstant{(1,) of 3})
ERROR (pytensor.graph.rewriting.basic): TRACEBACK:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1933, in process_node
    replacements = node_rewriter.transform(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1092, in transform
    return self.fn(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/tensor/rewriting/basic.py", line 1141, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 131, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 96, in make_c_thunk
    outputs = cl.make_thunk(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1202, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1122, in __compile__
    thunk, module = self.cthunk_factory(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1647, in cthunk_factory
    module = cache.module_from_key(key=key, lnk=self)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 1229, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1546, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 2641, in compile_str
...
ld: library not found for -lSystem
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)



You can find the C code in this temporary file: /var/folders/nv/ntvjypdj4tqbgznkrcfhzm240000gn/T/pytensor_compilation_error_fgg5rho8
library System is not found.
Output exceeds the size limit. Open the full output data in a text editor
ERROR (pytensor.graph.rewriting.basic): Rewrite failure due to: constant_folding
ERROR (pytensor.graph.rewriting.basic): node: InplaceDimShuffle{}(TensorConstant{(1,) of 3})
ERROR (pytensor.graph.rewriting.basic): TRACEBACK:
ERROR (pytensor.graph.rewriting.basic): Traceback (most recent call last):
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1933, in process_node
    replacements = node_rewriter.transform(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/graph/rewriting/basic.py", line 1092, in transform
    return self.fn(fgraph, node)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/tensor/rewriting/basic.py", line 1141, in constant_folding
    thunk = node.op.make_thunk(node, storage_map, compute_map, no_recycling=[])
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 131, in make_thunk
    return self.make_c_thunk(node, storage_map, compute_map, no_recycling)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/op.py", line 96, in make_c_thunk
    outputs = cl.make_thunk(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1202, in make_thunk
    cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1122, in __compile__
    thunk, module = self.cthunk_factory(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1647, in cthunk_factory
    module = cache.module_from_key(key=key, lnk=self)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 1229, in module_from_key
    module = lnk.compile_cmodule(location)
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/basic.py", line 1546, in compile_cmodule
    module = c_compiler.compile_str(
  File "/Users/marcelino/miniconda3/envs/pymc_env/lib/python3.9/site-packages/pytensor/link/c/cmodule.py", line 2641, in compile_str
...
ld: library not found for -lSystem
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)



You can find the C code in this temporary file: /var/folders/nv/ntvjypdj4tqbgznkrcfhzm240000gn/T/pytensor_compilation_error_rvr4bkw9
library System is not found.

I've encountered this with every dev container variation I've tried in GitHub codespaces (which are Debian builds). However, I noticed the latest Ubuntu image is being pulled in the Dockerfile, so it's worth verifying.

Using mamba for env management is usually how these compilation headaches are resolved, which may require open-sourcing an image purpose-built for pytensor.

These compilation errors are one of the most common issues encountered in pytensor production deployments, and in my opinion represent a key bottleneck preventing more widespread usage of this library.

@juanitorduz
Copy link
Collaborator

I just want to point out that this PR is an excellent initiative 💪 !

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

Woah @BBDS-Colt, that's some huge type!

I totally agree, and no worries, I've got you covered. Check out the code I wrote a few years ago (before the whole Aesara/PyTensor fork) here.

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

Ah, on second thought it's not quite that easy for Apple Silicon... GitHub doesn't provide ARM runners, so if you want to run tests you'd have to emulate with QEMU. It's doable but a little more complicated.

@michaelraczycki
Copy link
Contributor Author

@BBDS-Colt Locally I had the same issue, I found that when setting up the conda env on Mac M1 you should install all the dependencies, then uninstall the pytensor-base and install it again using conda or mamba install. The reason I suspect is that installing ipykernel re-installs some dependency package that doesn't support the arm architecture, therefore making pytensor unusable on arm. Reinstallation helped in my case, but working with the Jupyter-minimal image didn't cause the same issues to arise. I think in that case, all the packages were installed in the base image, and then we're installing pymc-marketing with correct arm-supporting dependencies

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

you should install all the dependencies, then uninstall the pytensor-base and install it again using conda or mamba install

@michaelraczycki, this seems like a bug. Would you be able to file a report, perhaps at PyTensor's conda-forge feedstock?

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

Didn't you also have some crazy recipe on Discourse for the BLAS setup? Could you also create an issue for that? I want to build it into the feedstock when I get the chance.

@michaelraczycki
Copy link
Contributor Author

Didn't you also have some crazy recipe on Discourse for the BLAS setup? Could you also create an issue for that? I want to build it into the feedstock when I get the chance.

Actually I don't remember the BLAS case, I can try to find it but I think it was also connected to the same pytensor issue. I can open the issue at Conda-forge pytensor, but first I'd try to reproduce the error again, it's been few months since I've last time seen it

@michaelraczycki
Copy link
Contributor Author

Ah, on second thought it's not quite that easy for Apple Silicon... GitHub doesn't provide ARM runners, so if you want to run tests you'd have to emulate with QEMU. It's doable but a little more complicated.

was this meant as a follow up to your conversation with Colt, or to our one about the Git CI for checking the notebooks?

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

More directly it was a followup with Colt, but we'd probably implement it in the CI.

There's quite a lot to do here, so perhaps it makes sense to merge this as a start and break up the other suggestions into a bunch of enhancements.

@ColtAllen
Copy link
Collaborator

More directly it was a followup with Colt, but we'd probably implement it in the CI.

There's quite a lot to do here, so perhaps it makes sense to merge this as a start and break up the other suggestions into a bunch of enhancements.

I agree; let's keep this one focused and leave the BLAS contingencies for a future PR. If you want me to post any issues for what's been discussed, let me know.

Also, this library runs flawlessly with pip install pymc-marketing on my 2023 M2 Pro, but pretty much any prod deployment in industry will be container-based.

@maresb
Copy link
Contributor

maresb commented Aug 9, 2023

Ya, the BLAS issues are anyways specific to PyTensor and don't have anything directly to do with this.

@ricardoV94
Copy link
Contributor

Is there a consensus whether this is still useful or can we close?

@twiecki
Copy link
Contributor

twiecki commented Oct 24, 2023

Looks useful, I say let's merge it.

@ricardoV94
Copy link
Contributor

I don't want a new CI to test 2 lines of code if that's okay

@twiecki
Copy link
Contributor

twiecki commented Oct 24, 2023

I don't want a new CI to test 2 lines of code if that's okay

That's okay ;).

@twiecki twiecki closed this Oct 24, 2023
@maresb
Copy link
Contributor

maresb commented Oct 24, 2023

There's a lot happening in this PR, so probably best to regroup under more targeted efforts.

Potentially:

  1. Build and test a pymc-marketing image (would probably make sense to reopen this after adding a push step to the CI)
  2. Improve the way we test various environments and versions in general, but this is probably best tackled first at the PyTensor/PyMC level

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.

7 participants