Skip to content

Commit 883c12d

Browse files
refactor: move estimation model definitions into packages [code:qws] [system:MiyabiG]
1 parent fe770a4 commit 883c12d

File tree

3 files changed

+149
-110
lines changed

3 files changed

+149
-110
lines changed

scripts/estimation/common.sh

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,48 @@ bk_estimation_load_package() {
140140
BK_ESTIMATION_MODEL_VERSION="${BK_ESTIMATION_MODEL_VERSION:-${BK_ESTIMATION_PACKAGE_VERSION:-0.1}}"
141141
}
142142

143+
bk_estimation_build_model_json_from_metadata() {
144+
local role="$1"
145+
local source_system="$2"
146+
local target_system="$3"
147+
local default_type="$4"
148+
local default_name="$5"
149+
local default_rule="$6"
150+
local model_version="${7:-${BK_ESTIMATION_PACKAGE_VERSION:-0.1}}"
151+
local package_metadata
152+
local role_metadata
153+
154+
package_metadata=$(bk_estimation_package_metadata)
155+
role_metadata=$(echo "$package_metadata" | jq -c --arg role "$role" '.models[$role] // {}')
156+
157+
jq -cn \
158+
--arg type "$(echo "$role_metadata" | jq -r --arg v "$default_type" '.type // $v')" \
159+
--arg name "$(echo "$role_metadata" | jq -r --arg v "$default_name" '.name // $v')" \
160+
--arg version "$model_version" \
161+
--arg source_system "$source_system" \
162+
--arg target_system "$target_system" \
163+
--arg system_compatibility_rule "$(echo "$role_metadata" | jq -r --arg v "$default_rule" '.system_compatibility_rule // $v')" \
164+
--arg implementation "scripts/estimation/packages/${BK_ESTIMATION_PACKAGE}.sh" \
165+
--arg role "$role" '
166+
{
167+
type: $type,
168+
name: $name,
169+
version: $version
170+
}
171+
+ (if $source_system != "" then {source_system: $source_system} else {} end)
172+
+ (if $target_system != "" then {target_system: $target_system} else {} end)
173+
+ (if $system_compatibility_rule != "" then {system_compatibility_rule: $system_compatibility_rule} else {} end)
174+
+ (if $role == "top_level" then {implementation: $implementation} else {} end)
175+
'
176+
}
177+
178+
bk_estimation_model_name_from_metadata() {
179+
local role="$1"
180+
local default_name="$2"
181+
182+
bk_estimation_package_metadata | jq -r --arg role "$role" --arg v "$default_name" '.models[$role].name // $v'
183+
}
184+
143185
bk_estimation_run_recorded_current_with_weakscaling() {
144186
local baseline_system="${1:-${BK_ESTIMATION_BASELINE_SYSTEM:-Fugaku}}"
145187
local baseline_exp="${2:-${BK_ESTIMATION_BASELINE_EXP:-CASE0}}"
@@ -168,20 +210,14 @@ bk_estimation_run_recorded_current_with_weakscaling() {
168210
if declare -F bk_estimation_package_build_recorded_current_model_json >/dev/null 2>&1; then
169211
est_current_model_json=$(bk_estimation_package_build_recorded_current_model_json "$baseline_system" "$current_model_version")
170212
else
171-
est_current_model_json=$(jq -cn \
172-
--arg type "intra_system_scaling_model" \
173-
--arg name "${current_package}-current" \
174-
--arg version "$current_model_version" \
175-
--arg source_system "$baseline_system" \
176-
--arg target_system "$baseline_system" \
177-
'{
178-
type: $type,
179-
name: $name,
180-
version: $version,
181-
source_system: $source_system,
182-
target_system: $target_system,
183-
system_compatibility_rule: "same_system_line"
184-
}')
213+
est_current_model_json=$(bk_estimation_build_model_json_from_metadata \
214+
"recorded_current" \
215+
"$baseline_system" \
216+
"$baseline_system" \
217+
"intra_system_scaling_model" \
218+
"${current_package}-current" \
219+
"same_system_line" \
220+
"$current_model_version")
185221
fi
186222

187223
bk_estimation_set_current_package_metadata \

scripts/estimation/packages/instrumented_app_sections_dummy.sh

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ bk_estimation_package_metadata() {
5555
"fallback_policy": {
5656
"mode": "allowed",
5757
"target": "weakscaling"
58+
},
59+
"models": {
60+
"top_level": {
61+
"type": "section-wise",
62+
"name": "instrumented-app-sections-dummy"
63+
},
64+
"current_system": {
65+
"type": "intra_system_scaling_model",
66+
"name": "instrumented-app-sections-current-scaling",
67+
"system_compatibility_rule": "exact_match"
68+
},
69+
"future_system": {
70+
"type": "cross_system_projection_model",
71+
"name": "instrumented-app-sections-future-projection",
72+
"system_compatibility_rule": "cross_system_allowed"
73+
}
5874
}
5975
}
6076
EOF
@@ -414,15 +430,17 @@ bk_estimation_package_run() {
414430
local future_system="${BK_ESTIMATION_FUTURE_SYSTEM:-FugakuNEXT}"
415431
local current_target_nodes="${BK_ESTIMATION_CURRENT_TARGET_NODES:-$est_node_count}"
416432
local future_target_nodes="${BK_ESTIMATION_FUTURE_TARGET_NODES:-$est_node_count}"
417-
local model_name="${BK_ESTIMATION_MODEL_NAME:-instrumented-app-sections-dummy}"
418433
local model_version="${BK_ESTIMATION_MODEL_VERSION:-0.1}"
434+
local model_name
419435
local default_section_factor="${BK_ESTIMATION_SECTION_DEFAULT_FACTOR:-0.5}"
420436
local logp_section_name="${BK_ESTIMATION_LOGP_SECTION_NAME:-allreduce}"
421437
local logp_package_name="logp"
422438
local breakdown_template
423439
local baseline_breakdown
424440
local applicability_issues_json
425441

442+
model_name=$(bk_estimation_model_name_from_metadata "top_level" "instrumented-app-sections-dummy")
443+
426444
est_future_bench_system="$est_system"
427445
est_future_bench_fom="$est_fom"
428446
est_future_bench_nodes="$est_node_count"
@@ -497,47 +515,30 @@ bk_estimation_package_run() {
497515
overlap_rule: "overlap timings are scaled according to their bound overlap package"
498516
}')
499517

500-
est_model_json=$(jq -cn \
501-
--arg type "section-wise" \
502-
--arg name "$model_name" \
503-
--arg version "$model_version" \
504-
--arg implementation "scripts/estimation/packages/instrumented_app_sections_dummy.sh" \
505-
'{
506-
type: $type,
507-
name: $name,
508-
version: $version,
509-
implementation: $implementation
510-
}')
511-
est_current_model_json=$(jq -cn \
512-
--arg type "intra_system_scaling_model" \
513-
--arg name "instrumented-app-sections-current-scaling" \
514-
--arg version "$model_version" \
515-
--arg source_system "$baseline_system" \
516-
--arg target_system "$baseline_system" \
517-
--arg system_compatibility_rule "exact_match" \
518-
'{
519-
type: $type,
520-
name: $name,
521-
version: $version,
522-
source_system: $source_system,
523-
target_system: $target_system,
524-
system_compatibility_rule: $system_compatibility_rule
525-
}')
526-
est_future_model_json=$(jq -cn \
527-
--arg type "cross_system_projection_model" \
528-
--arg name "instrumented-app-sections-future-projection" \
529-
--arg version "$model_version" \
530-
--arg source_system "$est_system" \
531-
--arg target_system "$future_system" \
532-
--arg system_compatibility_rule "cross_system_allowed" \
533-
'{
534-
type: $type,
535-
name: $name,
536-
version: $version,
537-
source_system: $source_system,
538-
target_system: $target_system,
539-
system_compatibility_rule: $system_compatibility_rule
540-
}')
518+
est_model_json=$(bk_estimation_build_model_json_from_metadata \
519+
"top_level" \
520+
"" \
521+
"" \
522+
"section-wise" \
523+
"$model_name" \
524+
"" \
525+
"$model_version")
526+
est_current_model_json=$(bk_estimation_build_model_json_from_metadata \
527+
"current_system" \
528+
"$baseline_system" \
529+
"$baseline_system" \
530+
"intra_system_scaling_model" \
531+
"instrumented-app-sections-current-scaling" \
532+
"exact_match" \
533+
"$model_version")
534+
est_future_model_json=$(bk_estimation_build_model_json_from_metadata \
535+
"future_system" \
536+
"$est_system" \
537+
"$future_system" \
538+
"cross_system_projection_model" \
539+
"instrumented-app-sections-future-projection" \
540+
"cross_system_allowed" \
541+
"$model_version")
541542

542543
est_confidence_json='{"level":"experimental","score":0.20}'
543544
est_notes_json=$(jq -cn \

scripts/estimation/packages/weakscaling.sh

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ bk_estimation_package_metadata() {
4646
"fallback_policy": {
4747
"mode": "none",
4848
"target": null
49+
},
50+
"models": {
51+
"top_level": {
52+
"type": "section-wise",
53+
"name": "weakscaling"
54+
},
55+
"current_system": {
56+
"type": "intra_system_scaling_model",
57+
"name": "weakscaling-current",
58+
"system_compatibility_rule": "same_system_line"
59+
},
60+
"future_system": {
61+
"type": "intra_system_scaling_model",
62+
"name": "weakscaling-future",
63+
"system_compatibility_rule": "same_system_line"
64+
},
65+
"recorded_current": {
66+
"type": "intra_system_scaling_model",
67+
"name": "weakscaling-current",
68+
"system_compatibility_rule": "same_system_line"
69+
}
4970
}
5071
}
5172
EOF
@@ -133,10 +154,12 @@ bk_estimation_package_run() {
133154
local future_system="${BK_ESTIMATION_FUTURE_SYSTEM:-$est_system}"
134155
local current_target_nodes="${BK_ESTIMATION_CURRENT_TARGET_NODES:-$est_node_count}"
135156
local future_target_nodes="${BK_ESTIMATION_FUTURE_TARGET_NODES:-$est_node_count}"
136-
local model_name="${BK_ESTIMATION_MODEL_NAME:-weakscaling}"
137157
local model_version="${BK_ESTIMATION_MODEL_VERSION:-0.1}"
158+
local model_name
138159
local applicability_issues_json
139160

161+
model_name=$(bk_estimation_model_name_from_metadata "top_level" "weakscaling")
162+
140163
est_current_system="$current_system"
141164
est_current_target_nodes="$current_target_nodes"
142165
est_current_scaling_method="$model_name"
@@ -191,45 +214,30 @@ bk_estimation_package_run() {
191214
logp_section_rule: "sections bound to package logp are scaled with logP"
192215
}')
193216

194-
est_model_json=$(jq -cn \
195-
--arg type "section-wise" \
196-
--arg name "$model_name" \
197-
--arg version "$model_version" \
198-
--arg implementation "scripts/estimation/packages/weakscaling.sh" \
199-
'{
200-
type: $type,
201-
name: $name,
202-
version: $version,
203-
implementation: $implementation
204-
}')
205-
est_current_model_json=$(jq -cn \
206-
--arg type "intra_system_scaling_model" \
207-
--arg name "weakscaling-current" \
208-
--arg version "$model_version" \
209-
--arg source_system "$est_system" \
210-
--arg target_system "$current_system" \
211-
'{
212-
type: $type,
213-
name: $name,
214-
version: $version,
215-
source_system: $source_system,
216-
target_system: $target_system,
217-
system_compatibility_rule: "same_system_line"
218-
}')
219-
est_future_model_json=$(jq -cn \
220-
--arg type "intra_system_scaling_model" \
221-
--arg name "weakscaling-future" \
222-
--arg version "$model_version" \
223-
--arg source_system "$est_system" \
224-
--arg target_system "$future_system" \
225-
'{
226-
type: $type,
227-
name: $name,
228-
version: $version,
229-
source_system: $source_system,
230-
target_system: $target_system,
231-
system_compatibility_rule: "same_system_line"
232-
}')
217+
est_model_json=$(bk_estimation_build_model_json_from_metadata \
218+
"top_level" \
219+
"" \
220+
"" \
221+
"section-wise" \
222+
"$model_name" \
223+
"" \
224+
"$model_version")
225+
est_current_model_json=$(bk_estimation_build_model_json_from_metadata \
226+
"current_system" \
227+
"$est_system" \
228+
"$current_system" \
229+
"intra_system_scaling_model" \
230+
"weakscaling-current" \
231+
"same_system_line" \
232+
"$model_version")
233+
est_future_model_json=$(bk_estimation_build_model_json_from_metadata \
234+
"future_system" \
235+
"$est_system" \
236+
"$future_system" \
237+
"intra_system_scaling_model" \
238+
"weakscaling-future" \
239+
"same_system_line" \
240+
"$model_version")
233241

234242
est_confidence_json='{"level":"experimental","score":0.30}'
235243
est_notes_json=$(jq -cn \
@@ -241,20 +249,14 @@ bk_estimation_package_build_recorded_current_model_json() {
241249
local baseline_system="$1"
242250
local model_version="$2"
243251

244-
jq -cn \
245-
--arg type "intra_system_scaling_model" \
246-
--arg name "weakscaling-current" \
247-
--arg version "$model_version" \
248-
--arg source_system "$baseline_system" \
249-
--arg target_system "$baseline_system" \
250-
'{
251-
type: $type,
252-
name: $name,
253-
version: $version,
254-
source_system: $source_system,
255-
target_system: $target_system,
256-
system_compatibility_rule: "same_system_line"
257-
}'
252+
bk_estimation_build_model_json_from_metadata \
253+
"recorded_current" \
254+
"$baseline_system" \
255+
"$baseline_system" \
256+
"intra_system_scaling_model" \
257+
"weakscaling-current" \
258+
"same_system_line" \
259+
"$model_version"
258260
}
259261

260262
bk_estimation_package_apply_metadata() {

0 commit comments

Comments
 (0)