Export Phi-3.5-mini-instruct piece by piece

torch.export.export() often breaks on big models because there are control flows or instructions breaking the propagation of dynamic shapes (see …). The function usually gives an indication where the model implementation can be fixed but in case, that is not possible, we can try to export the model piece by piece: every module is converted separately from its submodule. A model can be exported even if one of its submodules cannot.

Model

import pprint
from typing import Any, Dict
import torch
import torch._export.tools
import transformers
from onnx_diagnostic.helpers.cache_helper import make_dynamic_cache
from experimental_experiment.helpers import string_type
from experimental_experiment.torch_interpreter.piece_by_piece import (
    trace_execution_piece_by_piece,
)


def get_phi35_untrained(batch_size: int = 2, **kwargs) -> Dict[str, Any]:
    """
    Gets a non initialized model with two sets of inputs and different shapes.

    :param batch_size: batch size
    :param kwargs: to overwrite the configuration, example ``num_hidden_layers=1``
    :return: dictionary

    See `Phi-3.5-mini-instruct/config.json
    <https://huggingface.co/microsoft/Phi-3.5-mini-instruct/blob/main/config.json>`_.
    """
    config = {
        "_name_or_path": "Phi-3.5-mini-instruct",
        "architectures": ["Phi3ForCausalLM"],
        "attention_dropout": 0.0,
        "auto_map": {
            "AutoConfig": "configuration_phi3.Phi3Config",
            "AutoModelForCausalLM": "modeling_phi3.Phi3ForCausalLM",
        },
        "bos_token_id": 1,
        "embd_pdrop": 0.0,
        "eos_token_id": 32000,
        "hidden_act": "silu",
        "hidden_size": 3072,
        "initializer_range": 0.02,
        "intermediate_size": 8192,
        "max_position_embeddings": 131072,
        "model_type": "phi3",
        "num_attention_heads": 32,
        "num_hidden_layers": 32,
        "num_key_value_heads": 32,
        "original_max_position_embeddings": 4096,
        "pad_token_id": 32000,
        "resid_pdrop": 0.0,
        "rms_norm_eps": 1e-05,
        "rope_scaling": {
            "long_factor": [
                1.0800000429153442,
                1.1100000143051147,
                1.1399999856948853,
                1.340000033378601,
                1.5899999141693115,
                1.600000023841858,
                1.6200000047683716,
                2.620000123977661,
                3.2300000190734863,
                3.2300000190734863,
                4.789999961853027,
                7.400000095367432,
                7.700000286102295,
                9.09000015258789,
                12.199999809265137,
                17.670000076293945,
                24.46000099182129,
                28.57000160217285,
                30.420001983642578,
                30.840002059936523,
                32.590003967285156,
                32.93000411987305,
                42.320003509521484,
                44.96000289916992,
                50.340003967285156,
                50.45000457763672,
                57.55000305175781,
                57.93000411987305,
                58.21000289916992,
                60.1400032043457,
                62.61000442504883,
                62.62000274658203,
                62.71000289916992,
                63.1400032043457,
                63.1400032043457,
                63.77000427246094,
                63.93000411987305,
                63.96000289916992,
                63.970001220703125,
                64.02999877929688,
                64.06999969482422,
                64.08000183105469,
                64.12000274658203,
                64.41000366210938,
                64.4800033569336,
                64.51000213623047,
                64.52999877929688,
                64.83999633789062,
            ],
            "short_factor": [
                1.0,
                1.0199999809265137,
                1.0299999713897705,
                1.0299999713897705,
                1.0499999523162842,
                1.0499999523162842,
                1.0499999523162842,
                1.0499999523162842,
                1.0499999523162842,
                1.0699999332427979,
                1.0999999046325684,
                1.1099998950958252,
                1.1599998474121094,
                1.1599998474121094,
                1.1699998378753662,
                1.2899998426437378,
                1.339999794960022,
                1.679999828338623,
                1.7899998426437378,
                1.8199998140335083,
                1.8499997854232788,
                1.8799997568130493,
                1.9099997282028198,
                1.9399996995925903,
                1.9899996519088745,
                2.0199997425079346,
                2.0199997425079346,
                2.0199997425079346,
                2.0199997425079346,
                2.0199997425079346,
                2.0199997425079346,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0299997329711914,
                2.0799996852874756,
                2.0899996757507324,
                2.189999580383301,
                2.2199995517730713,
                2.5899994373321533,
                2.729999542236328,
                2.749999523162842,
                2.8399994373321533,
            ],
            "type": "longrope",
        },
        "rope_theta": 10000.0,
        "sliding_window": 262144,
        "tie_word_embeddings": False,
        "torch_dtype": "bfloat16",
        "use_cache": True,
        "attention_bias": False,
        "vocab_size": 32064,
    }
    config.update(**kwargs)
    conf = transformers.Phi3Config(**config)
    model = transformers.Phi3ForCausalLM(conf)
    model.eval()

    cache = make_dynamic_cache(
        [
            (torch.randn(batch_size, 32, 30, 96), torch.randn(batch_size, 32, 30, 96))
            for i in range(config["num_hidden_layers"])
        ]
    )
    cache2 = make_dynamic_cache(
        [
            (torch.randn(batch_size + 1, 32, 31, 96), torch.randn(batch_size + 1, 32, 31, 96))
            for i in range(config["num_hidden_layers"])
        ]
    )

    inputs = dict(
        input_ids=torch.randint(0, 32064, (batch_size, 3)).to(torch.int64),
        attention_mask=torch.ones((batch_size, 33)).to(torch.int64),
        past_key_values=cache,
    )
    inputs2 = dict(
        input_ids=torch.randint(0, 32064, (batch_size + 1, 4)).to(torch.int64),
        attention_mask=torch.ones((batch_size + 1, 35)).to(torch.int64),
        past_key_values=cache2,
    )
    return dict(inputs=inputs, model=model, inputs2=inputs2)


data = get_phi35_untrained(num_hidden_layers=2)
model, inputs, inputs2 = data["model"], data["inputs"], data["inputs2"]

