Skip to content

Commit

Permalink
Trace cleanup, nvfuser version warning (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
apaz-cli authored Aug 3, 2024
1 parent 9888395 commit 7660cd5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
9 changes: 5 additions & 4 deletions thunder/core/baseutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,10 @@ def print_base_printable(x: Any, /) -> str:
_exec_ctr = 0


def compile_and_exec(fn_name: str, python_str: str, program_name: str, ctx: dict) -> Callable:
def build_callable(fn_name: str, python_str: str, file_name: str, ctx: dict) -> Callable:
global _exec_ctr

program_name = f"{program_name}_{_exec_ctr}"
program_name = f"{file_name}_{_exec_ctr}"

# simple cache hack
mtime = None # this signals that the cache should not be invalidated(!)
Expand All @@ -454,9 +454,10 @@ def compile_and_exec(fn_name: str, python_str: str, program_name: str, ctx: dict
inspect.linecache.cache[program_name] = size, mtime, lines, program_name

try:
code = compile(python_str, program_name, mode="exec")
code: CodeType = compile(python_str, program_name, mode="exec")
exec(code, ctx)
return ctx[fn_name]
_callable: Callable = ctx[fn_name] # Grab from globals()
return _callable
except Exception as e:
print("Encountered an exception while trying to compile the following program:")
print(python_str)
Expand Down
5 changes: 2 additions & 3 deletions thunder/core/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,9 @@ def python_callable(self, *, global_dicts: None | dict = None, **kwargs: Any) ->
ctx["__function_obj"] = self.fn
ctx["thunder"] = thunder

callable = baseutils.compile_and_exec(
self.siginfo().name, python_str=python_str, program_name=f"thunder.{self.siginfo().name}", ctx=ctx
return baseutils.build_callable(
self.siginfo().name, python_str=python_str, file_name=f"thunder.{self.siginfo().name}", ctx=ctx
)
return callable

def __repr__(self) -> str:
return self.python(print_depth=-1)
Expand Down
12 changes: 11 additions & 1 deletion thunder/executors/nvfuserex.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@ def required_nvfuser_version() -> LooseVersion:

def nvfuser_available() -> bool:
v = nvfuser_version()
return v is not None and v >= required_nvfuser_version()
if v is None:
return False

required = required_nvfuser_version()
if v < required:
import warnings

msg = f"Your nvfuser installation is out of date. Thunder requires version {required}, but found version {v}."
warnings.warn(msg)
return False
return True


nvfuserex: None | FusionExecutor = None
Expand Down
2 changes: 2 additions & 0 deletions thunder/extend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def resolve_executors(executors: None | Sequence[Executor | str]) -> tuple[Execu
continue
else:
resolved_executors.append(ex)
elif not isinstance(e, Executor):
raise ValueError(f"An object of type {type(e)} is not a valid Executor. Executor list: {executors}")
else:
resolved_executors.append(e)

Expand Down

0 comments on commit 7660cd5

Please sign in to comment.