Skip to content

Commit

Permalink
Quantized integers to Torchx
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Sep 4, 2024
1 parent 81a2c5e commit ca18083
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions torchx/lib/torchx/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ defmodule Torchx.Backend do
for <<x::native-size(size) <- bin>>, into: <<>>, do: <<x::native-size(double_size)>>
end

defp maybe_pad_binary(bin, {:u, size}) when size in [2, 4] do
for <<x::native-size(size) <- bin>>, into: <<>>, do: <<x::native-8>>
end

defp maybe_pad_binary(bin, {:s, size}) when size in [2, 4] do
for <<x::native-signed-size(size) <- bin>>, into: <<>>, do: <<x::native-signed-8>>
end

defp maybe_pad_binary(bin, _), do: bin

## Shape
Expand Down Expand Up @@ -1746,6 +1754,12 @@ defmodule Torchx.Backend do
current_type = Torchx.scalar_type(device_ref) |> from_torch_type()

case {current_type, type} do
{{:s, 8}, {:s, qint}} when qint in [2, 4] ->
:ok

{{:u, 8}, {:u, qint}} when qint in [2, 4] ->
:ok

{{:s, 32}, {:u, 16}} ->
:ok

Expand Down

0 comments on commit ca18083

Please sign in to comment.