question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object mode code fails to load from cache

See original GitHub issue

Reporting a bug

  • I have tried using the latest released version of Numba (most recent is visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
  • I have included a self contained code sample to reproduce the problem. i.e. it’s possible to run as ‘python bug.py’.

Object mode code below fails to load from cache. The problem is that the objmode dispatcher is serialized and compiled during runtime (see here). However, the function IR saved is invalid. The issue is that func_ir.copy() is used to avoid compiler’s mutations, but this doesn’t copy the IR nodes, which are modified in places like here. Avoiding these copy() calls before dispatcher compilation but adding remove_dels after compilation solves the problem. Are these copy() calls necessary?

import numba
import pandas as pd

@numba.njit(cache=True)
def f():

  with numba.objmode(T="int64"):
    typemap = {}
    typemap.update({i:"Int64" for i in range(3)})
    df = pd.DataFrame()
    arrs = []
    for i in range(df.shape[1]):
      arrs.append(df.iloc[:, i].values)
    T = len(arrs)
  return (T,)


f()
 ✗ python ../tmp/objmode_test.py
 ✗ python ../tmp/objmode_test.py
Traceback (most recent call last):
  File "/Users/ehsan/dev/bodo/../tmp/objmode_test.py", line 18, in <module>
    f()
  File "/Users/ehsan/dev/numba/numba/core/pythonapi.py", line 1682, in _call_objmode_dispatcher
    entrypt = dispatcher.compile(argtypes)
  File "/Users/ehsan/dev/numba/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/Users/ehsan/dev/numba/numba/core/dispatcher.py", line 1329, in compile
    return super().compile(sig)
  File "/Users/ehsan/dev/numba/numba/core/dispatcher.py", line 1210, in compile
    cres = compiler.compile_ir(typingctx=self.typingctx,
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 724, in compile_ir
    norw_cres = compile_local(func_ir.copy(), norw_flags)
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 720, in compile_local
    return pipeline.compile_ir(func_ir=the_ir, lifted=lifted,
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 438, in compile_ir
    return self._compile_ir()
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 499, in _compile_ir
    return self._compile_core()
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 471, in _compile_core
    raise e
  File "/Users/ehsan/dev/numba/numba/core/compiler.py", line 462, in _compile_core
    pm.run(self.state)
  File "/Users/ehsan/dev/numba/numba/core/compiler_machinery.py", line 343, in run
    raise patched_exception
  File "/Users/ehsan/dev/numba/numba/core/compiler_machinery.py", line 334, in run
    self._runPass(idx, pass_inst, state)
  File "/Users/ehsan/dev/numba/numba/core/compiler_lock.py", line 35, in _acquire_compile_lock
    return func(*args, **kwargs)
  File "/Users/ehsan/dev/numba/numba/core/compiler_machinery.py", line 289, in _runPass
    mutated |= check(pss.run_pass, internal_state)
  File "/Users/ehsan/dev/numba/numba/core/compiler_machinery.py", line 262, in check
    mangled = func(compiler_state)
  File "/Users/ehsan/dev/numba/numba/core/typed_passes.py", line 794, in run_pass
    post_proc.run(emit_dels=False)
  File "/Users/ehsan/dev/numba/numba/core/postproc.py", line 78, in run
    self.func_ir.blocks = transforms.canonicalize_cfg(self.func_ir.blocks)
  File "/Users/ehsan/dev/numba/numba/core/transforms.py", line 315, in canonicalize_cfg
    return canonicalize_cfg_single_backedge(blocks)
  File "/Users/ehsan/dev/numba/numba/core/transforms.py", line 244, in canonicalize_cfg_single_backedge
    cfg = compute_cfg_from_blocks(blocks)
  File "/Users/ehsan/dev/numba/numba/core/analysis.py", line 243, in compute_cfg_from_blocks
    cfg.add_edge(k, target)
  File "/Users/ehsan/dev/numba/numba/core/controlflow.py", line 112, in add_edge
    raise ValueError("Cannot add edge as dest node %s not in nodes %s" %
ValueError: Failed in object mode pipeline (step: remove phis nodes)
Cannot add edge as dest node 119 not in nodes {102, 70, 72, 12, 14, 112}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
njriasancommented, Dec 20, 2021

IIRC this got discussed and we’re waiting on a PR or example of an approach to resolve this issue? ISTR from the discussion that there was a risk that removing all copies would result in unintended mutation of the original in some places.

Hi @gmarkall. Sorry about that. I did have a PR and reran all of the tests. None of the ones that we suspected would induce issues did, but there was an issue in another test. I will open the PR after I debug it, I just haven’t had time yet (and will this week).

1reaction
gmarkallcommented, Dec 20, 2021

IIRC this got discussed and we’re waiting on a PR or example of an approach to resolve this issue? ISTR from the discussion that there was a risk that removing all copies would result in unintended mutation of the original in some places.

Read more comments on GitHub >

github_iconTop Results From Across the Web

13 Working With Java Object Cache - Oracle Help Center
Default Value: By default, no LOADER is set. This attribute indicates that the object was created by the application in the cache, rather...
Read more >
An error 'Cache may be out of date, try `force_reload=True ...
My new code block is: model = torch.hub.load('ultralytics/yolov5', 'custom', path='static/best.pt', force_reload=True).autoshape().
Read more >
How to Solve the Chunk Load Error in JavaScript - Rollbar
Whenever there's an error observed in dynamically fetching helper JavaScript files known as Chunks, a ChunkLoad Error is thrown.
Read more >
Troubleshoot Connected Cache - Configuration Manager
Verify; Log files; Setup error codes; IIS configurations ... When you correctly install the Delivery Optimization cache server, ...
Read more >
Caching in GitLab CI/CD
You use multiple standalone runners (not in autoscale mode) attached to one project without a shared cache. Use only one runner for your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found