You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Significantly increased number of allocations in v0.16.4 compared to v0.16.3 #425
I was doing SimpleUpdate benchmark tests using the current master branch of PEPSKit using the following script:
using Random
using TensorKit
using PEPSKit
using BenchmarkTools
Nr, Nc =2, 2
ham =j1_j2_model(
ComplexF64, Trivial, InfiniteSquare(Nr, Nc);
J1 =1.0, J2 =0.0, sublattice =false
)
D =8
Vvir = ℂ^D
state =InfinitePEPS(randn, ComplexF64, ℂ^2, Vvir; unitcell = (2, 2))
wts =SUWeight(state)
alg =SimpleUpdate(; trunc =truncrank(D))
evolver =TimeEvolver(state, ham, 0.1, 10, alg, wts)
circuit = evolver.gate
functiontest_suiter()
return PEPSKit.su_iter(state, circuit, alg, wts)
end@btimetest_suiter()
Using TensorKit v0.16.4, the output is
13.033 ms (43992 allocations: 50.63 MiB)
If I downgrade to v0.16.3, I get
12.372 ms (25368 allocations: 49.86 MiB)
The number of allocations is almost 50% smaller with v0.16.3, though the speed change is not that dramatic. I haven't been able to produce a more minimal example. Is this something to worry about?
It is quite hard to gauge what is going on, since the number of allocations does not necessarily map directly to a performance regression. Since the whole cache management system got rewritten, it isn't odd that this is happening per se, since I think we now have to retrieve cache data in 2 steps, rather than in 1, and there is some allocations associated with that. If you have a more in-depth profile view it might be that we have a type instability somewhere, which is causing this?
I came up with a more minimal code that benchmarks the "apply_gate" step in simple update.
using BenchmarkTools
using Profile
using TensorKit
functioncontract(
a::AbstractTensorMap{T, S, 2, 1}, b::AbstractTensorMap{T, S, 2, 1},
gate::AbstractTensorMap{T, S, 2, 2}
) where {T, S}
return@tensor a2b2[-1-2; -3-4] := gate[-2-3; 12] * a[-113] * b[32-4]
end
Vp, Vv = ℂ^4, ℂ^10# P.S. if I use these, allocation number difference becomes much smaller.# Vp = Vect[FermionParity ⊠ U1Irrep]((0, 0) => 2, (1, 1) => 1, (1, -1) => 1)# Vv = Vect[FermionParity ⊠ U1Irrep]((0, 0) => 4, (1, 1) => 2, (1, -1) => 2, (0, 2) => 1, (0, -2) => 1)
a =randn(Vv ⊗ Vp ← Vv)
b =randn(Vv ⊗ Vp ← Vv)
gate =randn(Vp ⊗ Vp ← Vp ⊗ Vp)
a2b2 =contract(a, b, gate)
@btimecontract($a, $b, $gate)
Profile.Allocs.clear()
Profile.Allocs.@profile sample_rate=1.0contract(a, b, gate)
results = Profile.Allocs.fetch()
n_alloc =length(results.allocs)
@info"Length of results.allocs = $(n_alloc)"for item in results.allocs
println(item)
end
Good news is that if I increase the bond dimension, the relative differences in execution time and memory allocation of the two versions become smaller. So this is indeed caused by changes in bookkeeping code, instead of performance regression in contraction/decomposition that should scale with the bond dimension.
In v0.16.3, there are 20 allocations of FusionBlockStructure.
In #387, FusionBlockStructure is separated to SectorStructure and DegeneracyStructure. Here in v0.16.5, I observe 6 allocations of SectorStructure and 20 allocations of DegeneracyStructure.
Actually I think they might, this was the entire point: the sector structure is shared whenever only the degeneracy changes (that was the entire point), and so it should indeed cache less sector stuff than degeneracy stuff :)
Will close this for now since it seems like this is expected and the actual size allocated hasn't increased drastically, but happy to reopen if this turns out to be an issue.
Activity
lkdvos commentedon May 1, 2026
It is quite hard to gauge what is going on, since the number of allocations does not necessarily map directly to a performance regression. Since the whole cache management system got rewritten, it isn't odd that this is happening per se, since I think we now have to retrieve cache data in 2 steps, rather than in 1, and there is some allocations associated with that. If you have a more in-depth profile view it might be that we have a type instability somewhere, which is causing this?
Yue-Zhengyuan commentedon May 2, 2026
I came up with a more minimal code that benchmarks the "apply_gate" step in simple update.
Good news is that if I increase the bond dimension, the relative differences in execution time and memory allocation of the two versions become smaller. So this is indeed caused by changes in bookkeeping code, instead of performance regression in contraction/decomposition that should scale with the bond dimension.
Below is the output for v0.16.3
Details
and v0.16.5
Details
I do see many
Anys in both versions. Does it indicate type instability somewhere?Yue-Zhengyuan commentedon May 2, 2026
In v0.16.3, there are 20 allocations of
FusionBlockStructure.In #387,
FusionBlockStructureis separated toSectorStructureandDegeneracyStructure. Here in v0.16.5, I observe 6 allocations ofSectorStructureand 20 allocations ofDegeneracyStructure.So naively the numbers don't add up.
lkdvos commentedon May 2, 2026
Actually I think they might, this was the entire point: the sector structure is shared whenever only the degeneracy changes (that was the entire point), and so it should indeed cache less sector stuff than degeneracy stuff :)
lkdvos commentedon May 12, 2026
Will close this for now since it seems like this is expected and the actual size allocated hasn't increased drastically, but happy to reopen if this turns out to be an issue.