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

Simplify function implementation returned by thunder.jit for easier instrumentation of different stages #1333

Merged
merged 17 commits into from
Oct 31, 2024

Conversation

IvanYashchuk
Copy link
Collaborator

@IvanYashchuk IvanYashchuk commented Oct 21, 2024

This PR changes the thunder.jit.fn_ implementation to use just a few lines of code making it more readable and amenable to per-function instrumentation like cProfile, pyinstrument, or NVTX decorators.

I removed a few unused timer measurements or if there was just a stop with no start. Other than that all CompileStats time measurements are preserved in this PR.

There was a todo to rename "last_executed" to "last_computation", this change is included here.

Here is what the function looks like now:

def fn_(*args, **kwargs) -> Any:
    cache_entry, inps, pro_to_epi = get_computation_and_inputs(*args, **kwargs)
    check_storage_aliases(cache_entry, inps)
    result = cache_entry.computation_fn(*inps)
    result = maybe_connect_to_autograd(cache_entry, result)
    result = maybe_call_epilogue(cache_entry, result, pro_to_epi)
    return result

@IvanYashchuk IvanYashchuk marked this pull request as draft October 21, 2024 15:09
@IvanYashchuk IvanYashchuk marked this pull request as ready for review October 21, 2024 15:30
@IvanYashchuk IvanYashchuk requested a review from tfogal October 21, 2024 15:30
@IvanYashchuk
Copy link
Collaborator Author

@tfogal, could you please review the changes? Would this PR work well with the planned nvtx marker decorators from #1268?

@IvanYashchuk
Copy link
Collaborator Author

CI failures that I need to take a look what's going on:

=========================== short test summary info ============================
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-llama1-like] - TypeError: tuple indices must be integers or slices, not tuple
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-codellama2-like] - TypeError: tuple indices must be integers or slices, not tuple
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-falcon-40b-like] - TypeError: tuple indices must be integers or slices, not tuple
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-long-context-like] - TypeError: tuple indices must be integers or slices, not tuple
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-llama2-like] - TypeError: tuple indices must be integers or slices, not tuple
FAILED thunder/tests/test_jit_general.py::test_litgpt_variants_kvcache[cpu-falcon-7b-like] - TypeError: tuple indices must be integers or slices, not tuple

Copy link
Collaborator

@tfogal tfogal left a comment

Choose a reason for hiding this comment

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

Thank you!

thunder/__init__.py Show resolved Hide resolved
@tfogal
Copy link
Collaborator

tfogal commented Oct 21, 2024

There was a todo to rename "last_executed" to "last_computation", this change is included here.

Is this one of the timers that mixology is using? If so, we may want to hold off on this part. @mpatel31415 ?

@mpatel31415
Copy link
Contributor

There was a todo to rename "last_executed" to "last_computation", this change is included here.

Is this one of the timers that mixology is using? If so, we may want to hold off on this part. @mpatel31415 ?

No, we use iter_t0 = time.perf_counter() and t1 = time.perf_counter() from benchmark_litgpt.py script :)

@tfogal
Copy link
Collaborator

tfogal commented Oct 22, 2024

There was a todo to rename "last_executed" to "last_computation", this change is included here.

Is this one of the timers that mixology is using? If so, we may want to hold off on this part. @mpatel31415 ?

No, we use iter_t0 = time.perf_counter() and t1 = time.perf_counter() from benchmark_litgpt.py script :)

oh, great!

I thought you were using some timers, though---how are you measuring compilation time, if not using these CompileStats timers?

@mpatel31415
Copy link
Contributor

There was a todo to rename "last_executed" to "last_computation", this change is included here.

Is this one of the timers that mixology is using? If so, we may want to hold off on this part. @mpatel31415 ?

No, we use iter_t0 = time.perf_counter() and t1 = time.perf_counter() from benchmark_litgpt.py script :)

oh, great!

I thought you were using some timers, though---how are you measuring compilation time, if not using these CompileStats timers?

We measure 2N iterations giving us iter_times = [t1, t2, .. t_2N] and we assume that compilation (and warmup) time is sum(iter_times[:N]) - sum(iter_times[N:]). In this way it's easy to measure it irrespective of the compilation method in the same way.

@tfogal
Copy link
Collaborator

tfogal commented Oct 23, 2024

I thought you were using some timers, though---how are you measuring compilation time [. . .]

We measure 2N iterations [. . .]

Oh! That's actually great news as I had (incorrectly) thought you were using the timers, and this makes it easier for us to change that interface.

Thanks!

@tfogal
Copy link
Collaborator

tfogal commented Oct 30, 2024

Looks like tests pass and this is good to go, AFAICT.

@t-vi merge?

@t-vi
Copy link
Collaborator

t-vi commented Oct 31, 2024

So when will we be able to drop the timers?

Copy link
Collaborator

@t-vi t-vi left a comment

Choose a reason for hiding this comment

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

Thank you @IvanYashchuk @mpatel31415 @tfogal
Seems good, I would want to drop all the timings gathered here very soon unless there is a user for them.
From what I understand, people interested in timings do profile things.

@t-vi t-vi merged commit 7b620b0 into main Oct 31, 2024
41 checks passed
@t-vi t-vi deleted the thunder-fn-instrumentation branch October 31, 2024 08:47
@tfogal
Copy link
Collaborator

tfogal commented Nov 1, 2024

So when will we be able to drop the timers?

I can start looking at this after #1268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants