Imagine you're at a startup. Your entire product lives in one codebase. As you scale to millions of users, you face the classic question: should you break it apart into microservices? When? How?
Monolith = one kitchen that cooks everything. Simple, fast to start. Microservices = a food court where each stall specializes. Great at scale, but way more management. Start with one kitchen; split when it gets too crowded.
💻
💻 Algorithms
💻 算法 Day 14 / Algorithms Day 14
▼
💻 算法 Day 14 / Algorithms Day 14
#42 Trapping Rain Water (Hard) — Two Pointers
🧩 Two Pointers (5/5) — building on the template from earlier days in this block
Key twist vs earlier problems: instead of comparing sums/areas, we compare leftMax and rightMax. The side with the smaller max can be finalized because its limiting wall is known.
如果 leftMax < rightMax:左边的水位上限已确定(被 leftMax 限制),可以计算 l 位置的水并 l += 1
否则:对称处理右边
Python 代码 / Python code
from typing import List
class Solution:
def trap(self, height: List[int]) -> int:
l, r = 0, len(height) - 1
left_max, right_max = 0, 0
water = 0while l < r:
if height[l] < height[r]:
# left side is bounded by left_maxif height[l] >= left_max:
left_max = height[l]
else:
water += left_max - height[l]
l += 1else:
# right side is bounded by right_maxif height[r] >= right_max:
right_max = height[r]
else:
water += right_max - height[r]
r -= 1return water
🔍 手动走一遍 / Quick trace
例子:[0,1,0,2,1,0,1,3,2,1,2,1]
开始 l=0, r=11, left_max=0, right_max=0, water=0
右边较高(1 vs 1 走 else),更新 right_max=1,r=10
当左边较小(0 < 2):左侧可结算,left_max=0,l=1
height[2]=0 时,left_max=1,水 += 1-0 = 1
... 最终累计 water=6
Why it works: the side with the smaller boundary max is the limiting factor, so we can safely finalize water there without knowing the exact interior structure.
Imagine filling water between blocks. A spot’s water level is capped by the shorter of the tallest block on its left and right. Two pointers walk inward, tracking those tallest blocks and adding water as you go.
🗣️
🗣️ Soft Skills
🗣️ 软技能 Day 14 / Soft Skills Day 14
▼
🗣️ 软技能 Day 14 / Soft Skills Day 14
Tell me about a time you drove a large cross-team initiative
For cross-team initiatives, the hardest part is rarely the technical design—it’s alignment, dependencies, cadence, and communication overhead. Interviewers want evidence you can lead without formal authority.
⭐ STAR 结构(建议 90 秒回答)/ STAR structure (aim for 90 seconds)
S — Situation(背景)
中文:项目是什么?影响范围多大?涉及哪些团队?
English: What was the initiative? Scope? Which teams?
T — Task(你的职责)
中文:你具体负责什么?目标/成功标准是什么(SLO、迁移比例、成本、上线日期)?
English: What did you own? What were the success metrics?
English: It’s like a big group project. First define what “success” means, split work and owners, check progress regularly, test the risky parts early, and keep everyone moving together.
English: A custom hook is a reusable recipe for state + side effects. You call the recipe in different components instead of rewriting the steps each time.
🤖
🤖 AI
🤖 AI Day 14
▼
🤖 AI Day 14
LoRA & QLoRA — Efficient Fine-Tuning
Mode: CONCEPT · Category: Training · Read time: 2 min
Full fine-tuning is rewriting the whole book: powerful but expensive and risky. LoRA freezes the base model and learns small low-rank “adapter” matrices (patches). QLoRA further quantizes the base model (e.g., 4-bit) to cut VRAM dramatically while still training LoRA adapters.
LoRA factorizes the weight update as ΔW = A·B with small rank r. You train only A and B (far fewer parameters). QLoRA quantizes the base weights (often 4-bit) and trains LoRA adapters on top, using careful compute dtypes/quantization tricks to keep quality.
✅ 什么时候用 / When to use
中文:
- 你想针对“特定任务/风格/领域语料”提升效果,但预算有限
- 你希望可控地“加能力”,并且随时能切换不同 adapter(一个基座多个 LoRA)
- 你需要在单卡/小显存环境训练
English:
- You need task/domain/style adaptation on a budget
- You want modular adapters you can swap (one base, many LoRAs)
- You’re constrained by VRAM (single GPU / smaller GPUs)
🧪 可运行示例(≤15 行)/ Runnable snippet (≤15 lines)
下面示例展示“加载 LoRA adapter”的最小思路(训练通常更长、代码更多)。
# pip install -U transformers peft torchfrom transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = "gpt2"# demo base model
lora_path = "./my_lora_adapter"# your saved LoRA adapter folder
tok = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base)
model = PeftModel.from_pretrained(model, lora_path)
prompt = "Write a short product update:"
print(tok.decode(model.generate(**tok(prompt, return_tensors="pt"), max_new_tokens=40)[0]))
📚 References
LoRA paper (arXiv): https://arxiv.org/abs/2106.09685
QLoRA paper (arXiv): https://arxiv.org/abs/2305.14314
Hugging Face PEFT docs: https://huggingface.co/docs/peft/index
LoRA is a small attachable add-on that changes behavior without rewriting the whole brain. QLoRA compresses the brain to save memory, then still learns those small add-ons.
Attention Heatmap
When the model processes it, it attends most strongly to animal.