Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fine tune
Browse files Browse the repository at this point in the history
  • Loading branch information
Superjomn committed Mar 19, 2018
1 parent 6ea1b17 commit 5b791be
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 16 deletions.
9 changes: 6 additions & 3 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ def __register__(factor):
class GreaterWorseFactor(Factor):
''' Evaluator for any factors that large value is bad, trainning cost for example. '''

def __init__(self, name, diff_thre):
def __init__(self, name, diff_thre, skip_head=2):
'''
diff_thre: difference threshold.
'''
super(GreaterWorseFactor, self).__init__(out_file='%s_factor.txt' %
name)
self.skip_head = skip_head
self.name = name
self.diff_thre = diff_thre

def evaluate(self, root):
cur_data = load_records_from(pjoin(root, self.out_file))
his_data = load_records_from(pjoin(root, self.his_file))
cur_data = load_records_from(
pjoin(root, self.out_file))[self.skip_head:]
his_data = load_records_from(
pjoin(root, self.his_file))[self.skip_head:]
diff = cur_data - his_data
larger = diff > 0
self.ratios = diff[larger] / his_data[larger]
Expand Down
13 changes: 12 additions & 1 deletion gstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def set(key, value):
if not os.path.isdir(gstate.root):
os.mkdir(gstate.root)
with open(pjoin(gstate.root, key), 'w') as f:
f.write(value)
f.write(str(value))

@staticmethod
def get(key):
Expand Down Expand Up @@ -67,3 +67,14 @@ def update_baseline_history(history):
@staticmethod
def get_baseline_history():
return gstate.get(gstate.baseline_history)

source_code_updated = 'source_code_updated'

@staticmethod
def set_source_code_updated(updated):
''' updated: bool, yes/no '''
gstate.set(gstate.source_code_updated, 'yes' if updated else 'no')

@staticmethod
def get_source_code_updated():
return gstate.get(gstate.source_code_updated) == 'yes'
15 changes: 10 additions & 5 deletions main.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $XONSH_SHOW_TRACEBACK = True

import os
import sys; sys.path.insert(0, '')
import time

import prepare
import config
Expand All @@ -26,6 +27,7 @@ def test_latest_source():
baseline.strategy.refresh_workspace()
write_init_models_factors_to_gstate()
write_init_progress_to_gstate()
write_history_to_gstate()
# update_model_factors_status('prepare', 'update_baseline', 'pass')

log.warn('init local paddle repo %s' % config.local_repo_path())
Expand All @@ -38,6 +40,8 @@ def test_latest_source():
prepare.compile()
prepare.install_whl()
test_models()
# update baseline
baseline.strategy()

def test_models():
cd @(config.workspace)
Expand All @@ -59,8 +63,6 @@ def test_models():
update_evaluation_status(evaluate_status)

log.warn('evaluation result:\n%s' % gstate.get_evaluation_result())
baseline.strategy()

if evaluation_succeed():
update_success_commit_to_gstate()
else:
Expand Down Expand Up @@ -109,10 +111,13 @@ def source_code_updated():
cur_commit = repo.get_paddle_commit()
last_commit = gstate.get(config._state_paddle_code_commit_)
updated = last_commit is None or cur_commit != last_commit
gstate.set_source_code_updated(updated)
if not updated:
log.info("paddle source code is not changed, skip test, commitid %s" % cur_commit)
return updated
gstate.set(config._state_paddle_code_commit_, cur_commit)
else:
gstate.set(config._state_paddle_code_commit_, cur_commit)
return updated

test_latest_source()
for i in range(5000):
test_latest_source()
time.sleep(60)
9 changes: 4 additions & 5 deletions utils.xsh
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ def write_history_to_gstate():
spliter = '__'
history = $(git log --pretty=format:">>>%H__%ai__%s__%B")
records = []
print('history', repr(history))
for line in history.split('\n'):
if line.startswith('"'): line = line[1:-1]
print('line', repr(line))
if line.startswith('"'): line = line[1:]
if line.endswith('"'): line = line[:-1]
if not line: continue
if line.startswith('>>>'):
fields = line.strip().split(spliter)
Expand All @@ -130,7 +129,6 @@ def write_history_to_gstate():
body = fields[3]
records.append([commitid, date, subject, body])
else:
print('records', records)
# append body
records[-1][3] += '\n' + line
gstate.update_baseline_history(json.dumps(records))
Expand All @@ -139,7 +137,8 @@ def update_fail_commit_to_gstate():
commit = gstate.get(config._state_paddle_code_commit_)
gstate.set(config._fail_commit_, commit)

def update_success_commit_to_gstate(commit):
def update_success_commit_to_gstate():
commit = gstate.get(config._state_paddle_code_commit_)
gstate.set(config._success_commit_, commit)


Expand Down
5 changes: 5 additions & 0 deletions web/logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def current_working_on_commit():


