Neuron Check Model ツール

Neuron Check Model ツールは、コンパイル前後のモデル (SavedModel) の基本的な情報を提供します。

Neuron Check Model ツールは、現時点で TensorFlow 及び MXNet フレームワークに対して提供されます。 PyTorchの場合は、torch.neuron.analyze_model 関数をご利用下さい。詳細はこちら

Step 1. 事前インストール

pip install tensorflow_hub
wget https://raw.githubusercontent.com/aws/aws-neuron-sdk/master/src/neuron-gatherinfo/tf_neuron_check_model.py

Step 2. CPU向けモデルのチェック

章4.1で使用したCPU向けモデル /resnet50 に対してtf_neuron_check_model.pyを実行します。

python tf_neuron_check_model.py ./resnet50

次の結果が取得されます。Neuronコンパイラでサポートされているオペレータ、未対応のオペレータを確認することができます。

* The following table shows the supported and unsupported operations within this uncompiled model.
* Each line shows an operation type, the number of instances of that type within model,
* and whether the type is supported in Neuron.
* Some operation types are excluded from table because they are no-operations or training-related operations:
 ['Placeholder', 'PlaceholderWithDefault', 'NoOp', 'Const', 'Identity', 'IdentityN', 'VarHandleOp', 'VarIsInitializedOp', 'AssignVariableOp', 'ReadVariableOp', 'StringJoin', 'ShardedFilename', 'SaveV2', 'MergeV2Checkpoints', 'RestoreV2'] 

Op Type           Num Instances   Neuron Supported ?
-------           -------------   ------------------
Pad               2               Yes 
RandomUniform     54              Yes 
Sub               54              Yes 
Mul               54              Yes 
Add               54              Yes 
Conv2D            53              Yes 
BiasAdd           54              Yes 
FusedBatchNormV3  53              Yes 
Relu              49              Yes 
MaxPool           1               Yes 
AddV2             16              Yes 
Fill              56              Yes 
Mean              1               Yes 
MatMul            1               Yes 
Softmax           1               Yes 
Pack              1               Yes 

* Total inference operations: 504
* Total Neuron supported inference operations: 504
* Percent of total inference operations supported by Neuron: 100.0

Step 3. コンパイル済みモデルのチェック

章4.2で使用した Inferentia 推論チップ向けにコンパイル済みのモデル /resnet50_neuron に対して、tf_neuron_check_model.pyを実行します。

python tf_neuron_check_model.py ./resnet50_neuron
* Found 1 Neuron subgraph(s) (NeuronOp(s)) in this compiled model.
* Use this tool on the original uncompiled model to see Neuron supported operations.
* The following table shows all operations, including Neuron subgraphs.
* Each line shows an operation type, the number of instances of that type within model,
* and whether the type is supported in Neuron.
* Some operation types are excluded from table because they are no-operations or training-related operations:
 ['Placeholder', 'PlaceholderWithDefault', 'NoOp', 'Const', 'Identity', 'IdentityN', 'VarHandleOp', 'VarIsInitializedOp', 'AssignVariableOp', 'ReadVariableOp', 'StringJoin', 'ShardedFilename', 'SaveV2', 'MergeV2Checkpoints', 'RestoreV2'] 

Op Type   Num Instances   Neuron Supported ?
-------   -------------   ------------------
NeuronOp  1               Yes 

* Please run this model on Inf1 instance with at least 1 NeuronCore(s).
* The following list show each Neuron subgraph with number of pipelined NeuronCores used by subgraph
* (and subgraph operations if --expand_subgraph is used):

Subgraph Name                                                                 Num Pipelined NeuronCores
-------------                                                                 -------------------------
conv5_block3_3_bn/FusedBatchNormV3/ReadVariableOp/neuron_op_d6f098c01c780733  1   

Step 4. コンパイル済みモデルのサブグラフ情報をチェック

–-expand_subgraphオプションを使用して、各サブグラフで利用されるオペレータをタイプ別に表示できます。

python tf_neuron_check_model.py ./resnet50_neuron --expand_subgraph
Subgraph Name                                                                 Num Pipelined NeuronCores
-------------                                                                 -------------------------
conv5_block3_3_bn/FusedBatchNormV3/ReadVariableOp/neuron_op_d6f098c01c780733  1             
     Op Type         Num Instances 
     -------         ------------- 
     MatMul          1             
     Relu            49            
     Add             16            
     FusedBatchNorm  53            
     BiasAdd         54            
     Conv2D          53            
     Pad             2             
     Mean            1             
     MaxPool         1             
     Softmax         1             

Step 5. コンパイル済みモデルのサブグラフ情報をオペレータの名前と共に一覧表示

python tf_neuron_check_model.py ./resnet50_neuron --expand_subgraph --show_names

--show_namesオプションを使用して、各サブグラフで利用されるオペレータの名前を一覧表示します。

Subgraph Name                                                                 Num Pipelined NeuronCores
-------------                                                                 -------------------------
conv5_block3_3_bn/FusedBatchNormV3/ReadVariableOp/neuron_op_d6f098c01c780733  1             
     Op Name                             Op Type       
     -------                             -------       
     probs/MatMul                        MatMul        
     conv5_block3_out/Relu               Relu          
     conv5_block3_add/add                Add           
     conv5_block3_3_bn/FusedBatchNormV3  FusedBatchNorm
     conv5_block3_3_conv/BiasAdd         BiasAdd       
     conv5_block3_2_relu/Relu            Relu          
.
.
.
     conv4_block5_3_conv/Conv2D          Conv2D        
     conv4_block6_1_conv/BiasAdd         BiasAdd       
     conv4_block5_3_bn/FusedBatchNormV3  FusedBatchNorm
     conv4_block5_add/add                Add           
     conv4_block5_out/Relu               Relu          
     conv2_block3_1_relu/Relu            Relu          
     conv4_block6_2_conv/Conv2D          Conv2D        
     conv4_block6_2_conv/BiasAdd         BiasAdd       
     conv4_block6_3_conv/Conv2D          Conv2D        
     conv5_block1_0_conv/Conv2D          Conv2D