-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: tracing Random.jl functionality correctly #363
Draft
avik-pal
wants to merge
6
commits into
main
Choose a base branch
from
ap/random_numbers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> using Reactant, Random
julia> fn() = randn(Random.default_rng(), 2, 3)
fn (generic function with 1 method)
julia> @code_hlo optimize = false fn()
module {
func.func @main() -> tensor<3x2xf64> {
%c = stablehlo.constant dense<[9454987348304227925, 11257230962712577529]> : tensor<2xui64>
%output_state, %output = stablehlo.rng_bit_generator %c, algorithm = DEFAULT : (tensor<2xui64>) -> (tensor<2xui64>, tensor<2x3xui64>)
%0 = stablehlo.convert %output : (tensor<2x3xui64>) -> tensor<2x3xf64>
%cst = stablehlo.constant dense<1.8446744073709552E+19> : tensor<2x3xf64>
%1 = stablehlo.divide %0, %cst : tensor<2x3xf64>
%cst_0 = stablehlo.constant dense<2.000000e+00> : tensor<2x3xf64>
%2 = stablehlo.multiply %1, %cst_0 : tensor<2x3xf64>
%cst_1 = stablehlo.constant dense<1.000000e+00> : tensor<2x3xf64>
%3 = stablehlo.subtract %2, %cst_1 : tensor<2x3xf64>
%4 = chlo.erf_inv %3 : tensor<2x3xf64> -> tensor<2x3xf64>
%cst_2 = stablehlo.constant dense<1.4142135623730951> : tensor<2x3xf64>
%5 = stablehlo.multiply %4, %cst_2 : tensor<2x3xf64>
%6 = stablehlo.transpose %5, dims = [1, 0] : (tensor<2x3xf64>) -> tensor<3x2xf64>
return %6 : tensor<3x2xf64>
}
}
julia> @code_hlo fn()
module {
func.func @main() -> tensor<3x2xf64> {
%cst = stablehlo.constant dense<1.4142135623730951> : tensor<2x3xf64>
%cst_0 = stablehlo.constant dense<1.000000e+00> : tensor<2x3xf64>
%cst_1 = stablehlo.constant dense<2.000000e+00> : tensor<2x3xf64>
%cst_2 = stablehlo.constant dense<1.8446744073709552E+19> : tensor<2x3xf64>
%c = stablehlo.constant dense<[17523564455668573441, 5342821220909967229]> : tensor<2xui64>
%output_state, %output = stablehlo.rng_bit_generator %c, algorithm = DEFAULT : (tensor<2xui64>) -> (tensor<2xui64>, tensor<2x3xui64>)
%0 = stablehlo.convert %output : (tensor<2x3xui64>) -> tensor<2x3xf64>
%1 = stablehlo.divide %0, %cst_2 : tensor<2x3xf64>
%2 = stablehlo.multiply %1, %cst_1 : tensor<2x3xf64>
%3 = stablehlo.subtract %2, %cst_0 : tensor<2x3xf64>
%4 = chlo.erf_inv %3 : tensor<2x3xf64> -> tensor<2x3xf64>
%5 = stablehlo.multiply %4, %cst : tensor<2x3xf64>
%6 = stablehlo.transpose %5, dims = [1, 0] : (tensor<2x3xf64>) -> tensor<3x2xf64>
return %6 : tensor<3x2xf64>
}
} |
avik-pal
force-pushed
the
ap/random_numbers
branch
from
December 11, 2024 13:54
99e0e76
to
7d17faf
Compare
This is kind of working now. Can I get an initial review? |
avik-pal
commented
Dec 11, 2024
Comment on lines
+103
to
+111
if (f === Random.default_rng || f === default_rng) && length(argtypes) == 1 | ||
arginfo2 = ArgInfo( | ||
fargs isa Nothing ? nothing : Any[:($(default_rng_inside_interpreter))], | ||
Any[Core.Const(default_rng_inside_interpreter)], | ||
) | ||
return abstract_call_known( | ||
interp, default_rng_inside_interpreter, arginfo2, si, sv, max_methods | ||
) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will have to be updated once the new CUDA interpreter stuff lands
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.