def current_progress():
if not source_code_updated(): return 0
progresses = json.loads(gstate.get_progress_list())
progress = gstate.get_current_progress()
if progress:
Expand All @@ -64,3 +65,7 @@ def model_evaluation_status():
def baseline_history():
history = json.loads(gstate.get_baseline_history())
return history


def source_code_updated():
return gstate.get_source_code_updated()
7 changes: 6 additions & 1 deletion web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@
"modelce", static_url_path=STATIC_DIR, template_folder=TEMPLATE_DIR)

baseline_commit_url = "https://github.com/Superjomn/paddle-modelci-baseline/commit"
paddle_commit_url = "https://github.com/PaddlePaddle/Paddle/commit"


@app.route('/')
def index():
return render_template(
'dashboard.html',
current_module='dashboard',
paddle_commit_url=paddle_commit_url,
source_code_updated=logics.source_code_updated(),
baseline_commit_url=baseline_commit_url,
last_success_commit=logics.last_success_commit(),
last_fail_commit=logics.last_fail_commit(),
Expand All @@ -29,6 +33,7 @@ def index():
def history():
return render_template(
'history.html',
current_module='history',
baseline_commit_url=baseline_commit_url,
baseline_history=logics.baseline_history())

Expand All @@ -41,4 +46,4 @@ def serve_static(path):
if __name__ == '__main__':
host = '0.0.0.0'
port = 8080
app.run(debug=True, host=host, port=port)
app.run(debug=False, host=host, port=port)
12 changes: 12 additions & 0 deletions web/template/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE HTML>
<html>
<meta http-equiv="refresh" content="6">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<head>
<title>PaddlePaddle Model Continuous Evaluation</title>
Expand Down Expand Up @@ -117,7 +118,9 @@

<nav class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="/">ModelCE</a>
<!--
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
-->
</nav>

<div class="container-fluid">
Expand All @@ -126,7 +129,11 @@
<div class="sidebar-sticky">
<ul class="nav flex-column">
<li class="nav-item"> <!-- the main page -->
{% if current_module == "dashboard" %}
<a class="nav-link active" href="/">
{% else %}
<a class="nav-link" href="/">
{% endif %}
<span data-feather="home"></span>
Dashboard
<span class="sr-only">(current)</span>
Expand All @@ -142,9 +149,14 @@
-->

<li class="nav-item">
{% if current_module == "history" %}
<a class="nav-link active" href="/history">
{% else %}
<a class="nav-link" href="/history">
{% endif %}
<span data-feather="book"></span>
History
<span class="sr-only">(current)</span>
</a>
</li>
</ul>
Expand Down
16 changes: 15 additions & 1 deletion web/template/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ <h1 class="h2">Dashboard</h1>
<div class="container-fluid border-bottom">
<div class="row">
<div class="col-sm">
{% if last_success_commit == "none" %}
<span class="badge badge-success">Last success</span> <a href="#" class="alert-link">{{ last_success_commit }}</a>
{% else %}
<span class="badge badge-success">Last success</span> <a href="{{ paddle_commit_url }}/{{ last_success_commit }}" class="alert-link">{{ last_success_commit }}</a>
{% endif %}
</div>
<div class="col-sm">
{% if last_fail_commit == "none" %}
<span class="badge badge-danger">Last fail</span> <a href="#" class="alert-link">{{ last_fail_commit }}</a>
{% else %}
<span class="badge badge-danger">Last fail</span> <a href="{{ paddle_commit_url }}/{{ last_fail_commit }}" class="alert-link">{{ last_fail_commit }}</a>
{% endif %}
</div>
<hr/>
</div>

{%if source_code_updated %}
<div class="row alert alert-primary">
Currently working on &nbsp;<a href="#" class="alert-link">{{ current_working_on_commit }}</a>
Currently working on Paddle version: &nbsp;<a href="#" class="alert-link">{{ current_working_on_commit }}</a>
</div>
{% else %}
<div class="row alert alert-secondary">
Hold, waiting for new source update.
</div>
{% endif %}

<div class="row progress modelce-row">
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="{{ current_progress }}" aria-valuemin=0" aria-valuemax="100" style="width:{{ current_progress }}%">
Expand Down
30 changes: 30 additions & 0 deletions web/template/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "base.html" %}
{% block main %}
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h1 class="h2">History</h1>
</div>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
<h2 class="h3">Baseline updated records</h2>
</div>
<div class="container-fluid border-bottom">
<table class="table table-striped">
<tbody>
{% for record in baseline_history %}
<tr>
<th scope="row">
<a href="{{ baseline_commit_url }}/{{ record[0] }}">{{ record[0] }}</a></th>
<th scope="row">{{ record[1] }}</th>
</tr>
<tr>
<th scope="row">{{ record[2] }}</th>
<th scope="row">
<pre>{{record[3] }}</pre>
</th>
</tr>
{% endfor %}
</tbody>
</table>
</div> <!-- history -->
</main>
{% endblock %}

0 comments on commit 5b791be

Please sign in to comment.