Skip to content

Commit

Permalink
improve speed of tryprune.py tool
Browse files Browse the repository at this point in the history
  • Loading branch information
epico committed Aug 5, 2011
1 parent 4ae9a17 commit 3897e71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/myconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def getEstimateIndex(self):
def getSortedEstimateIndex(self):
return 'estimate.sorted.index'

def getInMemoryFileSystem(self):
return '/dev/shm'

def getEvalsText(self):
evals_text = m_evals_dir + '/data/evals.text'
return evals_text
Expand Down
22 changes: 19 additions & 3 deletions tryprune.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ def pruneModel(prunedmodel, k, CDF):
help='CDF parameter of k mixture model prune', \
default=0.99, type=float)

parser.add_argument('--fast', action='store_const', \
help='Use in-memory filesystem to speed up prune',\
const=True, default=False)

parser.add_argument('tryname', action='store', \
help='the storage directory')

args = parser.parse_args()
print(args)

tryname = 'try' + args.tryname

trydir = os.path.join(config.getFinalModelDir(), tryname)
Expand Down Expand Up @@ -187,10 +192,21 @@ def pruneModel(prunedmodel, k, CDF):

#prune merged model
print('pruning')

prunedmodel = os.path.join(trydir, 'pruned.db')
#backup merged model
shutil.copyfile(mergedmodel, prunedmodel)
pruneModel(prunedmodel, args.k, args.CDF)
if args.fast:
shmmodel = os.path.join(config.getInMemoryFileSystem(), 'pruned.db')
if os.access(shmmodel, os.F_OK):
os.unlink(shmmodel)
#copy to memory
shutil.copyfile(mergedmodel, shmmodel)
pruneModel(shmmodel, args.k, args.CDF)
#copy to filesystem
shutil.copyfile(shmmodel, prunedmodel)
else:
#backup merged model
shutil.copyfile(mergedmodel, prunedmodel)
pruneModel(prunedmodel, args.k, args.CDF)

#validate pruned model
print('validating')
Expand Down

0 comments on commit 3897e71

Please sign in to comment.