Views
No views yet
q_proj, k_proj, v_proj, and o_proj[last_token_pool ; mean_pool]LayerNorm -> Linear(4096, 256) -> GELU -> Dropout -> Linear(256, 64) -> GELU -> Dropout -> Linear(64, H)outputs.pred_depthsobservations is a compact summary of one local AUV observation window:depth: AUV depth in meters, using negative values underwater.T_grad: maximum absolute temperature difference inside the local sampled window.avg_T: average temperature inside the local sampled window.S_grad: maximum absolute salinity difference inside the local sampled window.avg_S: average salinity inside the local sampled window.1{
2 "season": "Winter",
3 "doy": 7,
4 "doy_sin": 0.1202,
5 "doy_cos": 0.9927,
6 "typical_thermocline_depth": "65-125 m",
7 "horizon": 5,
8 "observations": [
9 {"depth": -109.7, "T_grad": 0.6064, "avg_T": 16.46, "S_grad": 0.0075, "avg_S": 34.61},
10 {"depth": -174.3, "T_grad": 0.1081, "avg_T": 14.44, "S_grad": 0.0048, "avg_S": 34.55}
11 ]
12}1import json
2import torch
3from transformers import AutoModel, AutoTokenizer
4
5model_id = "zetian123123/thermo-qwen3-tsf"
6
7sample_json = """
8{
9 "season": "Winter",
10 "doy": 7,
11 "doy_sin": 0.1202,
12 "doy_cos": 0.9927,
13 "typical_thermocline_depth": "65-125 m",
14 "horizon": 5,
15 "observations": [
16 {"depth": -109.7, "T_grad": 0.6064, "avg_T": 16.46, "S_grad": 0.0075, "avg_S": 34.61},
17 {"depth": -174.3, "T_grad": 0.1081, "avg_T": 14.44, "S_grad": 0.0048, "avg_S": 34.55},
18 {"depth": -33.6, "T_grad": 2.7128, "avg_T": 24.29, "S_grad": 0.4870, "avg_S": 34.07}
19 ]
20}
21"""
22
23
24def build_prompt(sample):
25 season = sample["season"]
26 horizon = int(sample["horizon"])
27 obs_lines = []
28 for idx, obs in enumerate(sample["observations"], start=1):
29 obs_lines.append(
30 f"Step {idx:2d}: depth={obs['depth']:7.1f}m"
31 f" T_grad={obs['T_grad']:.4f} avg_T={obs['avg_T']:.2f}"
32 f" S_grad={obs['S_grad']:.4f} avg_S={obs['avg_S']:.2f}"
33 )
34
35 return (
36 f"<s><|im_start|>system\n"
37 f"You are an expert oceanographer. In {season}, predict the thermocline "
38 f"center depth (depth of maximum temperature gradient) for the next "
39 f"{horizon} timesteps based on AUV observations.<|im_end|>\n"
40 f"<|im_start|>user\n"
41 f"Season: {season} | DOY: {int(sample['doy'])} | "
42 f"sin={sample['doy_sin']:.4f} | cos={sample['doy_cos']:.4f}\n"
43 f"In {season}, thermocline typically at "
44 f"{sample['typical_thermocline_depth']}.\n\n"
45 f"[AUV Observations - {len(sample['observations'])} steps]\n"
46 + "\n".join(obs_lines)
47 + f"\n\nPredict thermocline center depth for the next {horizon} timesteps."
48 f"<|im_end|>\n"
49 f"<|im_start|>assistant\n"
50 )
51
52
53tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
54model = AutoModel.from_pretrained(model_id, trust_remote_code=True, torch_dtype="auto")
55model.eval()
56
57sample = json.loads(sample_json)
58prompt = build_prompt(sample)
59inputs = tokenizer(
60 prompt,
61 add_special_tokens=False,
62 max_length=1024,
63 padding="max_length",
64 truncation=True,
65 return_tensors="pt",
66)
67
68with torch.inference_mode():
69 outputs = model(**inputs)
70
71print(outputs.pred_depths.squeeze(0).tolist())outputs.logits: normalized depth predictions in [-1, 1]outputs.pred_depths: denormalized depths in meters-50 m.