print(string_type(inputs, with_shape=True))
dict(input_ids:T7s2x3,attention_mask:T7s2x33,past_key_values:DynamicCache(key_cache=#2[T1s2x32x30x96,T1s2x32x30x96], value_cache=#2[T1s2x32x30x96,T1s2x32x30x96]))

Dynamic Shapes

We want to infer the dynamic shapes from the two sets of inputs we gave. For that, we use a function to trace the execution of the model including its submodules. It is going to execute the model twice with the two sets of inputs and stores every intermediate input and output.

[_trace_forward_execution] -trace-  M:__main__-Phi3ForCausalLM.forward
[_trace_forward_execution] -trace- .. M:model-Phi3Model.forward
[_trace_forward_execution] -trace- .... M:embed_tokens-Embedding.forward
[_trace_forward_execution] -trace- .... M:layers[0]-Phi3DecoderLayer.forward
[_trace_forward_execution] -trace- ...... M:self_attn-Phi3Attention.forward
[_trace_forward_execution] -trace- ........ M:o_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:qkv_proj-Linear.forward
[_trace_forward_execution] -trace- ...... M:mlp-Phi3MLP.forward
[_trace_forward_execution] -trace- ........ M:gate_up_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:down_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:activation_fn-SiLU.forward
[_trace_forward_execution] -trace- ...... M:input_layernorm-Phi3RMSNorm.forward
[_trace_forward_execution] -trace- ...... M:post_attention_layernorm-Phi3RMSNorm.forward
[_trace_forward_execution] -trace- ...... M:resid_attn_dropout-Dropout.forward
[_trace_forward_execution] -trace- ...... M:resid_mlp_dropout-Dropout.forward
[_trace_forward_execution] -trace- .... M:layers[1]-Phi3DecoderLayer.forward
[_trace_forward_execution] -trace- ...... M:self_attn-Phi3Attention.forward
[_trace_forward_execution] -trace- ........ M:o_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:qkv_proj-Linear.forward
[_trace_forward_execution] -trace- ...... M:mlp-Phi3MLP.forward
[_trace_forward_execution] -trace- ........ M:gate_up_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:down_proj-Linear.forward
[_trace_forward_execution] -trace- ........ M:activation_fn-SiLU.forward
[_trace_forward_execution] -trace- ...... M:input_layernorm-Phi3RMSNorm.forward
[_trace_forward_execution] -trace- ...... M:post_attention_layernorm-Phi3RMSNorm.forward
[_trace_forward_execution] -trace- ...... M:resid_attn_dropout-Dropout.forward
[_trace_forward_execution] -trace- ...... M:resid_mlp_dropout-Dropout.forward
[_trace_forward_execution] -trace- .... M:norm-Phi3RMSNorm.forward
[_trace_forward_execution] -trace- .... M:rotary_emb-Phi3RotaryEmbedding.forward
[_trace_forward_execution] -trace- .. M:lm_head-Linear.forward
[trace_execution_piece_by_piece] run with dict(args:(),kwargs:dict(input_ids:T7s2x3,attention_mask:T7s2x33,past_key_values:DynamicCache(key_cache=#2[T1s2x32x30x96,T1s2x32x30x96], value_cache=#2[T1s2x32x30x96,T1s2x32x30x96])))
[__main__:Phi3ForCausalLM] > **dict(input_ids:T7r2,attention_mask:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[model:Phi3Model]   > **dict(input_ids:T7r2,attention_mask:T7r2,position_ids:None,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),inputs_embeds:None,use_cache:None,cache_position:None)
[embed_tokens:Embedding]     > T7r2
[embed_tokens:Embedding]     < T1r3
[rotary_emb:Phi3RotaryEmbedding]     > *(T1r3,T7r2)
[rotary_emb:Phi3RotaryEmbedding]     < *(T1r3,T1r3)
[layers[0]:Phi3DecoderLayer]     > *(T1r3,), **dict(attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[input_layernorm:Phi3RMSNorm]       > T1r3
[input_layernorm:Phi3RMSNorm]       < T1r3
[self_attn:Phi3Attention]       > **dict(hidden_states:T1r3,attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[qkv_proj:Linear]         > T1r3
[qkv_proj:Linear]         < T1r3
[o_proj:Linear]         > T1r3
[o_proj:Linear]         < T1r3
[self_attn:Phi3Attention]       < *(T1r3,None)
[resid_attn_dropout:Dropout]       > T1r3
[resid_attn_dropout:Dropout]       < T1r3
[post_attention_layernorm:Phi3RMSNorm]       > T1r3
[post_attention_layernorm:Phi3RMSNorm]       < T1r3
[mlp:Phi3MLP]       > T1r3
[gate_up_proj:Linear]         > T1r3
[gate_up_proj:Linear]         < T1r3
[activation_fn:SiLU]         > T1r3
[activation_fn:SiLU]         < T1r3
[down_proj:Linear]         > T1r3
[down_proj:Linear]         < T1r3
[mlp:Phi3MLP]       < T1r3
[resid_mlp_dropout:Dropout]       > T1r3
[resid_mlp_dropout:Dropout]       < T1r3
[layers[0]:Phi3DecoderLayer]     < T1r3
[layers[1]:Phi3DecoderLayer]     > *(T1r3,), **dict(attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[input_layernorm:Phi3RMSNorm]       > T1r3
[input_layernorm:Phi3RMSNorm]       < T1r3
[self_attn:Phi3Attention]       > **dict(hidden_states:T1r3,attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[qkv_proj:Linear]         > T1r3
[qkv_proj:Linear]         < T1r3
[o_proj:Linear]         > T1r3
[o_proj:Linear]         < T1r3
[self_attn:Phi3Attention]       < *(T1r3,None)
[resid_attn_dropout:Dropout]       > T1r3
[resid_attn_dropout:Dropout]       < T1r3
[post_attention_layernorm:Phi3RMSNorm]       > T1r3
[post_attention_layernorm:Phi3RMSNorm]       < T1r3
[mlp:Phi3MLP]       > T1r3
[gate_up_proj:Linear]         > T1r3
[gate_up_proj:Linear]         < T1r3
[activation_fn:SiLU]         > T1r3
[activation_fn:SiLU]         < T1r3
[down_proj:Linear]         > T1r3
[down_proj:Linear]         < T1r3
[mlp:Phi3MLP]       < T1r3
[resid_mlp_dropout:Dropout]       > T1r3
[resid_mlp_dropout:Dropout]       < T1r3
[layers[1]:Phi3DecoderLayer]     < T1r3
[norm:Phi3RMSNorm]     > T1r3
[norm:Phi3RMSNorm]     < T1r3
[model:Phi3Model]   < *BaseModelOutputWithPast(last_hidden_state:T1r3,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[lm_head:Linear]   > T1r3
[lm_head:Linear]   < T1r3
[__main__:Phi3ForCausalLM] < *CausalLMOutputWithPast(logits:T1r3,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[trace_execution_piece_by_piece] run with dict(args:(),kwargs:dict(input_ids:T7s3x4,attention_mask:T7s3x35,past_key_values:DynamicCache(key_cache=#2[T1s3x32x31x96,T1s3x32x31x96], value_cache=#2[T1s3x32x31x96,T1s3x32x31x96])))
[__main__:Phi3ForCausalLM] > **dict(input_ids:T7r2,attention_mask:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[model:Phi3Model]   > **dict(input_ids:T7r2,attention_mask:T7r2,position_ids:None,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),inputs_embeds:None,use_cache:None,cache_position:None)
[embed_tokens:Embedding]     > T7r2
[embed_tokens:Embedding]     < T1r3
[rotary_emb:Phi3RotaryEmbedding]     > *(T1r3,T7r2)
[rotary_emb:Phi3RotaryEmbedding]     < *(T1r3,T1r3)
[layers[0]:Phi3DecoderLayer]     > *(T1r3,), **dict(attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[input_layernorm:Phi3RMSNorm]       > T1r3
[input_layernorm:Phi3RMSNorm]       < T1r3
[self_attn:Phi3Attention]       > **dict(hidden_states:T1r3,attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[qkv_proj:Linear]         > T1r3
[qkv_proj:Linear]         < T1r3
[o_proj:Linear]         > T1r3
[o_proj:Linear]         < T1r3
[self_attn:Phi3Attention]       < *(T1r3,None)
[resid_attn_dropout:Dropout]       > T1r3
[resid_attn_dropout:Dropout]       < T1r3
[post_attention_layernorm:Phi3RMSNorm]       > T1r3
[post_attention_layernorm:Phi3RMSNorm]       < T1r3
[mlp:Phi3MLP]       > T1r3
[gate_up_proj:Linear]         > T1r3
[gate_up_proj:Linear]         < T1r3
[activation_fn:SiLU]         > T1r3
[activation_fn:SiLU]         < T1r3
[down_proj:Linear]         > T1r3
[down_proj:Linear]         < T1r3
[mlp:Phi3MLP]       < T1r3
[resid_mlp_dropout:Dropout]       > T1r3
[resid_mlp_dropout:Dropout]       < T1r3
[layers[0]:Phi3DecoderLayer]     < T1r3
[layers[1]:Phi3DecoderLayer]     > *(T1r3,), **dict(attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[input_layernorm:Phi3RMSNorm]       > T1r3
[input_layernorm:Phi3RMSNorm]       < T1r3
[self_attn:Phi3Attention]       > **dict(hidden_states:T1r3,attention_mask:T9r4,position_ids:T7r2,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]),use_cache:bool,cache_position:T7r1,position_embeddings:(T1r3,T1r3))
[qkv_proj:Linear]         > T1r3
[qkv_proj:Linear]         < T1r3
[o_proj:Linear]         > T1r3
[o_proj:Linear]         < T1r3
[self_attn:Phi3Attention]       < *(T1r3,None)
[resid_attn_dropout:Dropout]       > T1r3
[resid_attn_dropout:Dropout]       < T1r3
[post_attention_layernorm:Phi3RMSNorm]       > T1r3
[post_attention_layernorm:Phi3RMSNorm]       < T1r3
[mlp:Phi3MLP]       > T1r3
[gate_up_proj:Linear]         > T1r3
[gate_up_proj:Linear]         < T1r3
[activation_fn:SiLU]         > T1r3
[activation_fn:SiLU]         < T1r3
[down_proj:Linear]         > T1r3
[down_proj:Linear]         < T1r3
[mlp:Phi3MLP]       < T1r3
[resid_mlp_dropout:Dropout]       > T1r3
[resid_mlp_dropout:Dropout]       < T1r3
[layers[1]:Phi3DecoderLayer]     < T1r3
[norm:Phi3RMSNorm]     > T1r3
[norm:Phi3RMSNorm]     < T1r3
[model:Phi3Model]   < *BaseModelOutputWithPast(last_hidden_state:T1r3,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[lm_head:Linear]   > T1r3
[lm_head:Linear]   < T1r3
[__main__:Phi3ForCausalLM] < *CausalLMOutputWithPast(logits:T1r3,past_key_values:DynamicCache(key_cache=#2[T1r4,T1r4], value_cache=#2[T1r4,T1r4]))
[trace_forward_execution] traced execution of model Phi3ForCausalLM
>>> __main__: Phi3ForCausalLM
  > ((),dict(input_ids:CT7s2x3[2403,22947:A14437.166666666666],attention_mask:CT7s2x33[1,1:A1.0],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x30x96[-4.7647504806518555,4.326326847076416:A-0.001722080717186526],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x30x96[-4.548426628112793,4.881927967071533:A0.0003073910505945829],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]])))
  > ((),dict(input_ids:CT7s3x4[293,28676:A10304.916666666666],attention_mask:CT7s3x35[1,1:A1.0],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x31x96[-4.452320575714111,4.482417583465576:A-0.001559309880017668],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x31x96[-4.542145729064941,4.456912517547607:A-0.0030504683372217373],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]])))
    >>> model: Phi3Model
      > ((),dict(input_ids:CT7s2x3[2403,22947:A14437.166666666666],attention_mask:CT7s2x33[1,1:A1.0],position_ids:None,past_key_values:DynamicCache(key_cache=#2[CT1s2x32x30x96[-4.7647504806518555,4.326326847076416:A-0.001722080717186526],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x30x96[-4.548426628112793,4.881927967071533:A0.0003073910505945829],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]]),inputs_embeds:None,use_cache:None,cache_position:None))
      > ((),dict(input_ids:CT7s3x4[293,28676:A10304.916666666666],attention_mask:CT7s3x35[1,1:A1.0],position_ids:None,past_key_values:DynamicCache(key_cache=#2[CT1s3x32x31x96[-4.452320575714111,4.482417583465576:A-0.001559309880017668],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x31x96[-4.542145729064941,4.456912517547607:A-0.0030504683372217373],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]]),inputs_embeds:None,use_cache:None,cache_position:None))
        >>> embed_tokens: Embedding
          > ((CT7s2x3[2403,22947:A14437.166666666666],),{})
          > ((CT7s3x4[293,28676:A10304.916666666666],),{})
          < (CT1s2x3x3072[-0.09113658964633942,0.07846815139055252:A0.0001063543325673254],)
          < (CT1s3x4x3072[-0.07859042286872864,0.08254141360521317:A3.3375873743218915e-05],)
        <<<
        >>> layers[0]: Phi3DecoderLayer
          > ((CT1s2x3x3072[-0.09113658964633942,0.07846815139055252:A0.0001063543325673254],),dict(attention_mask:CT9s2x1x3x33[False,True:A0.9696969696969697],position_ids:CT7s1x3[30,32:A31.0],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x30x96[-4.7647504806518555,4.326326847076416:A-0.001722080717186526],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x30x96[-4.548426628112793,4.881927967071533:A0.0003073910505945829],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]]),use_cache:bool=True,cache_position:CT7s3[30,32:A31.0],position_embeddings:(CT1s1x3x96[-1.1855769157409668,1.1902371644973755:A0.746652018013669],CT1s1x3x96[-1.1887905597686768,1.190193772315979:A0.1589894221542636])))
          > ((CT1s3x4x3072[-0.07859042286872864,0.08254141360521317:A3.3375873743218915e-05],),dict(attention_mask:CT9s3x1x4x35[False,True:A0.9571428571428572],position_ids:CT7s1x4[31,34:A32.5],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x31x96[-4.452320575714111,4.482417583465576:A-0.001559309880017668],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x31x96[-4.542145729064941,4.456912517547607:A-0.0030504683372217373],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]]),use_cache:bool=True,cache_position:CT7s4[31,34:A32.5],position_embeddings:(CT1s1x4x96[-1.1855769157409668,1.190237045288086:A0.7129333875218435],CT1s1x4x96[-1.1719439029693604,1.1902378797531128:A0.18296290554159592])))
            >>> self_attn: Phi3Attention
              > ((),dict(hidden_states:CT1s2x3x3072[-4.475774765014648,3.8882486820220947:A0.005292199028745238],attention_mask:CT9s2x1x3x33[False,True:A0.9696969696969697],position_ids:CT7s1x3[30,32:A31.0],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x30x96[-4.7647504806518555,4.326326847076416:A-0.001722080717186526],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x30x96[-4.548426628112793,4.881927967071533:A0.0003073910505945829],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]]),use_cache:bool=True,cache_position:CT7s3[30,32:A31.0],position_embeddings:(CT1s1x3x96[-1.1855769157409668,1.1902371644973755:A0.746652018013669],CT1s1x3x96[-1.1887905597686768,1.190193772315979:A0.1589894221542636])))
              > ((),dict(hidden_states:CT1s3x4x3072[-3.97863507270813,4.1487531661987305:A0.0016295695936815796],attention_mask:CT9s3x1x4x35[False,True:A0.9571428571428572],position_ids:CT7s1x4[31,34:A32.5],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x31x96[-4.452320575714111,4.482417583465576:A-0.001559309880017668],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x31x96[-4.542145729064941,4.456912517547607:A-0.0030504683372217373],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]]),use_cache:bool=True,cache_position:CT7s4[31,34:A32.5],position_embeddings:(CT1s1x4x96[-1.1855769157409668,1.190237045288086:A0.7129333875218435],CT1s1x4x96[-1.1719439029693604,1.1902378797531128:A0.18296290554159592])))
                >>> o_proj: Linear
                  > ((CT1s2x3x3072[-2.607111930847168,2.5028462409973145:A0.0013326045899440962],),{})
                  > ((CT1s3x4x3072[-2.2516562938690186,2.508760690689087:A-0.0013460123746205828],),{})
                  < (CT1s2x3x3072[-1.5050135850906372,1.5978435277938843:A6.181910379786536e-05],)
                  < (CT1s3x4x3072[-1.7758616209030151,1.6423643827438354:A-0.0006846549322827084],)
                <<<
                >>> qkv_proj: Linear
                  > ((CT1s2x3x3072[-4.475774765014648,3.8882486820220947:A0.005292199028745238],),{})
                  > ((CT1s3x4x3072[-3.97863507270813,4.1487531661987305:A0.0016295695936815796],),{})
                  < (CT1s2x3x9216[-4.65165376663208,4.48263692855835:A0.00893873230235495],)
                  < (CT1s3x4x9216[-4.677167892456055,4.812062740325928:A0.004314366191514999],)
                <<<
              < (CT1s2x3x3072[-1.5050135850906372,1.5978435277938843:A6.181910379786536e-05],None)
              < (CT1s3x4x3072[-1.7758616209030151,1.6423643827438354:A-0.0006846549322827084],None)
            <<<
            >>> mlp: Phi3MLP
              > ((CT1s2x3x3072[-3.8217215538024902,3.773453950881958:A0.00041085544137765676],),{})
              > ((CT1s3x4x3072[-4.458906173706055,4.132623672485352:A-0.002081313220717856],),{})
                >>> gate_up_proj: Linear
                  > ((CT1s2x3x3072[-3.8217215538024902,3.773453950881958:A0.00041085544137765676],),{})
                  > ((CT1s3x4x3072[-4.458906173706055,4.132623672485352:A-0.002081313220717856],),{})
                  < (CT1s2x3x16384[-4.654725074768066,5.2648444175720215:A-0.003493740328266881],)
                  < (CT1s3x4x16384[-5.03797721862793,5.321545124053955:A0.003880382759532471],)
                <<<
                >>> down_proj: Linear
                  > ((CT1s2x3x8192[-11.465274810791016,9.498729705810547:A0.00012709623044701723],),{})
                  > ((CT1s3x4x8192[-9.507513999938965,9.973529815673828:A0.0016182036223356486],),{})
                  < (CT1s2x3x3072[-5.428591728210449,5.4952239990234375:A0.004960005130745533],)
                  < (CT1s3x4x3072[-5.537304878234863,5.285183906555176:A-0.013518460757634583],)
                <<<
                >>> activation_fn: SiLU
                  > ((CT1s2x3x8192[-4.654725074768066,5.2648444175720215:A-0.0036314135868072603],),{})
                  > ((CT1s3x4x8192[-4.4807844161987305,5.279421329498291:A0.007534549275031092],),{})
                  < (CT1s2x3x8192[-0.27846455574035645,5.23776388168335:A0.24455918712864122],)
                  < (CT1s3x4x8192[-0.27846455574035645,5.252656936645508:A0.24915387332847708],)
                <<<
              < (CT1s2x3x3072[-5.428591728210449,5.4952239990234375:A0.004960005130745533],)
              < (CT1s3x4x3072[-5.537304878234863,5.285183906555176:A-0.013518460757634583],)
            <<<
            >>> input_layernorm: Phi3RMSNorm
              > ((CT1s2x3x3072[-0.09113658964633942,0.07846815139055252:A0.0001063543325673254],),{})
              > ((CT1s3x4x3072[-0.07859042286872864,0.08254141360521317:A3.3375873743218915e-05],),{})
              < (CT1s2x3x3072[-4.475774765014648,3.8882486820220947:A0.005292199028745238],)
              < (CT1s3x4x3072[-3.97863507270813,4.1487531661987305:A0.0016295695936815796],)
            <<<
            >>> post_attention_layernorm: Phi3RMSNorm
              > ((CT1s2x3x3072[-1.5011974573135376,1.6037862300872803:A0.00016817331233672425],),{})
              > ((CT1s3x4x3072[-1.7764862775802612,1.6384447813034058:A-0.0006512790718776134],),{})
              < (CT1s2x3x3072[-3.8217215538024902,3.773453950881958:A0.00041085544137765676],)
              < (CT1s3x4x3072[-4.458906173706055,4.132623672485352:A-0.002081313220717856],)
            <<<
            >>> resid_attn_dropout: Dropout
              > ((CT1s2x3x3072[-1.5050135850906372,1.5978435277938843:A6.181910379786536e-05],),{})
              > ((CT1s3x4x3072[-1.7758616209030151,1.6423643827438354:A-0.0006846549322827084],),{})
              < (CT1s2x3x3072[-1.5050135850906372,1.5978435277938843:A6.181910379786536e-05],)
              < (CT1s3x4x3072[-1.7758616209030151,1.6423643827438354:A-0.0006846549322827084],)
            <<<
            >>> resid_mlp_dropout: Dropout
              > ((CT1s2x3x3072[-5.428591728210449,5.4952239990234375:A0.004960005130745533],),{})
              > ((CT1s3x4x3072[-5.537304878234863,5.285183906555176:A-0.013518460757634583],),{})
              < (CT1s2x3x3072[-5.428591728210449,5.4952239990234375:A0.004960005130745533],)
              < (CT1s3x4x3072[-5.537304878234863,5.285183906555176:A-0.013518460757634583],)
            <<<
          < (CT1s2x3x3072[-6.028512001037598,5.5714616775512695:A0.005128178884004026],)
          < (CT1s3x4x3072[-6.216238975524902,5.675511360168457:A-0.014169739990923821],)
        <<<
        >>> layers[1]: Phi3DecoderLayer
          > ((CT1s2x3x3072[-6.028512001037598,5.5714616775512695:A0.005128178884004026],),dict(attention_mask:CT9s2x1x3x33[False,True:A0.9696969696969697],position_ids:CT7s1x3[30,32:A31.0],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x33x96[-5.582975387573242,5.157957077026367:A-0.0023727715634959874],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x33x96[-4.548426628112793,4.881927967071533:A0.0014194773832447469],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]]),use_cache:bool=True,cache_position:CT7s3[30,32:A31.0],position_embeddings:(CT1s1x3x96[-1.1855769157409668,1.1902371644973755:A0.746652018013669],CT1s1x3x96[-1.1887905597686768,1.190193772315979:A0.1589894221542636])))
          > ((CT1s3x4x3072[-6.216238975524902,5.675511360168457:A-0.014169739990923821],),dict(attention_mask:CT9s3x1x4x35[False,True:A0.9571428571428572],position_ids:CT7s1x4[31,34:A32.5],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x35x96[-5.857463836669922,5.373706817626953:A-0.0013941143444751198],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x35x96[-4.542145729064941,4.812062740325928:A-0.0009732793747610155],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]]),use_cache:bool=True,cache_position:CT7s4[31,34:A32.5],position_embeddings:(CT1s1x4x96[-1.1855769157409668,1.190237045288086:A0.7129333875218435],CT1s1x4x96[-1.1719439029693604,1.1902378797531128:A0.18296290554159592])))
            >>> self_attn: Phi3Attention
              > ((),dict(hidden_states:CT1s2x3x3072[-4.243993282318115,3.93839955329895:A0.0035574824090930934],attention_mask:CT9s2x1x3x33[False,True:A0.9696969696969697],position_ids:CT7s1x3[30,32:A31.0],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x33x96[-5.582975387573242,5.157957077026367:A-0.0023727715634959874],CT1s2x32x30x96[-4.373596668243408,4.8538689613342285:A0.001473652380700859]], value_cache=#2[CT1s2x32x33x96[-4.548426628112793,4.881927967071533:A0.0014194773832447469],CT1s2x32x30x96[-5.35287618637085,4.31292724609375:A0.000841141901664096]]),use_cache:bool=True,cache_position:CT7s3[30,32:A31.0],position_embeddings:(CT1s1x3x96[-1.1855769157409668,1.1902371644973755:A0.746652018013669],CT1s1x3x96[-1.1887905597686768,1.190193772315979:A0.1589894221542636])))
              > ((),dict(hidden_states:CT1s3x4x3072[-4.5129241943359375,4.002876281738281:A-0.01007803847878345],attention_mask:CT9s3x1x4x35[False,True:A0.9571428571428572],position_ids:CT7s1x4[31,34:A32.5],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x35x96[-5.857463836669922,5.373706817626953:A-0.0013941143444751198],CT1s3x32x31x96[-4.328837871551514,4.748230934143066:A0.002522062806768854]], value_cache=#2[CT1s3x32x35x96[-4.542145729064941,4.812062740325928:A-0.0009732793747610155],CT1s3x32x31x96[-4.204125881195068,4.507618427276611:A0.002002391075485834]]),use_cache:bool=True,cache_position:CT7s4[31,34:A32.5],position_embeddings:(CT1s1x4x96[-1.1855769157409668,1.190237045288086:A0.7129333875218435],CT1s1x4x96[-1.1719439029693604,1.1902378797531128:A0.18296290554159592])))
                >>> o_proj: Linear
                  > ((CT1s2x3x3072[-3.1271181106567383,2.176844596862793:A0.0033640535202859433],),{})
                  > ((CT1s3x4x3072[-2.242114782333374,2.4049391746520996:A0.0022721900967497513],),{})
                  < (CT1s2x3x3072[-1.7004780769348145,1.5964746475219727:A0.0023179412031974302],)
                  < (CT1s3x4x3072[-1.5253567695617676,1.974783182144165:A-0.002659913608239448],)
                <<<
                >>> qkv_proj: Linear
                  > ((CT1s2x3x3072[-4.243993282318115,3.93839955329895:A0.0035574824090930934],),{})
                  > ((CT1s3x4x3072[-4.5129241943359375,4.002876281738281:A-0.01007803847878345],),{})
                  < (CT1s2x3x9216[-5.564769268035889,4.401213645935059:A0.009032221765210124],)
                  < (CT1s3x4x9216[-4.9568190574646,4.798978328704834:A0.003018803876607813],)
                <<<
              < (CT1s2x3x3072[-1.7004780769348145,1.5964746475219727:A0.0023179412031974302],None)
              < (CT1s3x4x3072[-1.5253567695617676,1.974783182144165:A-0.002659913608239448],None)
            <<<
            >>> mlp: Phi3MLP
              > ((CT1s2x3x3072[-3.9816975593566895,4.034908294677734:A0.0050716255979779135],),{})
              > ((CT1s3x4x3072[-4.408154487609863,4.054455280303955:A-0.011511877522447497],),{})
                >>> gate_up_proj: Linear
                  > ((CT1s2x3x3072[-3.9816975593566895,4.034908294677734:A0.0050716255979779135],),{})
                  > ((CT1s3x4x3072[-4.408154487609863,4.054455280303955:A-0.011511877522447497],),{})
                  < (CT1s2x3x16384[-5.366240978240967,4.421708583831787:A-0.0006165251856889616],)
                  < (CT1s3x4x16384[-4.919360637664795,5.474978446960449:A3.027062568368895e-05],)
                <<<
                >>> down_proj: Linear
                  > ((CT1s2x3x8192[-10.039819717407227,9.580595970153809:A-0.0028928588909338817],),{})
                  > ((CT1s3x4x8192[-14.281769752502441,9.475939750671387:A-0.003135237573787933],),{})
                  < (CT1s2x3x3072[-5.2242112159729,5.372959136962891:A0.008317143982923072],)
                  < (CT1s3x4x3072[-6.243739128112793,5.191996097564697:A0.010033387659228133],)
                <<<
                >>> activation_fn: SiLU
                  > ((CT1s2x3x8192[-4.4982428550720215,4.369277477264404:A-0.0017728366598817047],),{})
                  > ((CT1s3x4x8192[-4.919360637664795,5.474978446960449:A6.222506113336597e-06],),{})
                  < (CT1s2x3x8192[-0.27846455574035645,4.314652442932129:A0.24433904846600937],)
                  < (CT1s3x4x8192[-0.27846455574035645,5.452132225036621:A0.24430044279650295],)
                <<<
              < (CT1s2x3x3072[-5.2242112159729,5.372959136962891:A0.008317143982923072],)
              < (CT1s3x4x3072[-6.243739128112793,5.191996097564697:A0.010033387659228133],)
            <<<
            >>> input_layernorm: Phi3RMSNorm
              > ((CT1s2x3x3072[-6.028512001037598,5.5714616775512695:A0.005128178884004026],),{})
              > ((CT1s3x4x3072[-6.216238975524902,5.675511360168457:A-0.014169739990923821],),{})
              < (CT1s2x3x3072[-4.243993282318115,3.93839955329895:A0.0035574824090930934],)
              < (CT1s3x4x3072[-4.5129241943359375,4.002876281738281:A-0.01007803847878345],)
            <<<
            >>> post_attention_layernorm: Phi3RMSNorm
              > ((CT1s2x3x3072[-5.876540660858154,5.89663028717041:A0.00744612014103849],),{})
              > ((CT1s3x4x3072[-6.288590908050537,6.0020036697387695:A-0.01682965380971129],),{})
              < (CT1s2x3x3072[-3.9816975593566895,4.034908294677734:A0.0050716255979779135],)
              < (CT1s3x4x3072[-4.408154487609863,4.054455280303955:A-0.011511877522447497],)
            <<<
            >>> resid_attn_dropout: Dropout
              > ((CT1s2x3x3072[-1.7004780769348145,1.5964746475219727:A0.0023179412031974302],),{})
              > ((CT1s3x4x3072[-1.5253567695617676,1.974783182144165:A-0.002659913608239448],),{})
              < (CT1s2x3x3072[-1.7004780769348145,1.5964746475219727:A0.0023179412031974302],)
              < (CT1s3x4x3072[-1.5253567695617676,1.974783182144165:A-0.002659913608239448],)
            <<<
            >>> resid_mlp_dropout: Dropout
              > ((CT1s2x3x3072[-5.2242112159729,5.372959136962891:A0.008317143982923072],),{})
              > ((CT1s3x4x3072[-6.243739128112793,5.191996097564697:A0.010033387659228133],),{})
              < (CT1s2x3x3072[-5.2242112159729,5.372959136962891:A0.008317143982923072],)
              < (CT1s3x4x3072[-6.243739128112793,5.191996097564697:A0.010033387659228133],)
            <<<
          < (CT1s2x3x3072[-8.19876480102539,7.276418209075928:A0.015763263898204767],)
          < (CT1s3x4x3072[-8.007987022399902,7.789109230041504:A-0.006796266478583372],)
        <<<
        >>> norm: Phi3RMSNorm
          > ((CT1s2x3x3072[-8.19876480102539,7.276418209075928:A0.015763263898204767],),{})
          > ((CT1s3x4x3072[-8.007987022399902,7.789109230041504:A-0.006796266478583372],),{})
          < (CT1s2x3x3072[-4.1952948570251465,3.695281744003296:A0.00790044601701899],)
          < (CT1s3x4x3072[-3.9736742973327637,3.9668688774108887:A-0.0033651734585956974],)
        <<<
        >>> rotary_emb: Phi3RotaryEmbedding
          > ((CT1s2x3x3072[-0.09113658964633942,0.07846815139055252:A0.0001063543325673254],CT7s1x3[30,32:A31.0]),{})
          > ((CT1s3x4x3072[-0.07859042286872864,0.08254141360521317:A3.3375873743218915e-05],CT7s1x4[31,34:A32.5]),{})
          < (CT1s1x3x96[-1.1855769157409668,1.1902371644973755:A0.746652018013669],CT1s1x3x96[-1.1887905597686768,1.190193772315979:A0.1589894221542636])
          < (CT1s1x4x96[-1.1855769157409668,1.190237045288086:A0.7129333875218435],CT1s1x4x96[-1.1719439029693604,1.1902378797531128:A0.18296290554159592])
        <<<
      < (dict(last_hidden_state:CT1s2x3x3072[-4.1952948570251465,3.695281744003296:A0.00790044601701899],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x33x96[-5.582975387573242,5.157957077026367:A-0.0023727715634959874],CT1s2x32x33x96[-5.53786563873291,5.209494113922119:A0.0029642835425337352]], value_cache=#2[CT1s2x32x33x96[-4.548426628112793,4.881927967071533:A0.0014194773832447469],CT1s2x32x33x96[-5.564769268035889,4.401213645935059:A0.0009700510000091704]])),)
      < (dict(last_hidden_state:CT1s3x4x3072[-3.9736742973327637,3.9668688774108887:A-0.0033651734585956974],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x35x96[-5.857463836669922,5.373706817626953:A-0.0013941143444751198],CT1s3x32x35x96[-5.200832366943359,5.753454208374023:A0.0017684643389397157]], value_cache=#2[CT1s3x32x35x96[-4.542145729064941,4.812062740325928:A-0.0009732793747610155],CT1s3x32x35x96[-4.9568190574646,4.550383567810059:A0.0023251130318532407]])),)
    <<<
    >>> lm_head: Linear
      > ((CT1s2x3x3072[-4.1952948570251465,3.695281744003296:A0.00790044601701899],),{})
      > ((CT1s3x4x3072[-3.9736742973327637,3.9668688774108887:A-0.0033651734585956974],),{})
      < (CT1s2x3x32064[-4.951185703277588,5.317477703094482:A-0.0012874784351682835],)
      < (CT1s3x4x32064[-4.86270809173584,5.156239986419678:A0.0033525281002737134],)
    <<<
  < (dict(logits:CT1s2x3x32064[-4.951185703277588,5.317477703094482:A-0.0012874784351682835],past_key_values:DynamicCache(key_cache=#2[CT1s2x32x33x96[-5.582975387573242,5.157957077026367:A-0.0023727715634959874],CT1s2x32x33x96[-5.53786563873291,5.209494113922119:A0.0029642835425337352]], value_cache=#2[CT1s2x32x33x96[-4.548426628112793,4.881927967071533:A0.0014194773832447469],CT1s2x32x33x96[-5.564769268035889,4.401213645935059:A0.0009700510000091704]])),)
  < (dict(logits:CT1s3x4x32064[-4.86270809173584,5.156239986419678:A0.0033525281002737134],past_key_values:DynamicCache(key_cache=#2[CT1s3x32x35x96[-5.857463836669922,5.373706817626953:A-0.0013941143444751198],CT1s3x32x35x96[-5.200832366943359,5.753454208374023:A0.0017684643389397157]], value_cache=#2[CT1s3x32x35x96[-4.542145729064941,4.812062740325928:A-0.0009732793747610155],CT1s3x32x35x96[-4.9568190574646,4.550383567810059:A0.0023251130318532407]])),)
<<<
[_untrace_forward_execution]  M:__main__-Phi3ForCausalLM
[_untrace_forward_execution] .. M:model-Phi3Model
[_untrace_forward_execution] .... M:embed_tokens-Embedding
[_untrace_forward_execution] .... M:layers[0]-Phi3DecoderLayer
[_untrace_forward_execution] ...... M:self_attn-Phi3Attention
[_untrace_forward_execution] ........ M:o_proj-Linear
[_untrace_forward_execution] ........ M:qkv_proj-Linear
[_untrace_forward_execution] ...... M:mlp-Phi3MLP
[_untrace_forward_execution] ........ M:gate_up_proj-Linear
[_untrace_forward_execution] ........ M:down_proj-Linear
[_untrace_forward_execution] ........ M:activation_fn-SiLU
[_untrace_forward_execution] ...... M:input_layernorm-Phi3RMSNorm
[_untrace_forward_execution] ...... M:post_attention_layernorm-Phi3RMSNorm
[_untrace_forward_execution] ...... M:resid_attn_dropout-Dropout
[_untrace_forward_execution] ...... M:resid_mlp_dropout-Dropout
[_untrace_forward_execution] .... M:layers[1]-Phi3DecoderLayer
[_untrace_forward_execution] ...... M:self_attn-Phi3Attention
[_untrace_forward_execution] ........ M:o_proj-Linear
[_untrace_forward_execution] ........ M:qkv_proj-Linear
[_untrace_forward_execution] ...... M:mlp-Phi3MLP
[_untrace_forward_execution] ........ M:gate_up_proj-Linear
[_untrace_forward_execution] ........ M:down_proj-Linear
[_untrace_forward_execution] ........ M:activation_fn-SiLU
[_untrace_forward_execution] ...... M:input_layernorm-Phi3RMSNorm
[_untrace_forward_execution] ...... M:post_attention_layernorm-Phi3RMSNorm
[_untrace_forward_execution] ...... M:resid_attn_dropout-Dropout
[_untrace_forward_execution] ...... M:resid_mlp_dropout-Dropout
[_untrace_forward_execution] .... M:norm-Phi3RMSNorm
[_untrace_forward_execution] .... M:rotary_emb-Phi3RotaryEmbedding
[_untrace_forward_execution] .. M:lm_head-Linear

Now we keep in memory every input/output for the submodules, we can guess the dynamic shapes for every of them. The final ones:

The dynamic shapes are:
((),
 {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                 min=None,
                                 max=None,
                                 _factory=True),
                     1: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                 min=None,
                                 max=None,
                                 _factory=True)},
  'input_ids': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                            min=None,
                            max=None,
                            _factory=True),
                1: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                            min=None,
                            max=None,
                            _factory=True)},
  'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True),
                        2: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True)},
                       {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True),
                        2: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True)}],
                      [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True),
                        2: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True)},
                       {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True),
                        2: _DimHint(type=<_DimHintType.DYNAMIC: 3>,
                                    min=None,
                                    max=None,
                                    _factory=True)}]]})

