-
Notifications
You must be signed in to change notification settings - Fork 537
[CI] Update GPU Test Workflow + Update Some Tests and README #1316
Changes from 34 commits
b45fda2
ad7c2ee
e9901c2
84fac91
c2f80d9
e5ab220
0a6a1d3
92b9e85
749acec
44d0c5b
3e02d5f
d174fcf
a73161a
2587f2b
8908e71
994c2c1
39d2351
43bb922
0063052
68f814f
76cf1c4
43aadab
c0bfc6d
92950e0
b134ac1
91cd6f0
837903d
074880c
061cdfb
f8b87f4
86a4ff2
b3c017a
5c3a099
c866de3
67f2e38
2a9b3ba
9cbaaf5
0792dea
9d4c459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,12 @@ | |
|
||
# alias python3='/usr/bin/python3' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why comment? |
||
|
||
echo $PWD | ||
|
||
sudo apt-get install libopenblas-dev | ||
python3 -m pip install --user -upgrade pip | ||
python3 -m pip install --user setuptools pytest pytest-cov contextvars | ||
python3 -m pip install --upgrade cython | ||
python3 -m pip install --pre --user "mxnet-cu102>=2.0.0b20200802" -f https://dist.mxnet.io/python | ||
python3 -m pip install --user -e .[extras] | ||
python3 -m pytest --cov=./ --cov-report=xml --durations=50 --device="gpu" tests/ | ||
python3 -m pip install --user --quiet -upgrade pip | ||
python3 -m pip install --user --quiet setuptools pytest pytest-cov contextvars | ||
python3 -m pip install --upgrade --quiet cython | ||
python3 -m pip install --pre --user --quiet "mxnet-cu102>=2.0.0b20200802" -f https://dist.mxnet.io/python | ||
python3 -m pip install --user --quiet -e .[extras] | ||
python3 -m pytest --cov=./ --cov-report=xml --durations=50 --device="gpu" ../../tests/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this script is already at the root level and looking in paths further up would be confusing. |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,87 +12,88 @@ def test_list_pretrained_bert(): | |
|
||
|
||
@pytest.mark.parametrize('compute_layout', ['auto', 'NT', 'TN']) | ||
def test_bert_small_cfg(compute_layout): | ||
cfg = BertModel.get_cfg() | ||
cfg.defrost() | ||
cfg.MODEL.vocab_size = 100 | ||
cfg.MODEL.units = 12 * 4 | ||
cfg.MODEL.hidden_size = 64 | ||
cfg.MODEL.num_layers = 2 | ||
cfg.MODEL.num_heads = 2 | ||
cfg.MODEL.compute_layout = compute_layout | ||
cfg.freeze() | ||
def test_bert_small_cfg(compute_layout, ctx): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. We can use this like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an internal API and may change in the future. It may be better to use the |
||
with ctx: | ||
cfg = BertModel.get_cfg() | ||
cfg.defrost() | ||
cfg.MODEL.vocab_size = 100 | ||
cfg.MODEL.units = 12 * 4 | ||
cfg.MODEL.hidden_size = 64 | ||
cfg.MODEL.num_layers = 2 | ||
cfg.MODEL.num_heads = 2 | ||
cfg.MODEL.compute_layout = compute_layout | ||
cfg.freeze() | ||
|
||
# Generate TN layout | ||
cfg_tn = cfg.clone() | ||
cfg_tn.defrost() | ||
cfg_tn.MODEL.layout = 'TN' | ||
cfg_tn.freeze() | ||
# Generate TN layout | ||
cfg_tn = cfg.clone() | ||
cfg_tn.defrost() | ||
cfg_tn.MODEL.layout = 'TN' | ||
cfg_tn.freeze() | ||
|
||
# Sample data | ||
batch_size = 4 | ||
sequence_length = 8 | ||
num_mask = 3 | ||
inputs = mx.np.random.randint(0, 10, (batch_size, sequence_length)) | ||
token_types = mx.np.random.randint(0, 2, (batch_size, sequence_length)) | ||
valid_length = mx.np.random.randint(3, sequence_length, (batch_size,)) | ||
masked_positions = mx.np.random.randint(0, 3, (batch_size, num_mask)) | ||
# Sample data | ||
batch_size = 4 | ||
sequence_length = 8 | ||
num_mask = 3 | ||
inputs = mx.np.random.randint(0, 10, (batch_size, sequence_length)) | ||
token_types = mx.np.random.randint(0, 2, (batch_size, sequence_length)) | ||
valid_length = mx.np.random.randint(3, sequence_length, (batch_size,)) | ||
masked_positions = mx.np.random.randint(0, 3, (batch_size, num_mask)) | ||
|
||
# Test for BertModel | ||
bert_model = BertModel.from_cfg(cfg) | ||
bert_model.initialize() | ||
bert_model.hybridize() | ||
contextual_embedding, pooled_out = bert_model(inputs, token_types, valid_length) | ||
bert_model_tn = BertModel.from_cfg(cfg_tn) | ||
bert_model_tn.share_parameters(bert_model.collect_params()) | ||
bert_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn = bert_model_tn(inputs.T, token_types.T, valid_length) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
# Test for BertModel | ||
bert_model = BertModel.from_cfg(cfg) | ||
bert_model.initialize() | ||
bert_model.hybridize() | ||
contextual_embedding, pooled_out = bert_model(inputs, token_types, valid_length) | ||
bert_model_tn = BertModel.from_cfg(cfg_tn) | ||
bert_model_tn.share_parameters(bert_model.collect_params()) | ||
bert_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn = bert_model_tn(inputs.T, token_types.T, valid_length) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
|
||
# Test for BertForMLM | ||
bert_mlm_model = BertForMLM(cfg) | ||
bert_mlm_model.initialize() | ||
bert_mlm_model.hybridize() | ||
contextual_embedding, pooled_out, mlm_score = bert_mlm_model(inputs, token_types, | ||
valid_length, masked_positions) | ||
bert_mlm_model_tn = BertForMLM(cfg_tn) | ||
bert_mlm_model_tn.share_parameters(bert_mlm_model.collect_params()) | ||
bert_mlm_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn, mlm_score_tn =\ | ||
bert_mlm_model_tn(inputs.T, token_types.T, valid_length, masked_positions) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(mlm_score.asnumpy(), mlm_score_tn.asnumpy(), 1E-4, 1E-4) | ||
# Test for BertForMLM | ||
bert_mlm_model = BertForMLM(cfg) | ||
bert_mlm_model.initialize() | ||
bert_mlm_model.hybridize() | ||
contextual_embedding, pooled_out, mlm_score = bert_mlm_model(inputs, token_types, | ||
valid_length, masked_positions) | ||
bert_mlm_model_tn = BertForMLM(cfg_tn) | ||
bert_mlm_model_tn.share_parameters(bert_mlm_model.collect_params()) | ||
bert_mlm_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn, mlm_score_tn =\ | ||
bert_mlm_model_tn(inputs.T, token_types.T, valid_length, masked_positions) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(mlm_score.asnumpy(), mlm_score_tn.asnumpy(), 1E-4, 1E-4) | ||
|
||
# Test for BertForPretrain | ||
bert_pretrain_model = BertForPretrain(cfg) | ||
bert_pretrain_model.initialize() | ||
bert_pretrain_model.hybridize() | ||
contextual_embedding, pooled_out, nsp_score, mlm_scores =\ | ||
bert_pretrain_model(inputs, token_types, valid_length, masked_positions) | ||
bert_pretrain_model_tn = BertForPretrain(cfg_tn) | ||
bert_pretrain_model_tn.share_parameters(bert_pretrain_model.collect_params()) | ||
bert_pretrain_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn, nsp_score_tn, mlm_scores_tn = \ | ||
bert_pretrain_model_tn(inputs.T, token_types.T, valid_length, masked_positions) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(nsp_score.asnumpy(), nsp_score_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(mlm_score.asnumpy(), mlm_score_tn.asnumpy(), 1E-4, 1E-4) | ||
# Test for BertForPretrain | ||
bert_pretrain_model = BertForPretrain(cfg) | ||
bert_pretrain_model.initialize() | ||
bert_pretrain_model.hybridize() | ||
contextual_embedding, pooled_out, nsp_score, mlm_scores =\ | ||
bert_pretrain_model(inputs, token_types, valid_length, masked_positions) | ||
bert_pretrain_model_tn = BertForPretrain(cfg_tn) | ||
bert_pretrain_model_tn.share_parameters(bert_pretrain_model.collect_params()) | ||
bert_pretrain_model_tn.hybridize() | ||
contextual_embedding_tn, pooled_out_tn, nsp_score_tn, mlm_scores_tn = \ | ||
bert_pretrain_model_tn(inputs.T, token_types.T, valid_length, masked_positions) | ||
assert_allclose(contextual_embedding.asnumpy(), | ||
mx.np.swapaxes(contextual_embedding_tn, 0, 1).asnumpy(), | ||
1E-4, 1E-4) | ||
assert_allclose(pooled_out.asnumpy(), pooled_out_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(nsp_score.asnumpy(), nsp_score_tn.asnumpy(), 1E-4, 1E-4) | ||
assert_allclose(mlm_score.asnumpy(), mlm_score_tn.asnumpy(), 1E-4, 1E-4) | ||
|
||
|
||
@pytest.mark.remote_required | ||
@pytest.mark.parametrize('model_name', list_pretrained_bert()) | ||
def test_bert_get_pretrained(model_name): | ||
def test_bert_get_pretrained(model_name, ctx): | ||
assert len(list_pretrained_bert()) > 0 | ||
with tempfile.TemporaryDirectory() as root: | ||
with tempfile.TemporaryDirectory() as root, ctx: | ||
cfg, tokenizer, backbone_params_path, mlm_params_path =\ | ||
get_pretrained_bert(model_name, load_backbone=True, load_mlm=True, root=root) | ||
assert cfg.MODEL.vocab_size == len(tokenizer.vocab) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to manually upload the coverage in AWS Batch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also use g4.2x