import json import os from huggingface_hub import snapshot_download from sagemaker.s3 import S3Uploader tmp_dir = "./tmp" medusa_repository = "text-generation-inference/Mixtral-8x7B-Instruct-v0.1-medusa" # Medusa model # https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-AWQ/discussions/6 llm_repository = "ybelkada/Mixtral-8x7B-Instruct-v0.1-AWQ" # AWQ LLM model snapshot_download(repo_id=medusa_repository, local_dir=tmp_dir) snapshot_download(repo_id=llm_repository, local_dir=os.path.join(tmp_dir, "llm"),ignore_patterns="*.bin") # rewrite meudsa base model value with open(os.path.join(tmp_dir, "config.json"), "r") as f: data = json.load(f) data["base_model_name_or_path"] = "/opt/ml/model/llm/" # path to llm model in side Amazon SageMaker with open(os.path.join(tmp_dir, "config.json"), "w") as f_out: json.dump(data, indent=2, fp=f_out) # upload the model to s3 s3_path = S3Uploader.upload( local_path=tmp_dir, desired_s3_uri=f"s3://{sess.default_bucket()}/medusa/mixtral" )