Skip to content

Loosen index restriction #59

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

Merged
merged 1 commit into from
May 29, 2025
Merged

Loosen index restriction #59

merged 1 commit into from
May 29, 2025

Conversation

wsmoses
Copy link
Contributor

@wsmoses wsmoses commented May 13, 2025

cc @mcabbott for testing with reactant

@wsmoses
Copy link
Contributor Author

wsmoses commented May 13, 2025

okay with the Reactant PR (which depends on this being tagged: EnzymeAD/Reactant.jl#1278), everything seems good:

(base) wmoses@hydra:~/git/Reactant.jl$ cat oh.jl 
using OneHotArrays, Reactant

function oh_mul(a, b)
  return a * b
end

m = onehotbatch([10, 20, 30, 10, 10], 10:10:40)
r_m = Reactant.to_rarray(m)
a = rand(100,4)
r_a = Reactant.to_rarray(a)
@show @code_hlo oh_mul(r_a, r_m)
r_res = @jit oh_mul(r_a, r_m)
res = oh_mul(a, m)

@show convert(Array, r_res) ≈ res

(base) wmoses@hydra:~/git/Reactant.jl$ julia --project=oh oh.jl 
Precompiling ReactantOneHotArraysExt...
  1 dependency successfully precompiled in 3 seconds. 105 already precompiled.
AssertionError("Could not find registered platform with name: \"cuda\". Available platform names are: ")
#= /home/wmoses/git/Reactant.jl/oh.jl:11 =# @code_hlo(oh_mul(r_a, r_m)) = module @reactant_oh_mul attributes {mhlo.num_partitions = 1 : i64, mhlo.num_replicas = 1 : i64} {
  func.func @main(%arg0: tensor<4x100xf64>, %arg1: tensor<5xui32>) -> tensor<5x100xf64> {
    %c = stablehlo.constant dense<1> : tensor<5xi64>
    %0 = stablehlo.transpose %arg0, dims = [1, 0] : (tensor<4x100xf64>) -> tensor<100x4xf64>
    %1 = stablehlo.convert %arg1 : (tensor<5xui32>) -> tensor<5xi64>
    %2 = stablehlo.subtract %1, %c : tensor<5xi64>
    %3 = "stablehlo.gather"(%0, %2) <{dimension_numbers = #stablehlo.gather<offset_dims = [0], collapsed_slice_dims = [1], start_index_map = [1], index_vector_dim = 1>, slice_sizes = array<i64: 100, 1>}> : (tensor<100x4xf64>, tensor<5xi64>) -> tensor<100x5xf64>
    %4 = stablehlo.transpose %3, dims = [1, 0] : (tensor<100x5xf64>) -> tensor<5x100xf64>
    return %4 : tensor<5x100xf64>
  }
}
convert(Array, r_res) ≈ res = true

@avik-pal
Copy link
Member

cc @mcabbott for a review

@avik-pal
Copy link
Member

@mcabbott bump on this

@CarloLucibello CarloLucibello merged commit d5f18db into FluxML:main May 29, 2025
8 of 11 checks passed
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.

3 participants