deepLearn addLayer

Edge Case: Model Refactoring and Error Handling

Scénario de test & Cas d'usage

Business Context

A data science team is experimenting with different hyperparameters for a model. They need to replace an existing layer with a new one that has a different configuration. This scenario tests the 'replace' functionality and the action's behavior when encountering invalid layer references.
About the Set : deepLearn

Creation and training of deep neural networks.

Discover all actions of deepLearn
Data Preparation

A simple base model will be created in a table named 'refactor_model' to serve as the starting point for the refactoring tests.

Copied!
1/* No
2data step needed. The initial model is created in the first test step. */

Étapes de réalisation

1
Create a simple baseline model: Input -> Conv -> Output. The convolutional layer 'conv_v1' has 10 filters.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer / modelTable={name='refactor_model', replace=true} name='input' layer={type='input', nchannels=1, width=28, height=28};
3DEEPLEARN.addLayer / modelTable={name='refactor_model'} name='conv_v1' layer={type='convolution', nFilters=10, width=3} srcLayers={'input'};
4DEEPLEARN.addLayer / modelTable={name='refactor_model'} name='output' layer={type='output', n=5} srcLayers={'conv_v1'};
5RUN;
2
Test the 'replace' functionality. Add a new layer also named 'conv_v1' but with 20 filters instead of 10. Set 'replace=TRUE'.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='refactor_model'}
4 name='conv_v1'
5 layer={type='convolution', nFilters=20, width=3}
6 srcLayers={'input'}
7 replace=true;
8RUN;
3
Test error handling. Attempt to add a new layer that references a source layer that does not exist ('non_existent_layer').
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='refactor_model'}
4 name='error_layer'
5 layer={type='fullconnect', n=10}
6 srcLayers={'non_existent_layer'};
7RUN;
4
Verify that the model remains in a valid state after the failed step. Add a final, valid layer to ensure the model table was not corrupted.
Copied!
1PROC CAS;
2DEEPLEARN.addLayer /
3 modelTable={name='refactor_model'}
4 name='final_valid_layer'
5 layer={type='fullconnect', n=10}
6 srcLayers={'conv_v1'};
7RUN;

Expected Result


Step 2 successfully replaces the 'conv_v1' layer; the new model summary should show the convolutional layer with 20 filters. Step 3 is expected to fail and produce an error in the SAS log stating that the source layer 'non_existent_layer' was not found. Step 4 should succeed, demonstrating that the model table was not corrupted by the previous error. The final model will contain 'input', the updated 'conv_v1', 'final_valid_layer', and 'output' layers.