And all the dynamic shapes all along the traced submodules.

print(
    diag.pretty_text(
        with_dynamic_shape=True,
        with_shape=False,
        with_min_max=False,
        with_device=False,
        with_inputs=False,
    ).replace("<_DimHint.DYNAMIC: 3>", "DYN")
)
>>> __main__: Phi3ForCausalLM
  DS=((), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'input_ids': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]]})
    >>> model: Phi3Model
      DS=((), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'cache_position': None, 'input_ids': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'inputs_embeds': None, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]], 'position_ids': None, 'use_cache': None})
        >>> embed_tokens: Embedding: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
        >>> layers[0]: Phi3DecoderLayer
          DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 3: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'cache_position': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]], 'position_embeddings': ({1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}), 'position_ids': {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'use_cache': None})
            >>> self_attn: Phi3Attention
              DS=((), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 3: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'cache_position': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'hidden_states': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]], 'position_embeddings': ({1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}), 'position_ids': {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'use_cache': None})
                >>> o_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> qkv_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            <<<
            >>> mlp: Phi3MLP
              DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {})
                >>> gate_up_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> down_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> activation_fn: SiLU: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            <<<
            >>> input_layernorm: Phi3RMSNorm: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> post_attention_layernorm: Phi3RMSNorm: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> resid_attn_dropout: Dropout: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> resid_mlp_dropout: Dropout: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
        <<<
        >>> layers[1]: Phi3DecoderLayer
          DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 3: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'cache_position': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]], 'position_embeddings': ({1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}), 'position_ids': {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'use_cache': None})
            >>> self_attn: Phi3Attention
              DS=((), {'attention_mask': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 3: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'cache_position': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'hidden_states': {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'past_key_values': [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]], 'position_embeddings': ({1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}), 'position_ids': {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, 'use_cache': None})
                >>> o_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> qkv_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            <<<
            >>> mlp: Phi3MLP
              DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {})
                >>> gate_up_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> down_proj: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
                >>> activation_fn: SiLU: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            <<<
            >>> input_layernorm: Phi3RMSNorm: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> post_attention_layernorm: Phi3RMSNorm: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> resid_attn_dropout: Dropout: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
            >>> resid_mlp_dropout: Dropout: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
        <<<
        >>> norm: Phi3RMSNorm: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
        >>> rotary_emb: Phi3RotaryEmbedding: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}), {}) <<<
    <<<
    >>> lm_head: Linear: DS=(({0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 1: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)},), {}) <<<
