#!/usr/bin/env bash set -euo pipefail cd ~/LD-FPG-main/bbflow_base echo "===== patch latent.py: add q_sample_temperature =====" python - <<'PY' from pathlib import Path p = Path("bbflow/models/latent.py") s = p.read_text() old = ''' self.sample_coefficients = bool(getattr(latent_cfg, "sample_coefficients", False)) self.energy_from_q = bool(getattr(latent_cfg, "energy_from_q", False)) self.energy_from_q_full_cov = bool(getattr(latent_cfg, "energy_from_q_full_cov", False)) ''' new = ''' self.sample_coefficients = bool(getattr(latent_cfg, "sample_coefficients", False)) self.q_sample_temperature = float(getattr(latent_cfg, "q_sample_temperature", 1.0)) self.energy_from_q = bool(getattr(latent_cfg, "energy_from_q", False)) self.energy_from_q_full_cov = bool(getattr(latent_cfg, "energy_from_q_full_cov", False)) ''' if old not in s: if "q_sample_temperature" in s: print("[patch] latent.py already has q_sample_temperature init") else: raise SystemExit("[ERROR] could not find init insertion point in latent.py") else: s = s.replace(old, new) old = ''' selected_mu = mu[batch, component] selected_scale = scale_tril[batch, component] eps = torch.randn_like(selected_mu) coeff = selected_mu + torch.einsum("bij,bj->bi", selected_scale, eps) return coeff.to(dtype=condition["u_global"].dtype), component ''' new = ''' selected_mu = mu[batch, component] selected_scale = scale_tril[batch, component] temperature = float(getattr(self, "q_sample_temperature", 1.0)) if temperature != 1.0: selected_scale = selected_scale * temperature eps = torch.randn_like(selected_mu) coeff = selected_mu + torch.einsum("bij,bj->bi", selected_scale, eps) return coeff.to(dtype=condition["u_global"].dtype), component ''' if old not in s: if "q_sample_temperature" in s and "selected_scale = selected_scale * temperature" in s: print("[patch] latent.py already scales selected_scale by temperature") else: raise SystemExit("[ERROR] could not find sample_coefficients_from_q block in latent.py") else: s = s.replace(old, new) p.write_text(s) print("[patch] latent.py OK") PY echo "===== patch reproduction/02_sample_test.sh =====" python - <<'PY' from pathlib import Path p = Path("reproduction/02_sample_test.sh") s = p.read_text() old = '''INFERENCE_NUM_TIMESTEPS="${INFERENCE_NUM_TIMESTEPS:-20}" ''' new = '''INFERENCE_NUM_TIMESTEPS="${INFERENCE_NUM_TIMESTEPS:-20}" Q_SAMPLE_TEMPERATURE="${Q_SAMPLE_TEMPERATURE:-1.0}" ''' if old not in s: if "Q_SAMPLE_TEMPERATURE" in s: print("[patch] 02_sample_test.sh already has Q_SAMPLE_TEMPERATURE env") else: raise SystemExit("[ERROR] could not find INFERENCE_NUM_TIMESTEPS block") else: s = s.replace(old, new) old = ''' "inference.interpolant.sampling.num_timesteps=${INFERENCE_NUM_TIMESTEPS}" \\ "inference.log_times=true" ''' new = ''' "inference.interpolant.sampling.num_timesteps=${INFERENCE_NUM_TIMESTEPS}" \\ "+latent.q_sample_temperature=${Q_SAMPLE_TEMPERATURE}" \\ "inference.log_times=true" ''' if old not in s: if "+latent.q_sample_temperature" in s: print("[patch] 02_sample_test.sh already passes q temperature") else: raise SystemExit("[ERROR] could not find hydra override tail") else: s = s.replace(old, new) p.write_text(s) print("[patch] reproduction/02_sample_test.sh OK") PY echo "===== verify patch =====" grep -n "q_sample_temperature\\|Q_SAMPLE_TEMPERATURE" bbflow/models/latent.py reproduction/02_sample_test.sh