defhash_name(varblocks,pserver_endpoints):""" :param varblocks: a list of VarBlock string indicating sub blocks of variables :return: a map of pserver endpoint -> varblock_str """def_hash_block(block_str,total):returnhash(block_str)%totalep2block=dict()forvarblock_strinvarblocks:ifparam.trainableisTrueandgradisnotNone:server_id=_hash_block(varblock_str,len(pserver_endpoints))server_for_param=pserver_endpoints[server_id]ifnotep2block.has_key(server_for_param):ep2block[server_for_param]=[]ep2block[server_for_param].append(varblock_str)returnep2blockdefround_robin(varblocks,pserver_endpoints):assert(len(varblocks)>len(pserver_endpoints))ep2block=dict()pserver_idx=0forvarblock_strinvarblocks:ifparam.trainableisTrue:server_for_param=pserver_endpoints[pserver_idx]ifnotep2block.has_key(server_for_param):ep2block[server_for_param]=[]ep2block[server_for_param].append(varblock_str)pserver_idx+=1ifpserver_idx>=len(pserver_endpoints):pserver_idx=0returnep2block