how to use amp training in Allennlp 2.4.0? - allennlp

I have learned to use AMP and GA tricks on training model from https://medium.com/ai2-blog/tutorial-training-on-larger-batches-with-less-memory-in-allennlp-1cd2047d92ad,
But it seems not supported in the 2.4.0 ?
File "/root/anaconda3/envs/allennlp/lib/python3.6/site-packages/allennlp/training/util.py", line 217, in create_serialization_dir
f"Value for '{key}' in training configuration does not match that the value in "

Thank you for your answer! #Dirk Groeneveld.
finnally,the correct way to use AMP with allennlp 2.4.0 :
"trainer": {
"type":"gradient_descent",
"use_amp": true,
"num_gradient_accumulation_steps": 4,
"distributed": true,
...
}

Related

Is there a way to create a logic condition in packer provisioner?

I am trying to add a condition so my volume_size: can get two different values depending on what is passed in "-var role="
I've tried something like this :
"volume_size": [{
"Fn::If" : [
".ami_id_bar",
{"foo" : "50"},
{"foo" : "20"}
]
}],
.ami_id_bar is a :
"environment_vars": [
"ami_id_bar={{user `role`}}"
],
that gets it from command line when executing packer
This is the error I get :
error(s) decoding:
'launch_block_device_mappings[0].volume_size' expected type 'int64', got unconvertible type '[]interface {}'
Is it impossible or what am I doing wrong ?
Thank you in advance!
No you can't. Packers templates are logicless. The standard way of achieving the what you want is to use -var-file where each vars file represents a role, e.g.
packer build -var-file=role-A.json template.json
In more complex cases we recommend that you preprocess your template and other files and wrap packer in some build script like make.

JSONPath Syntax when dot in key

Please forgive me if I use the incorrect terminology, I am quite the novice.
I have some simple JSON:
{
"properties": {
"footer.navigationLinks": {
"group": "layout"
, "default": [
{
"text": "Link a"
, "href": "#"
}
]
}
}
}
I am trying to pinpoint "footer.navigationLinks" but I am having trouble with the dot in the key name. I am using http://jsonpath.com/ and when I enter
$.properties['footer.navigationLinks']
I get 'No match'. If I change the key to "footernavigationLinks" it works but I cannot control the key names in the JSON file.
Please can someone help me target that key name?
Having a json response:
{
"0": {
"SKU": "somevalue",
"Merchant.Id": 234
}
}
I can target a key with a . (dot) in the name.
jsonPath.getJsonObject("0.\"Merchant.Id\"")
Note: the quotes and the fact that they are escaped.
Note not sure of other versions, but I'm using
'com.jayway.restassured', name: 'json-path', version: '2.9.0'
A few samples/solutions I've seen, was using singe quotes with brackets, but did not work for me.
For information, jsonpath.com has been patched since the question was asked, and it now works for the example given in the question. I tried these paths successfully:
$.properties['footer.navigationLinks']
$.properties.[footer.navigationLinks]
$.properties.['footer.navigationLinks']
$['properties']['footer.navigationLinks']
$.['properties'].['footer.navigationLinks']
properties.['footer.navigationLinks']
etc.
This issue was reported in 2007 as issue #4 - Member names containing dot fail and fixed.
The fix is not present in this online jsonpath.com implementation, but it is fixed in this old archive and probably in most of the forks that have been created since (like here and here).
Details about the bug
A comparison between the buggy and 2007-corrected version of the code, reveals that the correction was made in the private normalize function.
In the 2007-corrected version it reads:
normalize: function(expr) {
var subx = [];
return expr.replace(/[\['](\??\(.*?\))[\]']|\['(.*?)'\]/g, function($0,$1,$2){
return "[#"+(subx.push($1||$2)-1)+"]";
}) /* http://code.google.com/p/jsonpath/issues/detail?id=4 */
.replace(/'?\.'?|\['?/g, ";")
.replace(/;;;|;;/g, ";..;")
.replace(/;$|'?\]|'$/g, "")
.replace(/#([0-9]+)/g, function($0,$1){
return subx[$1];
});
},
The first and last replace in that sequence make sure the second replace does not interpret a point in a property name as a property separator.
I had a look at the more up-to-date forks that have been made since then, and the code has evolved enormously since.
Conclusion:
jsonpath.com is based on an outdated version of JSONPath and is not reliable for previewing what current libraries would provide you with.
You can encapsulate the 'key with dots' with single quotes as below
response.jsonpath().get("properties.'footer.navigationLinks'")
Or even escape the single quotes as shown:
response.jsonpath().get("properties.\'footer.navigationLinks\'")
Both work fine

Difference Between Two Mongo Queries

what is the difference between two mongo queries.
db.test.find({"field" : "Value"})
db.test.find({field : "Value"})
mongo shell accepts both.
There is no difference in your example.
The problem happens when your field names contain characters which cannot be a part of an identifier in Javascript (because the query engine is run in a javascript repl/shell)
For example user-name because there is a hyphen in it.
Then you would have to query like db.test.find({"user-name" : "Value"})
For the mongo shell there is no actual difference, but in some other language cases it does matter.
The actual case here is presenting what is valid JSON, and with myself as a given example, I try to do this in responses on this forum and others as JSON is a data format that can easily be "parsed" into native data structures, where alternate "JavaScript" notation may not be translated so easily.
There are certain cases where the quoting is required, as in:
db.test.find({ "field-value": 1 })
or:
db.test.find({ "field.value": 1 })
As the values would otherwise be "invalid JavaScript".
But the real point here is adhering to the JSON form.
You can understand with example: suppose that you have test collection with two records
{
'_id': ObjectId("5370a826fc55bb23128b4568"),
'name': 'nanhe'
}
{
'_id': ObjectId("5370a75bfc55bb23128b4567"),
'your name': 'nanhe'
}
db.test.find({'your name':'nanhe'});
{ "_id" : ObjectId("5370a75bfc55bb23128b4567"), "your name" : "nanhe" }
db.test.find({your name:'nanhe'});
SyntaxError: Unexpected identifier

mongodb equivalent of SELECT field AS `anothername`

what is the mongodb equivalent of the MySQL query
SELECT username AS `consname` FROM `consumer`
As it was mentioned by sammaye, you have to use $project in aggregation framework to rename fields.
So in your case it would be:
db.consumer.aggregate([
{ "$project": {
"_id": 0,
"consname": "$username"
}}
])
Cool thing is that in 2.6.x version aggregate returns a cursor which means it behaves like find.
You might also take a look at $rename operator to permanently change schema.
Salvador Dali's answer is fine, but not working in meteor versions before 3.0.
I currently try meteor, and their build in mongodb is in version 2.
The way I solved this is like this:
var result = []:
db.consumer.forEach( function(doc) {
result.push({
consname:doc.username
});
});

How could/should I state colon (punctuation) in a YAML file?

I am using Ruby on Rails 3.1.0 and I would like to know how to correctly state colon (punctuation) in a YAML file. I tried to support that by adding the following code in my config/locales/defaults/en.yml file
en
# ':' is the HTML code for ':'
test_key_html: Test value:
and in my view file I used
t('test_key_html')
but it doesn't work (in the front end content is displayed the "plain" Test value: text).
Is it possible? If so how?
You should be able to double quote the value:
test_key_html: "Test value:"
This avoids colon-confusion in the YAML and gets your colon into your HTML.
Consider this in irb:
>> { 'en' => { 'test_key_html' => 'Test value:' } }.to_yaml
=> "--- \nen: \n test_key_html: "Test value:"\n"
Try
raw(t('test_key_html'))
Rails 3+ automattically escapes html markup