<<<

Evaluate the export

In many cases, the export (to torch.fx.Graph, to ONNX) does not work on the first try. We need a way to understand how much the model can be exported. It can be used to evaluate the how much code needs to be rewritten or patched to be exportable. The verbosity can be increase to show dynamic shapes, results of the discrepancies. Let’s display the module and its submodule first.

print(
    diag.pretty_text(
        with_dynamic_shape=False,
        with_shape=False,
        with_min_max=False,
        with_device=False,
        with_inputs=False,
    )
)
>>> __main__: Phi3ForCausalLM
    >>> model: Phi3Model
        >>> embed_tokens: Embedding <<<
        >>> layers[0]: Phi3DecoderLayer
            >>> self_attn: Phi3Attention
                >>> o_proj: Linear <<<
                >>> qkv_proj: Linear <<<
            <<<
            >>> mlp: Phi3MLP
                >>> gate_up_proj: Linear <<<
                >>> down_proj: Linear <<<
                >>> activation_fn: SiLU <<<
            <<<
            >>> input_layernorm: Phi3RMSNorm <<<
            >>> post_attention_layernorm: Phi3RMSNorm <<<
            >>> resid_attn_dropout: Dropout <<<
            >>> resid_mlp_dropout: Dropout <<<
        <<<
        >>> layers[1]: Phi3DecoderLayer
            >>> self_attn: Phi3Attention
                >>> o_proj: Linear <<<
                >>> qkv_proj: Linear <<<
            <<<
            >>> mlp: Phi3MLP
                >>> gate_up_proj: Linear <<<
                >>> down_proj: Linear <<<
                >>> activation_fn: SiLU <<<
            <<<
            >>> input_layernorm: Phi3RMSNorm <<<
            >>> post_attention_layernorm: Phi3RMSNorm <<<
            >>> resid_attn_dropout: Dropout <<<
            >>> resid_mlp_dropout: Dropout <<<
        <<<
        >>> norm: Phi3RMSNorm <<<
        >>> rotary_emb: Phi3RotaryEmbedding <<<
    <<<
    >>> lm_head: Linear <<<
