Skip to content

Commit

Permalink
Fix compression bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsch committed Oct 10, 2023
1 parent f83a7e6 commit 450a771
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/StochasticStyles/compression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ struct ThresholdCompression{T} <: CompressionStrategy
end
ThresholdCompression() = ThresholdCompression(1)

_set_value!(w, key, val) = w[key] = val
_set_value!(w::Dict, key, val) = val 0 ? w[key] = val : delete!(w, key)

function _threshold_compress!(t::ThresholdCompression, w, pairs)
for (add, val) in pairs
prob = abs(val) / t.threshold
if prob < 1 # projection is only necessary if abs(val) < s.threshold
val = ifelse(prob > rand(), t.threshold * sign(val), zero(val))
end
w[add] = val
_set_value!(w, add, val)
end
end

Expand Down

0 comments on commit 450a771

Please sign in to comment.