xdslproject / xdsl

A Python Compiler Design Toolkit
Other
270 stars 70 forks source link

Wrong values on large dense arrays after xdsl-opt #2876

Closed gabrielrodcanal closed 1 month ago

gabrielrodcanal commented 3 months ago

Hi there, I have found a strange behaviour when running an MLIR code through xdsl-opt (no passes). The code is a NN that has very large dense arrays, and so they are formatted as a string in hex. After running the code through xdsl-opt however, it replaces it by a single float, even though the tensor is multidimensional. A minimal example:

"builtin.module"() ({
  "memref.global"() <{constant, initial_value = dense<"0xEEA7CC3DF47612BE2BA4173E8B75E8BDE0B915BDA3191CBE8388E0BDC826DB3DFE78273E6B037E3DEF140D3EF0B5803D4026693CD6B6E1BCE08B4DBDC3A9E63D943B163EE64E46BD808C253EB8F4893D30270CBE36696C3D045E1DBED06A703DA33EBBBD66D646BD36507BBD764D8FBD7010FA3DB6E1B53D9B83C8BDD33FA73D58AD293EB0A6123EAB2627BA40B4CB3C20E9B6BD805AB2BDE047BDBC809A743DE01ADD3D9B77D5BDCEE7043E00B8C1BDCBA80A3DBB03DA3D787C993D163968BC208510BDABFDB1BD8C07213EA34614BEAB06B73A0091413B8013B3BD768F193E7B6515BE7306833D363183BC36BC8B3CA016B7BD3E05D33DE67C28BDCABB0EBEDA2A013EA67DF6BD007EB5BA782A04BEAB69F73D16DD703D3B93A43D1BE45B3DEBAEE8BD8891F1BDF8B18F3D20EC923CE67101BE8382A8BDAB9EE7BA0006CA3AA3F224BE1B56A5BDC06B8A3DC3E6BE3D562310BB964B713C2CC11FBE4BC68F3DAEACD7BDFB093A3D00070F3EC3E4C93D5BCF0D3D1B01E13D9B7D7F3D537CD43D6BEDFBBC4BD9AEBD17BA023E569906BB86599CBD4E28073E1639F5BDF60909BE8B4727BEE4AD153EDF3C05BEB01913BEEB1A59BD03E8D4BD4BD3123D9EA381BD6058F03CD0EFF73D00747FBADBC5AEBD5054273E204DB4BD00CA683B1E28C93D3BCC2A3D9B0E683D4302923D9A3408BEABC89D3A565336BCC0A7F3BD76D1F93D68A3B93D44891C3E1685243E1B3FDBBD5E06A4BD2B4192BD2B19983C50C97B3D40A808BEC0994C3D4B3435BD0B88293D506749BDFC13063E2B7ADF3CF3B013BE"> : tensor<4x4x3x3xf32>, sym_name = "__constant_4x4x3x3xf32_1", sym_visibility = "private", type = memref<4x4x3x3xf32>}> : () -> ()
}) {torch.debug_module_name = "ResnetBB"} : () -> ()

After running it through xdsl-opt it will produce:

builtin.module attributes  {"torch.debug_module_name" = "ResnetBB"} {
  "memref.global"() <{"constant", "initial_value" = dense<0.09992967545986176> : tensor<4x4x3x3xf32>, "sym_name" = "__constant_4x4x3x3xf32_1", "sym_visibility" = "private", "type" = memref<4x4x3x3xf32>}> : () -> ()
}
JosseVanDelm commented 3 months ago

I added support for this back in January in https://github.com/xdslproject/xdsl/pull/1974 , but it is quite likely that something was wrong there since the things I had to do to make it work were quite crusty.

superlopuh commented 3 months ago

Unassigning people just because that leads to a bit of a bystander effect, it would be great if one of the people previously assigned to assign the issue to themselves to communicate that they're looking into it. Seems like a bad bug that might bight us in the future. I can't really look into it for the next two weeks.