岗位特点
- 强调场景落地(外卖/到店/酒旅)
- 重视系统稳定性和性能
- 关注成本优化
- 看重问题解决能力
高频面试题
美团 Q1:大模型应用常见问题如何排查和缓解?
🧠 图解记忆: 先按链路定位证据,再对症缓解,最后用同一评测集验证改动是否真实有效。
💡 答案要点
题目: 列举LLM在实际应用中的主要问题,并针对每个问题给出解决方案。
答案要点:
问题1: 幻觉(Hallucination)
- 表现: 编造不存在的事实
- 原因: 概率预测,不是事实查询
- 解决方案:python
# 方案1: RAG def rag_answer(question): docs = vectordb.search(question) prompt = f"基于文档: {docs}\n回答: {question}" return llm.generate(prompt, temperature=0.2) # 方案2: Self-Consistency answers = [llm.generate(question) for _ in range(5)] final = most_common(answers) # 投票 # 方案3: 引用溯源 prompt = "回答问题并标注来源: {question}" - 效果: RAG降80%幻觉,Self-Consistency提升15%准确率
问题2: 长尾知识覆盖不足
- 表现: 专业/小众知识回答不准
- 解决方案:python
# 垂直领域微调 from peft import LoraConfig, get_peft_model lora_config = LoraConfig( r=8, lora_alpha=16, target_modules=["q_proj", "v_proj"], task_type="CAUSAL_LM" ) model = get_peft_model(base_model, lora_config) # 在专业数据上微调 trainer.train(medical_dataset) # 医疗数据
问题3: 数据新鲜度
- 表现: 知识截止到训练时间
- 解决方案:python
# 动态知识注入 def answer_with_search(question): # 1. 判断是否需要实时信息 if requires_realtime(question): # 2. 搜索最新信息 search_results = web_search(question) # 3. 结合搜索结果回答 prompt = f""" 最新信息: {search_results} 问题: {question} 回答: """ return llm.generate(prompt) else: return llm.generate(question)
问题4: 复读机问题
- 表现: 重复生成相同内容
- 原因: 温度过低或采样策略单一
- 解决方案:python
# 方案1: Repetition Penalty response = llm.generate( prompt, repetition_penalty=1.2 # >1惩罚重复 ) # 方案2: 多样性采样 response = llm.generate( prompt, temperature=0.7, top_p=0.9, top_k=50 ) # 方案3: 检测并重新生成 if has_repetition(response): response = llm.generate(prompt, temperature=0.9)
问题5: 推理计算和内存挑战
- 表现: 70B模型需要140GB显存
- 解决方案:python
# 方案1: 量化 from transformers import BitsAndBytesConfig quantization_config = BitsAndBytesConfig( load_in_4bit=True, # 4bit量化 bnb_4bit_compute_dtype=torch.float16 ) model = AutoModelForCausalLM.from_pretrained( "meta-llama/Llama-2-70b", quantization_config=quantization_config ) # 显存从140GB → 35GB # 方案2: 模型路由 def smart_routing(question): complexity = estimate_complexity(question) if complexity < 0.3: return llm_small.generate(question) # 7B elif complexity < 0.7: return llm_medium.generate(question) # 13B else: return llm_large.generate(question) # 70B # 成本降低60%
问题6: 偏见问题
- 表现: 性别/种族/地域偏见
- 解决方案:python
# RLHF + 人工反馈 # 1. 收集偏见案例 bias_cases = [ {"prompt": "CEO是...", "bad": "他", "good": "他/她"}, ] # 2. 训练Reward Model reward_model.train(bias_cases) # 3. PPO优化 ppo_trainer.train(policy_model, reward_model)
综合解决方案:
展开 Python 代码示例(40 行)
python
class RobustLLMSystem:
def __init__(self):
self.llm = load_model()
self.vectordb = VectorDB()
self.search_engine = WebSearch()
def generate(self, question):
# 1. 检测问题类型
question_type = self.classify_question(question)
# 2. 选择策略
if question_type == "factual":
# 事实类 → RAG
return self.rag_generate(question)
elif question_type == "realtime":
# 实时类 → 搜索
return self.search_generate(question)
elif question_type == "reasoning":
# 推理类 → Self-Consistency
return self.self_consistency_generate(question)
else:
# 通用
return self.llm.generate(question, temperature=0.7)
def rag_generate(self, question):
docs = self.vectordb.search(question)
prompt = f"基于: {docs}\n回答: {question}"
return self.llm.generate(prompt, temperature=0.2)
def search_generate(self, question):
results = self.search_engine.search(question)
prompt = f"参考: {results}\n回答: {question}"
return self.llm.generate(prompt)
def self_consistency_generate(self, question, n=5):
answers = [self.llm.generate(question, temperature=0.7) for _ in range(n)]
return most_common(answers)面试话术:
"LLM主要6大问题:1)幻觉用RAG+引用溯源降80%,2)长尾知识用LoRA微调覆盖,3)数据新鲜度用实时搜索,4)复读机用repetition_penalty惩罚,5)计算成本用4bit量化+模型路由降60%,6)偏见用RLHF纠正。美团场景下我用综合方案:事实类走RAG,实时类走搜索,推理类用Self-Consistency,不同问题不同策略,准确率提升25%成本降50%。"
