ãã®èšäºã¯ã Fine-tune and deploy Llama 2 models cost-effectively in Amazon SageMaker JumpStart with AWS Inferentia and AWS Trainium ã翻蚳ãããã®ã§ãã æ¬æ¥ã Amazon SageMaker JumpStart ã«ããã AWS Trainium ããã³ AWS Inferentia ã€ã³ã¹ã¿ã³ã¹ã䜿çšãã Llama 2 æšè«ãšãã¡ã€ã³ãã¥ãŒãã³ã°ã®ãµããŒãã®æäŸãçºè¡šã§ããããšã倧å€å¬ããæããŸããSageMaker ãéã㊠AWS Trainium ããã³ AWS Inferentia ããŒã¹ã®ã€ã³ã¹ã¿ã³ã¹ã䜿çšããããšã§ããã¡ã€ã³ãã¥ãŒãã³ã°ã®ã³ã¹ããæå€§50%ãããŒã¯ã³ãããã®ã¬ã€ãã³ã·ãäœæžããªããããããã€ã¡ã³ãã³ã¹ãã 4.7 åäœæžã§ããŸããLlama 2 ã¯ãæé©åããã Transformer ã¢ãŒããã¯ãã£ãŒã䜿çšããèªå·±ååž°åã®ããã¹ãçæã¢ãã«ã§ããäžè¬ã«å©çšå¯èœãªã¢ãã«ãšããŠãLlama 2 ã¯ãããã¹ãåé¡ãææ
åæãèšèªç¿»èš³ãèšèªã¢ããªã³ã°ãããã¹ãçæã察話ã·ã¹ãã ãªã©ãå€ãã® èªç¶èšèªåŠçïŒNLPïŒã¿ã¹ã¯ã«åããŠèšèšãããŠããŸããLlama 2 ã®ãããªå€§èŠæš¡èšèªã¢ãã«ïŒLLMïŒã®ãã¡ã€ã³ãã¥ãŒãã³ã°ããããã€ã¯ãã³ã¹ãããããã ãã顧客äœéšãåäžãããããã®ãªã¢ã«ã¿ã€ã æ§èœãæºããããšãå°é£ã«ãªãããšããããŸããAWS Trainium ããã³ AWS Inferentia ã¯ã AWS Neuron ãœãããŠã§ã¢éçºããã(SDK)ã«ãã£ãŠå©çšå¯èœãšãªã£ãŠãããLlama 2 ã¢ãã«ã®ãã¬ãŒãã³ã°ãšæšè«ã«ãããŠã髿§èœãã€ã³ã¹ã广ã®é«ããªãã·ã§ã³ãæäŸããŸãã ãã®æçš¿ã§ã¯ãSageMaker JumpStart ã«ãã㊠AWS Trainium ãš AWS Inferentia ã€ã³ã¹ã¿ã³ã¹ã§ Llama 2 ããããã€ããã³ãã¡ã€ã³ãã¥ãŒãã³ã°ãè¡ãæ¹æ³ã瀺ããŸãã ãœãªã¥ãŒã·ã§ã³ã®æŠèŠ ãã®ããã°ã§ã¯ã以äžã®ã·ããªãªã«ã€ããŠèª¬æããŸãã Amazon SageMaker Studio UI ã§ã®ã¯ã³ã¯ãªãã¯ã§ã®ãããã€ããŸã㯠SageMaker Python SDK ãå©çšããŠã AWS Inferentia ã€ã³ã¹ã¿ã³ã¹ã« Llama 2 ã®ãããã€ãè¡ããŸãã SageMaker Studio UI ããã³ SageMaker Python SDK ã®äž¡æ¹ã§ AWS Trainium ã€ã³ã¹ã¿ã³ã¹äžã§ Llama 2 ã®ãã¡ã€ã³ãã¥ãŒãã³ã°ãè¡ããŸãã ãã¡ã€ã³ãã¥ãŒãã³ã°ããã Llama 2 ã¢ãã«ã®ããã©ãŒãã³ã¹ããäºååŠç¿ãããã¢ãã«ãšæ¯èŒãããã¡ã€ã³ãã¥ãŒãã³ã°ã®æå¹æ§ã瀺ããŸãã å®éã«åããéã¯ã GitHub ã®ãµã³ãã«ããŒããã㯠ãã芧ãã ããã SageMaker Studio UI ãš Python SDK ã䜿ã£ããAWS Inferentia ãžã® Llama 2 ã®ããã〠ãã®ã»ã¯ã·ã§ã³ã§ã¯ãSageMaker Studio UI ã䜿çšãã¯ã³ã¯ãªãã¯ã®ãããã€æäœãšPython SDK ã§ãLlama 2 ã AWS Inferentia ã€ã³ã¹ã¿ã³ã¹ã«ãããã€ããæ¹æ³ã瀺ããŸãã SageMaker Studio UI ã§ Llama 2 ã¢ãã«ãæ¢ã SageMaker JumpStart ã¯ãäžè¬ã«å
¬éãããŠãããã®ãšãããã©ã€ãšã¿ãªãª åºç€ã¢ãã« ã®äž¡æ¹ãžã®ã¢ã¯ã»ã¹ãæäŸããŸããåºç€ã¢ãã«ã¯ããµãŒãããŒãã£ããã³ãããã©ã€ãšã¿ãªãªãããã€ããŒããæäŸããã³ã¡ã³ããã³ã¹ãããŸãããã®ããããããã¯ã¢ãã«ã®ãœãŒã¹ã«ãã£ãŠæå®ãããç°ãªãã©ã€ã»ã³ã¹ã®äžã§ãªãªãŒã¹ãããŠããŸãã䜿çšããåºæ¬ã¢ãã«ã®ã©ã€ã»ã³ã¹ãå¿
ã確èªããŠãã ãããããŠã³ããŒããã³ã³ãã³ãã®äœ¿çšãè¡ãåã«ãé©çšãããã©ã€ã»ã³ã¹æ¡é
ã確èªãã䜿çšã±ãŒã¹ã«é©ããŠããããšã確èªãã責任ããããŸãã SageMaker JumpStart ãéããŠãSageMaker Studio UI ããã³ SageMaker Python SDK ã§ Llama 2 åºç€ã¢ãã«ã«ã¢ã¯ã»ã¹ã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãSageMaker Studio ã§ã¢ãã«ãæ€åºããæ¹æ³ã«ã€ããŠèª¬æããŸãã SageMaker Studio ã¯ãçµ±åéçºç°å¢ïŒIDEïŒã§ããããã¹ãŠã®æ©æ¢°åŠç¿ïŒMLïŒéçºã¹ããããå®è¡ããããã®ç¹å®çšéåãããŒã«ã«ã¢ã¯ã»ã¹ã§ããåäžã® Web ããŒã¹ã®ããžã¥ã¢ã«ã€ã³ã¿ãŒãã§ãŒã¹ãæäŸããŸããSageMaker Studio ã®éå§ãšã»ããã¢ããæ¹æ³ã®è©³çްã«ã€ããŠã¯ã ãã¡ã ãåç
§ããŠãã ããã SageMaker Studio ã«å
¥ããšãSageMaker JumpStart ã«ã¢ã¯ã»ã¹ã§ããŸããããã§ã¯ã Prebuilt and automated solutions ã®é
ç®ãããäºååŠç¿ãããã¢ãã«ãããŒãããã¯ãããã³äºåæ§ç¯ããããœãªã¥ãŒã·ã§ã³ãé²èЧã§ããŸãããããã©ã€ãšã¿ãªã¢ãã«ã«ã¢ã¯ã»ã¹ãã詳现æ
å ±ã«ã€ããŠã¯ã Use proprietary foundation models from Amazon SageMaker JumpStart in Amazon SageMaker Studio ãåç
§ããŠãã ããã SageMaker JumpStart ã®ã©ã³ãã£ã³ã°ããŒãžããã¯ããœãªã¥ãŒã·ã§ã³ãã¢ãã«ãããŒãããã¯ãããã³ãã®ä»ã®ãªãœãŒã¹ãé²èЧã§ããŸãã Llama 2 ã¢ãã«ã衚瀺ãããªãå Žåã¯ãSageMaker Studioãã·ã£ããããŠã³ããŠåèµ·åããŠããŒãžã§ã³ãæŽæ°ããŠãã ãããããŒãžã§ã³ã®æŽæ°ã«é¢ãã詳现ã¯ã Shut down and Update Studio Classic Apps ãåç
§ããŠãã ããã Explore All Text Generation Models ãéžæããããæ€çŽ¢ããã¯ã¹ã« ã llama ãŸã㯠neuron ãšå
¥åããããšã§ãä»ã®ã¢ãã«ããªãšãŒã·ã§ã³ãèŠã€ããããšãã§ããŸãã SageMaker Jumpstart ã«ãã Llama-2-13b ã¢ãã«ã®ããã〠ã¢ãã«ã«ãŒããéžæããŠãã©ã€ã»ã³ã¹ããã¬ãŒãã³ã°ã«äœ¿çšãããããŒã¿ãããã³äœ¿ç𿹿³ãªã©ã¢ãã«ã®è©³çްã衚瀺ã§ããŸãããŸãããã®ããŒã³ãŒãã®äŸã䜿çšããŠã¢ãã«ãå©çšããããã® Deploy ãã¿ã³ãš Open notebook ãã¿ã³ãèŠã€ããããšãã§ããŸãã ã©ã¡ããã®ãã¿ã³ãéžæãããšããããã¢ããã衚瀺ããããšã³ããŠãŒã¶ãŒã©ã€ã»ã³ã¹å¥çŽæžããã³å©çšèŠçŽïŒAUPïŒã衚瀺ãããŸãããããã«åæãããã©ããã確èªã§ããŸãã ããªã·ãŒã«æ¿èªãããšãã¢ãã«ã®ãšã³ããã€ã³ãããããã€ããããšãå¯èœã«ãªããæ¬¡ã®ã»ã¯ã·ã§ã³ã§ç€ºãããã«äœ¿ãããšãã§ããŸãã Python SDK ã«ãã Llama 2 Neuron ã¢ãã«ã®ããã〠Deploy ãéžæããŠããªã·ãŒã«åæãããšãã¢ãã«ã®ãããã€ãéå§ãããŸãããŸãã Open notebook ãéžæããŠäŸãšãªãããŒãããã¯ã䜿çšããããšãã§ããŸããããŒãããã¯ã«ã¯ãã¢ãã«ã®ãããã€ããæšè«ã®å®æœããªãœãŒã¹ã®ã¯ãªãŒã³ã¢ãããŸã§ã®äžé£ã®ã¬ã€ãã³ã¹ãèšè¿°ãããŠããŸãã AWS Trainium ãŸã㯠AWS Inferentia ã€ã³ã¹ã¿ã³ã¹äžã§ã¢ãã«ããããã€ãŸãã¯ãã¡ã€ã³ãã¥ãŒãã³ã°ããã«ã¯ããŸã PyTorch NeuronïŒ torch-neuronx ïŒãåŒã³åºããŠãã¢ãã«ã Neuron åºæã®ã°ã©ãã«ã³ã³ãã€ã«ããå¿
èŠããããŸããããã«ãããInferentia ã® NeuronCore ã«æé©åãããŸãããŠãŒã¶ãŒã¯ãã¢ããªã±ãŒã·ã§ã³ã®ç®çã«å¿ããŠãæå°ã®ã¬ã€ãã³ã·ãŸãã¯æå€§ã®ã¹ã«ãŒããããæé©åããããã«ã³ã³ãã€ã©ã«æç€ºã§ããŸããJumpStart ã§ã¯ãæ§ã
ãªæ§æã«å¯Ÿã㊠Neuron ã°ã©ããäºåã«ã³ã³ãã€ã«ããŠããããŠãŒã¶ãŒãã³ã³ãã€ã«æé ãçç¥ããè¿
éã«ã¢ãã«ããã¡ã€ã³ãã¥ãŒãã³ã°ããã³ãããã€ã§ããããã«ããŠããŸãã Neuron ã®äºåã³ã³ãã€ã«ãããã°ã©ãã¯ãç¹å®ã® Neuron Compiler ããŒãžã§ã³ã«åºã¥ããŠäœæãããŠããããšã«æ³šæããŠãã ããã AWS Inferentia ããŒã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§ LIama 2 ããããã€ããæ¹æ³ã¯ 2 ã€ãããŸããäžã€ç®ã®æ¹æ³ã¯ãäºåã«æ§ç¯ãããæ§æã䜿çšããããã 2 è¡ã®ã³ãŒãã§ã¢ãã«ããããã€ã§ããããã«ããŸããäºã€ç®ã®æ¹æ³ã§ã¯æ§æã«å¯ŸããŠãã现ããå¶åŸ¡ãå¯èœã§ãããŸããäžã€ç®ã®æ¹æ³ã§ããäºåæ§ç¯ã®æ§æã䜿çšããäŸãšããŠäºååŠç¿ãããLlama 2 13B Neuronã¢ãã«ã䜿çšããŠLlama 13Bãããã2è¡ã§ãããã€ããæ¹æ³ã以äžã«ç€ºããŸãã from sagemaker.jumpstart.model import JumpStartModel model_id = "meta-textgenerationneuron-llama-2-13b model = JumpStartModel(model_id=model_id) pretrained_predictor = model.deploy(accept_eula=False) ## To set 'accept_eula' to be True to deploy ãããã®ã¢ãã«ã§æšè«ãå®è¡ããã«ã¯ã model.deploy() ã®åŒã³åºãã®äžéšãšããŠã accept_eula åŒæ°ã True ã«æå®ããå¿
èŠããããŸãããã®åŒæ°ã True ã«èšå®ãããšãã¢ãã«ã® EULA ã«åæããããšã«ãªããŸããEULA ã¯ã¢ãã«ã«ãŒãã®èª¬æãŸã㯠Meta ã®ãŠã§ããµã€ã ããå
¥æã§ããŸãã Llama 2 13Bã®ããã©ã«ãã®ã€ã³ã¹ã¿ã³ã¹ã¿ã€ã㯠ml.inf2.8xlarge ã§ããä»ã®ãµããŒããããŠããã¢ãã«ã詊ãããšãã§ããŸãã meta-textgenerationneuron-llama-2-7b meta-textgenerationneuron-llama-2-7b-f ïŒãã£ããã¢ãã«ïŒ meta-textgenerationneuron-llama-2-13b-f ïŒãã£ããã¢ãã«ïŒ ãŸãããããã€ã®æ§æããã现ããå¶åŸ¡ãããå Žåãã³ã³ããã¹ãã®é·ãããã³ãœã«äžŠå床ãæå€§ããŒãªã³ã°ããããµã€ãºãªã©ãç°å¢å€æ°ãä»ããŠå€æŽããããšãã§ããŸãããããã€ã«äœ¿çšãã Deep Learning Container (DLC) 㯠Large Model Inference (LMI) NeuronX DLC ã§ããç°å¢å€æ°ã¯ä»¥äžã®éãã§ãã OPTION_N_POSITIONS â å
¥åããã³åºåããŒã¯ã³ã®æå€§æ°ãäŸãã°ã OPTION_N_POSITIONS ã 512 ã§ã¢ãã«ãã³ã³ãã€ã«ããå Žåãå
¥åããŒã¯ã³ã¯ 128ïŒå
¥åããã³ãããµã€ãºïŒãæå€§åºåããŒã¯ã³ã¯ 384ïŒå
¥åããã³åºåããŒã¯ã³ã®åèšã 512 ã«ãªãããã«ïŒã䜿çšã§ããŸããæå€§åºåããŒã¯ã³ã«ã€ããŠã¯ã384 以äžã®å€ãªãåé¡ãããŸãããããããè¶
ããŠã¯ãããŸããïŒäŸ: å
¥å 256 ããã³åºå 512ïŒã OPTION_TENSOR_PARALLEL_DEGREE â AWS Inferentia ã€ã³ã¹ã¿ã³ã¹ã§ã¢ãã«ãããŒããã NeuronCore ã®æ°ã OPTION_MAX_ROLLING_BATCH_SIZE â åæãªã¯ãšã¹ãã®æå€§ããããµã€ãºã OPTION_DTYPE â ã¢ãã«ãããŒãããããŒã¿ã¿ã€ãã Neuron ã°ã©ãã®ã³ã³ãã€ã«ã¯ãã³ã³ããã¹ãã®é·ã ( OPTION_N_POSITIONS )ããã³ãœã«äžŠå床 ( OPTION_TENSOR_PARALLEL_DEGREE )ãæå€§ããããµã€ãº ( OPTION_MAX_ROLLING_BATCH_SIZE )ãããã³ããŒã¿ã¿ã€ã ( OPTION_DTYPE ) ã«äŸåããŸããSageMaker JumpStart ã§ã¯ããããã®ãã©ã¡ãŒã¿ã®ããã®ããŸããŸãªæ§æã® Neuron ã°ã©ããäºåã«ã³ã³ãã€ã«ããŠãããã©ã³ã¿ã€ã ã®ã³ã³ãã€ã«ãåé¿ããããã®èšå®ã衚ã«èšèŒãããŠããŸããç°å¢å€æ°ã以äžã®ã«ããŽãªã®ããããã«è©²åœããå ŽåãNeuron ã°ã©ãã®ã³ã³ãã€ã«ã¯ã¹ããããããŸãã LIama-2 7B and LIama-2 7B Chat Instance type OPTION_N_POSITIONS OPTION_MAX_ROLLING_BATCH_SIZE OPTION_TENSOR_PARALLEL_DEGREE OPTION_DTYPE ml.inf2.xlarge 1024 1 2 fp16 ml.inf2.8xlarge 2048 1 2 fp16 ml.inf2.24xlarge 4096 4 4 fp16 ml.inf2.24xlarge 4096 4 8 fp16 ml.inf2.24xlarge 4096 4 12 fp16 ml.inf2.48xlarge 4096 4 4 fp16 ml.inf2.48xlarge 4096 4 8 fp16 ml.inf2.48xlarge 4096 4 12 fp16 ml.inf2.48xlarge 4096 4 24 fp16 LIama-2 13B and LIama-2 13B Chat ml.inf2.8xlarge 1024 1 2 fp16 ml.inf2.24xlarge 2048 4 4 fp16 ml.inf2.24xlarge 4096 4 8 fp16 ml.inf2.24xlarge 4096 4 12 fp16 ml.inf2.48xlarge 2048 4 4 fp16 ml.inf2.48xlarge 4096 4 8 fp16 ml.inf2.48xlarge 4096 4 12 fp16 ml.inf2.48xlarge 4096 4 24 fp16 以äžã¯ãLlama 2 13B ã®ãããã€ãšèšå®ã®äŸã«ãªããŸãã from sagemaker.jumpstart.model import JumpStartModel model_id = "meta-textgenerationneuron-llama-2-13b-f" model = JumpStartModel( model_id=model_id, env={ "OPTION_DTYPE": "fp16", "OPTION_N_POSITIONS": "4096", "OPTION_TENSOR_PARALLEL_DEGREE": "12", "OPTION_MAX_ROLLING_BATCH_SIZE": "4", }, instance_type="ml.inf2.24xlarge" ) pretrained_predictor = model.deploy(accept_eula=False) ## To set 'accept_eula' to be True to deploy ããã§ Llama-2-13b ã¢ãã«ããããã€ããã®ã§ããšã³ããã€ã³ããåŒã³åºãããšã§æšè«ãå®è¡ã§ããŸãã以äžã§ã¯ããµããŒããããŠããæšè«æã®èšå®ãã©ã¡ãŒã¿ã瀺ããŠããŸãã max_length â åºåã®é·ãïŒå
¥åã®ã³ã³ããã¹ãé·ãå«ãïŒã max_length ã«éãããŸã§ã¢ãã«ã¯ããã¹ããçæããŸããæå®ãããå Žåãæ£ã®æŽæ°ã§ããå¿
èŠããããŸãã max_new_tokens â åºåã®é·ãïŒå
¥åã®ã³ã³ããã¹ãé·ãé€ãïŒã max_new_tokens ã«éãããŸã§ã¢ãã«ã¯ããã¹ããçæããŸããæå®ãããå Žåãæ£ã®æŽæ°ã§ããå¿
èŠããããŸãã num_beams â 貪欲æ³ã§äœ¿çšãããããŒã ã®æ°ã瀺ããŸããæå®ãããå Žåã num_return_sequences 以äžã®æŽæ°ã§ããå¿
èŠããããŸãã no_repeat_ngram_size â åºåã·ãŒã±ã³ã¹ã§ no_repeat_ngram_size ã®åèªã®äžŠã³ãç¹°ãè¿ãããªãããã«ã¢ãã«ãä¿èšŒããŸããæå®ãããå Žåãæ£ã®æŽæ°ã§ 1 ãã倧ããå¿
èŠããããŸãã temperature â åºåã®ã©ã³ãã æ§ãå¶åŸ¡ããŸããé«ã枩床ã§ã¯äœç¢ºçã®åèªã®åºåã·ãŒã±ã³ã¹ãçæãããäœã枩床ã§ã¯é«ç¢ºçã®åèªã®åºåã·ãŒã±ã³ã¹ãçæãããŸãã temperature ã 0 ã®å Žåã貪欲ãªãã³ãŒãã£ã³ã°ãè¡ãããŸããæå®ãããå Žåãæ£ã®æµ®åå°æ°ç¹æ°ã§ããå¿
èŠããããŸãã early_stopping â True ã®å Žåããã¹ãŠã®ããŒã ã®ä»®èª¬ãæã®çµç«¯ããŒã¯ã³ã«å°éããæç¹ã§ããã¹ãçæãçµäºããŸããæå®ãããå Žåã Boolean ã§ããå¿
èŠããããŸãã do_sample â True ã®å Žåãã¢ãã«ã¯æ¬¡ã®åèªã尀床ã«åŸã£ãŠãµã³ããªã³ã°ããŸããæå®ãããå Žåã Boolean ã§ããå¿
èŠããããŸãã top_k â ããã¹ãçæã®åã¹ãããã§ãã¢ãã«ã¯ top_k ã§æãå°€ããããåèªãããµã³ããªã³ã°ããŸããæå®ãããå Žåãæ£ã®æŽæ°ã§ããå¿
èŠããããŸãã top_p â ããã¹ãçæã®åã¹ãããã§ãã¢ãã«ã¯ top_p ã®çޝç©ç¢ºçã§æå°ã®å¯èœãªåèªã®ã»ãããããµã³ããªã³ã°ããŸããæå®ãããå Žåã0 ãã 1 ã®æµ®åå°æ°ç¹æ°ã§ããå¿
èŠããããŸãã stop â æå®ãããå Žåãæååã®ãªã¹ãã§ããå¿
èŠããããŸããæå®ãããæååã®ãããããçæãããå Žåãããã¹ãçæã¯åæ¢ããŸãã 以äžã¯æšè«ã³ãŒãã®äŸã瀺ããŠããŸãã payload = { "inputs": "I believe the meaning of life is", "parameters": { "max_new_tokens": 64, "top_p": 0.9, "temperature": 0.6, }, } response = pretrained_predictor.predict(payload) åºåã¯ä»¥äžã«ãªããŸãã I believe the meaning of life is > to be happy. I believe that happiness is a choice. I believe that happiness is a state of mind. I believe that happiness is a state of being. I believe that happiness is a state of being. I believe that happiness is a state of being. I believe that happiness is a state of being. I believe ãã©ã¡ãŒã¿ã«é¢ããè©³çŽ°ãªæ
å ±ã«ã€ããŠã¯ã ãã¡ã ãåç
§ããŠãã ããã SageMaker Studio UI ãš SageMaker Python SDK ã䜿çšãããTrainium ã€ã³ã¹ã¿ã³ã¹ã§ã® Llama 2 ã¢ãã«ã®ãã¡ã€ã³ãã¥ãŒãã³ã° çæ AI ã®åºç€ã¢ãã«ã¯ãæ©æ¢°åŠç¿ïŒMLïŒããã³äººå·¥ç¥èœïŒAIïŒã®äž»èŠãªçŠç¹ãšãªã£ãŠããŸãããããŸããŸãªé åã«ãããæ±åã¯ããã«ã¹ã±ã¢ãéèãµãŒãã¹ãªã©ç¹å®ã®é åã§ç¬èªã®ããŒã¿ãé¢äžããå Žåã«ã¯äžååãªå ŽåããããŸãããã®ããšã¯ãçæ AI ã¢ãã«ãç¹å®ã®é åã«ãããŠããã©ãŒãã³ã¹ãåäžãããããã«ããã¡ã€ã³åºæã®ããŒã¿ã§ãã¡ã€ã³ãã¥ãŒãã³ã°ãå¿
èŠã§ããããšã匷調ããŠããŸãã äºååŠç¿æžã¿ã® Llama 2 ã¢ãã«ããããã€ããŸãããããã®ã¢ãã«ããã¡ã€ã³åºæã®ããŒã¿ã§ãã¡ã€ã³ãã¥ãŒãã³ã°ããæ£ç¢ºæ§ãåäžãããããã³ããã®è£å®ãæ¹åããã¢ãã«ãç¹å®ã®ããžãã¹ãŠãŒã¹ã±ãŒã¹ãšããŒã¿ã«é©å¿ãããæ¹æ³ãèŠãŠã¿ãŸããããã¢ãã«ã®ãã¡ã€ã³ãã¥ãŒãã³ã°ã¯ãSageMaker Studio UI ãŸãã¯SageMaker Python SDK ã®ããããã䜿çšããŠè¡ãããšãã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãäž¡æ¹ã®æ¹æ³ã«ã€ããŠèª¬æããŸãã SageMaker Studioã䜿çšãã Llama-2-13b Neuron ã¢ãã«ã®ãã¡ã€ã³ãã¥ãŒãã³ã° SageMaker Studio ã«å
¥ããLlama-2-13b Neuron ã¢ãã«ã«ç§»åããŸãã Deploy ã¿ãã§ããã¡ã€ã³ãã¥ãŒãã³ã°ã®ããã®ãã¬ãŒãã³ã°ããã³æ€èšŒããŒã¿ã»ãããå«ãŸãã Amazon Simple Storage Service (Amazon S3) ãã±ãããæå®ã§ããŸããããã«ããã¡ã€ã³ãã¥ãŒãã³ã°ã®ããã®ãããã€èšå®ããã€ããŒãã©ã¡ãŒã¿ãããã³ã»ãã¥ãªãã£èšå®ãæ§æããããšãã§ããŸãããã®åŸãSageMaker ML ã€ã³ã¹ã¿ã³ã¹äžã§ãã¬ãŒãã³ã°ãžã§ããéå§ããããã« Train ãéžæããŸãã Llama 2 ã¢ãã«ã䜿çšããã«ã¯ãEULA ããã³ AUP ã«åæããå¿
èŠããããŸãã Train ãéžæãããšãããã衚瀺ãããŸãããã¡ã€ã³ãã¥ãŒãã³ã°ãžã§ããéå§ããããã«ã¯ã I have read and accept EULA and AUP ãéžæããŠãã ããã ãã¡ã€ã³ãã¥ãŒãã³ã°ãããã¢ãã«ã®ãã¬ãŒãã³ã°ãžã§ãã®ã¹ããŒã¿ã¹ã¯ãSageMaker ã³ã³ãœãŒã«ã®ããã²ãŒã·ã§ã³ãã€ã³ã§ Training jobs ãéžæããããšã§ç¢ºèªã§ããŸãã ãã®ããŒã³ãŒãã®äŸã䜿çšããŠLlama 2 Neuron ã¢ãã«ããã¡ã€ã³ãã¥ãŒãã³ã°ããããæ¬¡ã®ã»ã¯ã·ã§ã³ã§ç€ºãããã« Python SDK ã䜿çšããŠãã¡ã€ã³ãã¥ãŒãã³ã°ããããšãã§ããŸãã SageMaker Python SDK ã䜿çšãã Llama-2-13b Neuron ã¢ãã«ããã¡ã€ã³ãã¥ãŒãã³ã° ãã¡ã€ã³é©å¿ã®åœ¢åŒãŸã㯠åœä»€ããŒã¹ã®ãã¡ã€ã³ãã¥ãŒãã³ã°åœ¢åŒ ã®ããŒã¿ã»ããã§ãã¡ã€ã³ãã¥ãŒãã³ã°ããããšãã§ããŸãã以äžã¯ããã¡ã€ã³ãã¥ãŒãã³ã°ãè¡ãåã«ãã¬ãŒãã³ã°ããŒã¿ãã©ã®ããã«ãã©ãŒããããããã®æé ã§ãã Input â JSON lines (.jsonl) ãŸãã¯ããã¹ã (.txt) 圢åŒã®ãã¡ã€ã«ãå«ãŸããŠãã train ãã£ã¬ã¯ããªã§ãã JSON lines (.jsonl) ãã¡ã€ã«ã®å Žåãåè¡ã¯åå¥ã® JSON ãªããžã§ã¯ãã§ããå JSON ãªããžã§ã¯ãã¯ãããŒã text ã§ãããå€ã 1 ã€ã®ãã¬ãŒãã³ã°äŸã®å
容ã§ããããŒãšå€ã®ãã¢ã«æ§é åãããå¿
èŠããããŸãã train ãã£ã¬ã¯ããªå
ã®ãã¡ã€ã«æ°ã¯ 1 ãšçããããå¿
èŠããããŸãã Output â æšè«ã«ãããã€ã§ãããã¬ãŒãã³ã°ãããã¢ãã«ã§ãã ãã®äŸã§ã¯ãåœä»€ããŒã¹ã®ãã¡ã€ã³ãã¥ãŒãã³ã°åœ¢åŒã§ Dolly ããŒã¿ã»ãã ã®ãµãã»ããã䜿çšããŠããŸããDolly ããŒã¿ã»ããã«ã¯ã質åå¿çãèŠçŽãæ
å ±æœåºãªã©ã®ããŸããŸãªã«ããŽãªã®çŽ 15,000 ã®åœä»€ã«åŸã£ãã¬ã³ãŒããå«ãŸããŠããŸããããã¯Apache 2.0ã©ã€ã»ã³ã¹ã®ããšã§å©çšå¯èœã§ãããã¡ã€ã³ãã¥ãŒãã³ã°ã«ã¯ information_extraction ã®äŸã䜿çšããŠããŸãã Dolly ããŒã¿ã»ãããããŒããã train ïŒãã¡ã€ã³ãã¥ãŒãã³ã°çšïŒãš test ïŒè©äŸ¡çšïŒã«åå²ããŸãã from datasets import load_dataset dolly_dataset = load_dataset("databricks/databricks-dolly-15k", split="train") task = "information_extraction" To train for summarization/closed question and answering, you can replace the assertion in next line to example["category"] == "sumarization"/"closed_qa". summarization_dataset = dolly_dataset.filter(lambda example: example["category"] == task) summarization_dataset = summarization_dataset.remove_columns("category") We split the dataset into two where test data is used to evaluate at the end. train_and_test_dataset = summarization_dataset.train_test_split(test_size=0.1) Dumping the training data to a local file to be used for training. train_and_test_dataset["train"].to_json("train.jsonl") 2. ãã¬ãŒãã³ã°ãžã§ãã®ããã®ã€ã³ã¹ãã©ã¯ã·ã§ã³åœ¢åŒã®ããŒã¿ã®ååŠçã«ã¯ãããã³ããã®ãã³ãã¬ãŒãã䜿çšããŸãã prompt = ("""Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\n{instruction}\n\n### Input:\n{context}### Response:\n{response}\n\n<s>""") ãã€ããŒãã©ã¡ãŒã¿ãŒãæ€èšŒãããŠãŒã¹ã±ãŒã¹ã«å¿ããŠäžæžããè¡ããŸãã from sagemaker import hyperparameters model_id = "meta-textgenerationneuron-llama-2-13b" model_version = "1.*" my_hyperparameters = hyperparameters.retrieve_default( model_id=model_id, model_version=model_version ) my_hyperparameters["max_input_length"] = "4096" ## you can increase it up to 4096 for sequence length. my_hyperparameters["max_steps"] = "25" my_hyperparameters["learning_rate"] = "0.0001" print(my_hyperparameters) hyperparameters.validate(model_id=model_id, model_version=model_version, hyperparameters=my_hyperparameters) 4. ã¢ãã«ããã¡ã€ã³ãã¥ãŒãã³ã°ããSageMaker ãã¬ãŒãã³ã°ãžã§ããéå§ããŸãããã¡ã€ã³ãã¥ãŒãã³ã°ã¹ã¯ãªããã¯ã neuronx-nemo-megatron ãªããžããªã«åºã¥ããŠããããã㯠Neuron ããã³ EC2 Trn1 ã€ã³ã¹ã¿ã³ã¹ã§ã®äœ¿çšã«é©å¿ããã NeMo ãš Apex ããã±ãŒãžã®ããŒãžã§ã³ã§ããneuronx-nemo-megatron ãªããžããªã«ã¯ãLLM ãã¹ã±ãŒã«ããŠãã¡ã€ã³ãã¥ãŒãã³ã°ããããã® 3DïŒããŒã¿ããã³ãœã«ãããã³ãã€ãã©ã€ã³ïŒäžŠååŠçãåãã£ãŠããŸãããµããŒããããŠãã Trainium ã€ã³ã¹ã¿ã³ã¹ã¯ ml.trn1.32xlarge ããã³ ml.trn1n.32xlarge ã§ãã from sagemaker.jumpstart.estimator import JumpStartEstimator estimator = JumpStartEstimator( model_id=model_id, model_version=model_version, hyperparameters=my_hyperparameters, environment={"accept_eula": "false"}, # please change `accept_eula` to be `true` to accept EULA. #instance_type="ml.trn1n.32xlarge", if not specified, default `ml.trn1.32xlarge` will be used. ) estimator.fit({"train": train_data_location}) 5. æåŸã«ããã¡ã€ã³ãã¥ãŒãã³ã°ãããã¢ãã«ã SageMaker ãšã³ããã€ã³ããžãããã€ããŸãã finetuned_predictor = estimator.deploy() äºååŠç¿æžã¿ãšãã¡ã€ã³ãã¥ãŒãã³ã°ããã Llama 2 Neuron ã¢ãã«ã®ã¬ã¹ãã³ã¹ã®æ¯èŒ Llama-2-13b ã®äºååŠç¿æžã¿ã¢ãã«ãšãã¡ã€ã³ãã¥ãŒãã³ã°ãããã¢ãã«ã®ããã³ããè£å®ã®æ§èœæ¯èŒã以äžã®è¡šã«ç€ºããŸãããŸããSEC Filing ããŒã¿ã»ããã. txt 圢åŒã§äœ¿çšã㊠Llama 2 ããã¡ã€ã³ãã¥ãŒãã³ã°ããäŸãæäŸããŠããŸãã詳现ã«ã€ããŠã¯ãGitHubã®ãµã³ãã« ããŒããã㯠ãåç
§ããŠãã ããã Item Inputs Ground truth Response from non-finetuned model Response from fine-tuned model 1 Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nExtract universities Moret studied at and his year of graduation for each, and put them in a bulleted list.\n\n### Input:\nMoret was born in 1953 in Vevey Switzerland, and did his undergraduate studies at the Ãcole Polytechnique Fédérale de Lausanne (EPFL), graduating in 1975. He went on to graduate studies at the University of Tennessee, earning a Ph.D. in 1980. He then joined the faculty of the University of New Mexico, where he remained until 2006, when he moved to EPFL. He retired from EPFL in December 2016.\n\nIn 1996, Moret founded the ACM Journal of Experimental Algorithmics, and he remained editor in chief of the journal until 2003. In 2001, Moret founded the Workshop in Algorithms for Bioinformatics (WABI) and remains on the Steering Committee for the conference.\n\nIn 2018, Moret was elected as a Fellow of the International Society for Computational Biology, for his outstanding contributions to the fields of computational biology and bioinformatics.\n\n### Response:\n * Ãcole Polytechnique Fédérale de Lausanne (EPFL) (graduated 1975)\n* University of Tennessee (graduated 1980) Moret studied at the Ãcole Polytechnique Fédérale de Lausanne (EPFL) and the University of Tennessee, graduating in1975 and1980, respectively.\n\n### Hint:\n\n- Use the `split` function to split the input into a list of sentences.\n- Use the `split` function to split each sentence into a list of words.\n- Use the `split` function to split â Ãcole Polytechnique Fédérale de Lausanne (EPFL),1975\n- University of Tennessee,1980\n- University of New Mexico\n- Ãcole Polytechnique Fédérale de Lausanne (EPFL),2006\n\n<s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n 2 Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nFrom the passage identify the attributes of Dionysus. Display the results in a comma separated format.\n\n### Input:\nDionysus (ÎιÏΜÏ
ÏοÏ, Diónusos)/Bacchus (ÎάκÏοÏ, Bákkhos)\n\nGod of wine, fruitfulness, parties, festivals, madness, chaos, drunkenness, vegetation, ecstasy, and the theater. He is the twice-born son of Zeus and Semele, in that Zeus snatched him from his motherâs womb and stitched Dionysus into his own thigh and carried him until he was ready to be born. In art he is depicted as either an older bearded god (particularly before 430 BC) or an effeminate, long-haired youth (particularly after 430 BC). His attributes include the thyrsus, a drinking cup, the grape vine, and a crown of ivy. He is often in the company of his thiasos, a group of attendants including satyrs, maenads, and his old tutor Silenus. The consort of Dionysus was Ariadne. It was once held that Dionysius was a later addition to the Greek pantheon, but the discovery of Linear B tablets confirm his status as a deity from an early period. Bacchus was another name for him in Greek, and came into common usage among the Romans. His sacred animals include dolphins, serpents, tigers, and donkeys.\n\n### Response:\n the thyrsus, a drinking cup, the grape vine, a crown of ivy Dionysus (ÎιÏΜÏ
ÏοÏ, Diónusos)\n\nGod of wine, fruitfulness, parties, festivals, madness, chaos, drunkenness, vegetation, ecstasy, and the theater. He is the twice-born son of Zeus and Semele, in that Zeus snatched him from his motherâs womb and stitched Dionysus into his own thigh thyrsus, a drinking cup, the grape vine, a crown of ivy\n\n<s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWhat is the difference between Parthian and Arsacid Empire?\n\n### Input:\nThe Parthian Empire, also known as the Arsacid Empire was a 3 Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWhy does the capital of Uzbekistan contain the biggest Greek community?\n\n### Input:\nThe Greeks in Uzbekistan number approximately 9,000. The community is made up of Greeks from Russia who were deported by force from that country to Uzbekistan in the 1940s, and political refugees from Greece. About 30,000 Greeks lived in the country before World War II and a further 11,000 arrived after the Greek Civil War and the defeat of Democratic Army of Greece. Their numbers have dwindled from a high of some 40,000 in the 1960s. The main reason is emigration to Greece after the end of the Cold War when laws allowed the return of all ethnic Greeks who had been exiled for political reasons after the Greek Civil War. The biggest Greek community in the country is in the capital city of Tashkent where most of the Greek political refugees were relocated by the Soviet authorities. In ancient times the south of the country was part of the Hellenistic Seleucid Kingdom but the few Greek communities there have since assimilated. The most important organization representing ethnic Greeks is the Greek Cultural Association of Tashkent. The activities of this organization include Greek language instruction (19 classes with a total of 571 students, classes for adults) and the teaching of Greek dances and music.\n\n### Response:\n Most of the Greek political refugees in Uzbekistan were relocated by the Soviet authorities to the capital city of Tashkent. \nâ`\nThe capital of Uzbekistan contains the biggest Greek community because the Greeks in Uzbekistan number approximately9,000. The community is made up of Greeks from Russia who were deported by force from that country to Uzbekistan in the1940s, and political refugees from Greece. About30,000 Greeks lived in the country before World War II and a further11,00 The capital of Uzbekistan contains the biggest Greek community because that is where most of the Greek political refugees were relocated by the Soviet authorities after being deported from Greece.\n\n<s> Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n### Instruction:\nWhat is the difference between Parthian and Arsacid Empire?\n\n### Input:\n ãã¡ã€ã³ãã¥ãŒãã³ã°ã¢ãã«ããã®å¿çã¯ãäºååŠç¿æžã¿ã¢ãã«ãšæ¯èŒããŠç²ŸåºŠãé¢é£æ§ãæç¢ºãã§èããæ¹åã瀺ããŠããŸããããã€ãã®ã±ãŒã¹ã§ã¯ããŠãŒã¹ã±ãŒã¹ã«å¯ŸããŠäºååŠç¿æžã¿ã¢ãã«ã䜿çšããã ãã§ã¯ååã§ãªãå Žåãããããã®ãã¯ããã¯ã䜿çšããŠãã¡ã€ã³ãã¥ãŒãã³ã°ããããšã§ã解決çãããŒã¿ã»ããã«ããããŒãœãã©ã€ãºãå¯èœãšãªããŸãã ã¯ãªãŒã³ã¢ãã ãã¬ãŒãã³ã°ãžã§ããå®äºããæ¢åã®ãªãœãŒã¹ããã䜿çšããªãå Žåã¯ã以äžã®ã³ãŒãã䜿çšããŠãªãœãŒã¹ãåé€ã§ããŸãã # Delete resources # Delete the fine-tuned model finetuned_predictor.delete_model() # Delete the fine-tuned model endpoint finetuned_predictor.delete_endpoint() çµè« Llama 2 Neuron ã¢ãã«ã® SageMaker äžã§ã®ãããã€ããã³ãã¡ã€ã³ãã¥ãŒãã³ã°ã¯ãå€§èŠæš¡ãªçæAIã¢ãã«ã®ç®¡çãšæé©åã«ãããŠèãã鲿©ã瀺ããŠããŸããLlama-2-7b ã Llama-2-13b ãªã©ã®ããªãšãŒã·ã§ã³ãå«ãã ã¢ãã«ã¯ãNeuron ã䜿çšããŠAWS Inferentia ããã³ AWS Trainium ããŒã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§å¹ççãªãã¬ãŒãã³ã°ãšæšè«ãè¡ããããã©ãŒãã³ã¹ãšæ¡åŒµæ§ãåäžãããŠããŸãã ãããã®ã¢ãã«ã¯ SageMaker JumpStart UI ããã³ Python SDK ãéããŠæè»ãã€ç°¡äŸ¿ã«ãããã€ããããšãã§ããŸããNeuron SDK ã¯ãäžè¬çãªMLãã¬ãŒã ã¯ãŒã¯ã®ãµããŒããšé«æ§èœãªæ©èœãåããŠããããããã®å€§èŠæš¡ãªã¢ãã«ãå¹ççã«åŠçã§ããããã«ããŠããŸãã ãããã®ã¢ãã«ãç¹å®ã®ãã¡ã€ã³ã«ç¹åããããŒã¿ã§ãã¡ã€ã³ãã¥ãŒãã³ã°ããããšã¯ãå°éåéã«ãããŠé¢é£æ§ãšç²ŸåºŠãåäžãããããã«éèŠã§ãããã®ããã»ã¹ã¯ãSageMaker Studio UI ã Python SDK ã䜿çšããŠå®è¡ã§ããç¹å®ã®ããŒãºã«åãããŠã«ã¹ã¿ãã€ãºãå¯èœã§ãããããã³ããã®è£å®ãšå¿çã®å質ã®åäžã«ã€ãªãããŸãã ãããã®ã¢ãã«ã®äºååŠç¿æžã¿ããŒãžã§ã³ã¯åŒ·åã§ãããäžè¬çãŸãã¯ç¹°ãè¿ãã®å¿çãæäŸããå¯èœæ§ããããŸãããã¡ã€ã³ãã¥ãŒãã³ã°ã¯ã¢ãã«ãç¹å®ã®æèã«åãããããæ£ç¢ºã§é¢é£æ§ãããã倿§ãªå¿çããããããŸãããã®ã«ã¹ã¿ãã€ãºã¯ç¹ã«ãäºååŠç¿æžã¿ãšãã¡ã€ã³ãã¥ãŒãã³ã°ããã¢ãã«ã®å¿çãæ¯èŒããéã«é¡èã§ãããåŸè
ã¯åºåã®å質ãšå°éæ§ã«ãããŠæãããªæ¹åã瀺ããŠããŸããçµè«ãšããŠãSageMaker äžã§ã® Neuron Llama 2 ã¢ãã«ã®ãããã€ãšãã¡ã€ã³ãã¥ãŒãã³ã°ã¯ãå
é²ç㪠AI ã¢ãã«ã®ç®¡çã«å¯Ÿããå
ç¢ãªãã¬ãŒã ã¯ãŒã¯ã衚ããç¹ã«ç¹å®ã®ãã¡ã€ã³ãã¿ã¹ã¯ã«åãããŠèª¿æŽãããå Žåã«ã¯ãæ§èœãšé©çšç¯å²ã§èããæ¹åãæäŸããŠããŸãã ãµã³ãã« ããŒããã㯠ãåç
§ããŠãã²å§ããŠã¿ãŸãããã GPU ããŒã¹ã®ã€ã³ã¹ã¿ã³ã¹ã§äºååŠç¿æžã¿ Llama 2 ã¢ãã«ããããã€ããã³ãã¡ã€ã³ãã¥ãŒãã³ã°ãã詳现ã«ã€ããŠã¯ã Fine-tune Llama 2 for text generation on Amazon SageMaker JumpStart ããã³ Llama 2 foundation models from Meta are now available in Amazon SageMaker JumpStart ãåç
§ããŠãã ããã