<<<

The we try to export to see the submodule failing the whole model. We can pickle the failing model and restore it to speedup the refactoring to make it work.

print("----------------------")
ep = diag.try_export(
    exporter="fx",
    use_dynamic_shapes=True,
    exporter_kwargs=dict(strict=False),
    verbose=1,
)
----------------------

[try_export-FX]  M:__main__-Phi3ForCausalLM --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] .. M:model-Phi3Model --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] .... M:embed_tokens-Embedding --- OK:
[try_export-FX] .... M:layers[0]-Phi3DecoderLayer --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] ...... M:self_attn-Phi3Attention --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] ........ M:o_proj-Linear --- OK:
[try_export-FX] ........ M:qkv_proj-Linear --- OK:
[try_export-FX] ...... M:mlp-Phi3MLP --- OK:
[try_export-FX] ...... M:input_layernorm-Phi3RMSNorm --- OK:
[try_export-FX] ...... M:post_attention_layernorm-Phi3RMSNorm --- OK:
[try_export-FX] ...... M:resid_attn_dropout-Dropout --- OK:
[try_export-FX] ...... M:resid_mlp_dropout-Dropout --- OK:
[try_export-FX] .... M:layers[1]-Phi3DecoderLayer --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] ...... M:self_attn-Phi3Attention --- FAIL, step=EXPORT, reason=Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None) --- For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1969, in _non_strict_export\n    ) = make_fake_inputs(\n        ^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 356, in make_fake_inputs\n    _check_dynamic_shapes(combined_args, dynamic_shapes)\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1031, in _check_dynamic_shapes\n    _tree_map_with_path(check_shape, combined_args, dynamic_shapes, tree_name="inputs")\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 614, in _tree_map_with_path\n    return tree_map_with_path(f, tree, *dynamic_shapes, is_leaf=is_leaf)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in tree_map_with_path\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 1193, in unflatten\n    leaves = list(leaves)\n             ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_pytree.py", line 2056, in <genexpr>\n    return treespec.unflatten(func(*xs) for xs in zip(*all_keypath_leaves))\n                              ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 611, in f\n    return func(path, t, *dynamic_shapes)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/dynamic_shapes.py", line 1024, in check_shape\n    raise UserError(\n', "torch._dynamo.exc.UserError: Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}], [{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}, {0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True), 2: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=True)}]] specified at `dynamic_shapes['past_key_values']` to non-tensor type <class 'transformers.cache_utils.DynamicCache'> at `inputs['past_key_values']` (expected None)\nFor more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#dynamic-shapes-validation\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n"]
[try_export-FX] ........ M:o_proj-Linear --- OK:
[try_export-FX] ........ M:qkv_proj-Linear --- OK:
[try_export-FX] ...... M:mlp-Phi3MLP --- OK:
[try_export-FX] ...... M:input_layernorm-Phi3RMSNorm --- OK:
[try_export-FX] ...... M:post_attention_layernorm-Phi3RMSNorm --- OK:
[try_export-FX] ...... M:resid_attn_dropout-Dropout --- OK:
[try_export-FX] ...... M:resid_mlp_dropout-Dropout --- OK:
[try_export-FX] .... M:norm-Phi3RMSNorm --- OK:



def forward(self, arg0_1: "f32[48]", arg1_1: "f32[s77, s27, 3072]", arg2_1: "i64[1, s9]"):
    # No stacktrace found for following nodes
    _set_grad_enabled = torch._C._set_grad_enabled(False);  _set_grad_enabled = None
    max_1: "i64[]" = torch.ops.aten.max.default(arg2_1);  arg2_1 = None
    add: "i64[]" = torch.ops.aten.add.Tensor(max_1, 1);  max_1 = None
    gt: "b8[]" = torch.ops.aten.gt.Scalar(add, 4096);  add = None
    ne: "b8[]" = torch.ops.aten.ne.Scalar(gt, 0);  gt = None
    item: "Sym(Eq(u0, 1))" = torch.ops.aten.item.default(ne);  ne = item = None
    _set_grad_enabled_1 = torch._C._set_grad_enabled(True);  _set_grad_enabled_1 = None




def forward(self, arg0_1: "f32[48]", arg1_1: "f32[s77, s27, 3072]", arg2_1: "i64[1, s9]"):
    # No stacktrace found for following nodes
    _set_grad_enabled = torch._C._set_grad_enabled(False);  _set_grad_enabled = None
    max_1: "i64[]" = torch.ops.aten.max.default(arg2_1);  arg2_1 = None
    add: "i64[]" = torch.ops.aten.add.Tensor(max_1, 1);  max_1 = None
    gt: "b8[]" = torch.ops.aten.gt.Scalar(add, 4096);  add = None
    ne: "b8[]" = torch.ops.aten.ne.Scalar(gt, 0);  gt = None
    item: "Sym(Eq(u0, 1))" = torch.ops.aten.item.default(ne);  ne = item = None
    _set_grad_enabled_1 = torch._C._set_grad_enabled(True);  _set_grad_enabled_1 = None

[try_export-FX] .... M:rotary_emb-Phi3RotaryEmbedding --- FAIL, step=EXPORT, reason=Could not guard on data-dependent expression Eq(u0, 1) (unhinted: Eq(u0, 1)).  (Size-like symbols: none) ---  --- consider using data-dependent friendly APIs such as guard_or_false, guard_or_true and statically_known_trueCaused by: (_export/non_strict_utils.py:1066 in __torch_function__) --- For more information, run with TORCH_LOGS="dynamic" --- For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0" --- If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1 --- For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing ---  --- For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1 ---  --- The following call raised this error: ---   File "~/github/transformers/src/transformers/modeling_rope_utils.py", line 50, in longrope_frequency_update ---     if seq_len > original_max_position_embeddings: ---  ---  --- The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.['Traceback (most recent call last):\n', '  File "~/github/experimental-experiment/experimental_experiment/torch_interpreter/piece_by_piece.py", line 1601, in _try_export_no_bypass_export\n    ep = torch.export.export(\n         ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 315, in export\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/__init__.py", line 280, in export\n    return _export(\n           ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2275, in _export\n    ep = _export_for_training(\n         ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1173, in wrapper\n    raise e\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1139, in wrapper\n    ep = fn(*args, **kwargs)\n         ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2090, in _export_for_training\n    export_artifact = export_func(\n                      ^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 2014, in _non_strict_export\n    aten_export_artifact = _to_aten_func(  # type: ignore[operator]\n                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1805, in _export_to_aten_ir_make_fx\n    gm, graph_signature = transform(_make_fx_helper)(\n                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1934, in _aot_export_non_strict\n    gm, sig = aot_export(wrapped_mod, args, kwargs=kwargs, **flags)\n              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1718, in _make_fx_helper\n    gm = make_fx(\n         ^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2429, in wrapped\n    return make_fx_tracer.trace(f, *args)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2356, in trace\n    return self._trace_inner(f, *args)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2318, in _trace_inner\n    t = dispatch_trace(\n        ^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_compile.py", line 53, in inner\n    return disable_fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_dynamo/eval_frame.py", line 1099, in _fn\n    return fn(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1303, in dispatch_trace\n    graph = tracer.trace(root, concrete_args)  # type: ignore[arg-type]\n            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1908, in trace\n    res = super().trace(root, concrete_args)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 868, in trace\n    (self.create_arg(fn(*args)),),\n                     ^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1361, in wrapped\n    out = f(*tensors)  # type:ignore[call-arg]\n          ^^^^^^^^^^^\n', '  File "<string>", line 1, in <lambda>\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1605, in wrapped_fn\n    return tuple(flat_fn(*args))\n                 ^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_functorch/_aot_autograd/utils.py", line 187, in flat_fn\n    tree_out = fn(*args, **kwargs)\n               ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_functorch/_aot_autograd/graph_capture_wrappers.py", line 1354, in functional_call\n    out = mod(*args[params_len:], **kwargs)\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 843, in module_call_wrapper\n    return self.call_module(mod, forward, args, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1997, in call_module\n    return Tracer.call_module(self, m, forward, args, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 560, in call_module\n    ret_val = forward(*args, **kwargs)\n              ^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 836, in forward\n    return _orig_module_call(mod, *args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl\n    return self._call_impl(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl\n    return forward_call(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/export/_trace.py", line 1918, in forward\n    tree_out = mod(*args, **kwargs)\n               ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 843, in module_call_wrapper\n    return self.call_module(mod, forward, args, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1997, in call_module\n    return Tracer.call_module(self, m, forward, args, kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 560, in call_module\n    ret_val = forward(*args, **kwargs)\n              ^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 836, in forward\n    return _orig_module_call(mod, *args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1775, in _wrapped_call_impl\n    return self._call_impl(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1786, in _call_impl\n    return forward_call(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/github/transformers/src/transformers/modeling_rope_utils.py", line 86, in wrapper\n    longrope_frequency_update(self, position_ids, device=x.device)\n', '  File "~/github/transformers/src/transformers/modeling_rope_utils.py", line 50, in longrope_frequency_update\n    if seq_len > original_max_position_embeddings:\n       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1409, in __torch_function__\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1479, in __torch_function__\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/_export/non_strict_utils.py", line 1066, in __torch_function__\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/sym_node.py", line 538, in guard_bool\n    r = self.evaluate()\n        ^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/sym_node.py", line 512, in evaluate\n    return self.shape_env.evaluate_sym_node(self, size_oblivious)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/symbolic_shapes.py", line 7244, in evaluate_sym_node\n    return self.evaluate_expr(\n           ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/symbolic_shapes.py", line 7344, in evaluate_expr\n    return self._inner_evaluate_expr(\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/recording.py", line 272, in wrapper\n    return retlog(fn(*args, **kwargs))\n                  ^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/symbolic_shapes.py", line 7367, in _inner_evaluate_expr\n    return self._evaluate_expr(\n           ^^^^^^^^^^^^^^^^^^^^\n', '  File "~/vv/this312/lib/python3.12/site-packages/torch/fx/experimental/symbolic_shapes.py", line 7585, in _evaluate_expr\n    raise self._make_data_dependent_error(\n', 'torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode: Could not guard on data-dependent expression Eq(u0, 1) (unhinted: Eq(u0, 1)).  (Size-like symbols: none)\n\nconsider using data-dependent friendly APIs such as guard_or_false, guard_or_true and statically_known_trueCaused by: (_export/non_strict_utils.py:1066 in __torch_function__)\nFor more information, run with TORCH_LOGS="dynamic"\nFor extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0"\nIf you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1\nFor more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing\n\nFor C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1\n\nThe following call raised this error:\n  File "~/github/transformers/src/transformers/modeling_rope_utils.py", line 50, in longrope_frequency_update\n    if seq_len > original_max_position_embeddings:\n\n\nThe error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your `export()` call with `draft_export()`.\n']
[try_export-FX] .... M:rotary_emb-Phi3RotaryEmbedding --- FAIL: Could not guard on data-depend...
[try_export-FX] .. M:lm_head-Linear --- OK:

Let’s display a report.

print(f"success: {ep.status}")
print(diag.get_export_report())
success: 2
__main__                         Phi3ForCausalLM       FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
..model                          Phi3Model             FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
....embed_tokens                 Embedding             OK -- ExportedProgram
....layers[0]                    Phi3DecoderLayer      FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
......self_attn                  Phi3Attention         FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
........o_proj                   Linear                OK -- ExportedProgram
........qkv_proj                 Linear                OK -- ExportedProgram
......mlp                        Phi3MLP               OK -- ExportedProgram
........gate_up_proj             Linear                <OK-2i-0>
........down_proj                Linear                <OK-2i-0>
........activation_fn            SiLU                  <OK-2i-0>
......input_layernorm            Phi3RMSNorm           OK -- ExportedProgram
......post_attention_layernorm   Phi3RMSNorm           OK -- ExportedProgram
......resid_attn_dropout         Dropout               OK -- ExportedProgram
......resid_mlp_dropout          Dropout               OK -- ExportedProgram
....layers[1]                    Phi3DecoderLayer      FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
......self_attn                  Phi3Attention         FAIL -- step=EXPORT, reason='Cannot associate shape [[{0: _DimHint(type=<_DimHintType.DYNAMIC: 3>, min=None, max=None, _factory=T...'
........o_proj                   Linear                OK -- ExportedProgram
........qkv_proj                 Linear                OK -- ExportedProgram
......mlp                        Phi3MLP               OK -- ExportedProgram
........gate_up_proj             Linear                <OK-2i-0>
........down_proj                Linear                <OK-2i-0>
........activation_fn            SiLU                  <OK-2i-0>
......input_layernorm            Phi3RMSNorm           OK -- ExportedProgram
......post_attention_layernorm   Phi3RMSNorm           OK -- ExportedProgram
......resid_attn_dropout         Dropout               OK -- ExportedProgram
......resid_mlp_dropout          Dropout               OK -- ExportedProgram
....norm                         Phi3RMSNorm           OK -- ExportedProgram
....rotary_emb                   Phi3RotaryEmbedding   FAIL -- step=EXPORT, reason='Could not guard on data-dependent expression Eq(u0, 1) (unhinted: Eq(u0, 1)).  (Size-like symbols: n...'
..lm_head                        Linear                OK -- ExportedProgram

Replace the failing module by a custom op

The main module is not exportable because one piece cannot be exported. But maybe if we assume it works, maybe everything else is working. So let’s try to replace this class by a custom op. This will be something for another example.

Total running time of the script: (0 minutes 8.584 seconds)

Related examples

Export Phi-3.5-mini-instruct with report_exportability

Export Phi-3.5-mini-instruct with report_exportability

Export Phi-3.5-mini-instruct with draft_export

Export Phi-3.5-mini-instruct with draft_export

to_onnx and submodules from LLMs

to_onnx and submodules from LLMs

Check the exporter on a dummy from HuggingFace

Check the exporter on a dummy from HuggingFace

to_onnx and a model with a test

to_onnx and a model with a test

Gallery generated by Sphinx-Gallery