MCPcopy Create free account
hub / github.com/modelscope/modelscope / put_file

Method put_file

modelscope/hub/utils/caching.py:369–390  ·  view source on GitHub ↗

Put model on model_file_location to cache, the model first download to /tmp, and move to cache. Args: model_file_info (str): The file description returned by get_model_files. model_file_location (str): The location of the temporary file. Returns:

(self, model_file_info, model_file_location)

Source from the content-addressed store, hash-verified

367 break
368
369 def put_file(self, model_file_info, model_file_location):
370 """Put model on model_file_location to cache, the model first download to /tmp, and move to cache.
371
372 Args:
373 model_file_info (str): The file description returned by get_model_files.
374 model_file_location (str): The location of the temporary file.
375
376 Returns:
377 str: The location of the cached file.
378 """
379 self.remove_if_exists(model_file_info)
380 cache_key = self.__get_cache_key(model_file_info)
381 cache_full_path = os.path.join(self.cache_root_location,
382 cache_key['Path'])
383 cache_file_dir = os.path.dirname(cache_full_path)
384 if not os.path.exists(cache_file_dir):
385 os.makedirs(cache_file_dir, exist_ok=True)
386 move(model_file_location, cache_full_path)
387 with self._cache_lock:
388 self.cached_files.append(cache_key)
389 self._save_cached_files_unlocked()
390 return cache_full_path

Callers

nothing calls this directly

Calls 5

remove_if_existsMethod · 0.95
__get_cache_keyMethod · 0.95
existsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected