Skip to content
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

dump load contraction orders #24

Merged
merged 3 commits into from
Jan 2, 2022
Merged

dump load contraction orders #24

merged 3 commits into from
Jan 2, 2022

Conversation

GiggleLiu
Copy link
Member

@GiggleLiu GiggleLiu commented Jan 2, 2022

julia> using OMEinsum, OMEinsumContractionOrders, Graphs
[ Info: Precompiling OMEinsumContractionOrders [6f22d1fd-8eed-4bb7-9776-e7d684900715]

julia> function random_regular_eincode(n, k; optimize=nothing)
            g = Graphs.random_regular_graph(n, k)
            ixs = [minmax(e.src,e.dst) for e in Graphs.edges(g)]
            return EinCode((ixs..., [(i,) for i in     Graphs.vertices(g)]...), ())
           end
random_regular_eincode (generic function with 1 method)

julia> code = random_regular_eincode(200, 3);

julia> optcode_tree = optimize_code(code, uniformsize(code, 2), TreeSA(sc_target=28, βs=0.1:0.1:20,
                                                                ntrials=5, niters=30, sc_weight=2.0));

julia> timespace_complexity(optcode_tree, uniformsize(code, 2))
(30.536222605629487, 26.0)

julia> writejson("test.json", optcode_tree)

julia> optcode_loaded = readjson("test.json")
SlicedEinsum{Any, NestedEinsum{DynamicEinCode{Int64}}}(Slicing{Any}(Any[]), 181, 181 -> 
├─ 145181, 181145 -> 181
│  ├─ 7518126, 1457526 -> 181145
│  │  ├─ 14519190, 145752619190 -> 1457526
│  │  │  ├─ 82961764737145, 47176758226371919096 -> 145752619190
│  │  │  │  ├─ 907075471059672163200150183661968550191, 19610515050471831631767075858272662620037191 -> 47176758226371919096
│  │  │  │  │  
│  │  │  │  │  
│  │  │  │  └─ 8216896176, 1684737145 -> 82961764737145
│  │  │  │     
│  │  │  │     
│  │  │  └─ 90107, 107145191 -> 14519190
│  │  │     ├─ 107191, 107145 -> 107145191
│  │  │     │  
│  │  │     │  
│  │  │     └─ 90107
│  │  └─ 26181, 75181 -> 7518126
│  │     ├─ 75181
│  │     └─ 26181
│  └─ 145, 145181 -> 145181
│     ├─ 145181
│     └─ 145
└─ 181
)

julia> timespace_complexity(optcode_loaded, uniformsize(code, 2))
(30.536222605629487, 26.0)

Data format

julia> code = EinCode([[1,2], [2,3], [3,4]], [1,4])
12, 23, 34 -> 14

julia> optcode = optimize_code(code, uniformsize(code, 2), TreeSA(; nslices=1))
SlicedEinsum{Int64, NestedEinsum{DynamicEinCode{Int64}}}(Slicing{Int64}([2]), 24, 12 -> 14
├─ 12
└─ 34, 23 -> 24
   ├─ 23
   └─ 34
)

Will generate file

{
    "slices": [
        2
    ],
    "output": [
        1,
        4
    ],
    "tree": {
        "isleaf": false,
        "eins": {
            "ixs": [
                [
                    2,
                    4
                ],
                [
                    1,
                    2
                ]
            ],
            "iy": [
                1,
                4
            ]
        },
        "args": [
            {
                "isleaf": false,
                "eins": {
                    "ixs": [
                        [
                            3,
                            4
                        ],
                        [
                            2,
                            3
                        ]
                    ],
                    "iy": [
                        2,
                        4
                    ]
                },
                "args": [
                    {
                        "isleaf": true,
                        "tensorindex": 3
                    },
                    {
                        "isleaf": true,
                        "tensorindex": 2
                    }
                ]
            },
            {
                "isleaf": true,
                "tensorindex": 1
            }
        ]
    },
    "label-type": "Int64",
    "inputs": [
        [
            1,
            2
        ],
        [
            2,
            3
        ],
        [
            3,
            4
        ]
    ]
}
  • root["label-type"] is the data type for labels.
  • root["slices"] are the sliced labels.
  • root["inputs"] are vectors of labels for input tensors.
  • root["output"] are labels for the output tensor.
  • root["tree"] specifies the nested einsum (a contraction tree).
  • eins is the einsum code for a single step contraction, its siblings ixs are inputs, which is a vector of vector, iy is the output, which is a vector.
  • args specifies the input arguments, which is a vector of leaf nodes or non-leaf nodes. For leaf nodes, we use tensorindex to specify a tensor in the inputs, a non-leaf nodes is specified as a nested einsum (subtree).

How to benchmark

julia> using CUDA, BenchmarkTools
[ Info: OMEinsum loaded the CUDA module successfully

julia> @benchmark CUDA.@sync optcode_loaded([CUDA.rand(fill(2, length(ix))...) for ix in getixsv(optcode_loaded)]...)
BenchmarkTools.Trial: 12 samples with 1 evaluation.
 Range (min  max):  417.572 ms  485.062 ms  ┊ GC (min  max): 2.28%  4.11%
 Time  (median):     441.641 ms               ┊ GC (median):    4.45%
 Time  (mean ± σ):   444.844 ms ±  24.147 ms  ┊ GC (mean ± σ):  3.69% ± 1.22%

  █ █ ██  █  █                   █  █ █      █           █    █  
  █▁█▁██▁▁█▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁█▁█▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁█ ▁
  418 ms           Histogram: frequency by time          485 ms <

 Memory estimate: 42.38 MiB, allocs estimate: 739486.

@codecov
Copy link

codecov bot commented Jan 2, 2022

Codecov Report

Merging #24 (35e8eab) into master (8903b36) will increase coverage by 0.29%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #24      +/-   ##
==========================================
+ Coverage   95.46%   95.75%   +0.29%     
==========================================
  Files           7        8       +1     
  Lines         684      731      +47     
==========================================
+ Hits          653      700      +47     
  Misses         31       31              
Impacted Files Coverage Δ
src/OMEinsumContractionOrders.jl 100.00% <ø> (ø)
src/json.jl 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8903b36...35e8eab. Read the comment docs.

@GiggleLiu GiggleLiu merged commit 7f53e3e into master Jan 2, 2022
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.

1 participant