sagemaker-python-sdk icon indicating copy to clipboard operation
sagemaker-python-sdk copied to clipboard

Sagemaker Error in Local Mode

Open simonloveslife opened this issue 8 years ago • 8 comments

System Information

  • Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans): MXNET
  • Framework Version: 1.2
  • Python Version:2.7
  • CPU or GPU: CPU
  • Python SDK Version:1.8
  • Are you using a custom image:

Describe the problem

I am trying to run MXNet estimator in local mode, on my laptop, code is like this , got error ValueError: Expecting 's3' scheme, got: file in file://home/name/no_code

code_location = 'file://home/name/no_code' model_location = 'file://home/name/no_model' local_data = 'file://home/name/no_data/'

sg_estimator = MXNet(entry_point=entry_point, role=role, train_instance_count=1, train_instance_type='local', hyperparameters={'learning_rate':0.1}, code_location = code_location, output_path =model_location ) sg_estimator.fit(local_data)

it seems like the estimator is still looking for S3. Then I deeply dived , in this file test-runtime/lib/python2.7/site-packages/sagemaker/estimator.py", it turns out “local_code” is None and it switched to s3.

local_code = get_config_value('local.local_code', self.sagemaker_session.config) if self.sagemaker_session.local_mode and local_code: # if there is no source dir, use the directory containing the entry point. if self.source_dir is None: self.source_dir = os.path.dirname(self.entry_point) self.entry_point = os.path.basename(self.entry_point)

code_dir = 'file://' + self.source_dir
script = self.entry_point

else: self.uploaded_code = self._stage_user_code_in_s3() code_dir = self.uploaded_code.s3_prefix script = self.uploaded_code.script_name

Then I looked into how self.sagemaker_seesion.config is created, I found it loaded a YAML file, I checked the file and it’s empty.

sagemaker_config_file = os.path.join(os.path.expanduser('~'), '.sagemaker', 'config.yaml') if os.path.exists(sagemaker_config_file): self.config = yaml.load(open(sagemaker_config_file, 'r'))

I also searched sagemaker_config_file online, and didn’t find anything.

simonloveslife avatar Oct 03 '18 01:10 simonloveslife

I might be wrong but I think you can try file:///home/name/no_code

derekhh avatar Oct 03 '18 01:10 derekhh

Thanks @derekhh ,I tried, still got same error

simonloveslife avatar Oct 03 '18 06:10 simonloveslife

Hi @simonloveslife

Using local code is kind of an experimental feature which is why its not fully documented yet. You can use it if you write the yaml config file.

$ cat ~/.sagemaker/config.yaml

local:
    local_code: True

iquintero avatar Oct 03 '18 18:10 iquintero

Thanks! @iquintero I am curious what params should I set in the estimator to avoid doing those configurations? I mean don't use "local_code" but use other logic to let code figure out the mode.

simonloveslife avatar Oct 03 '18 19:10 simonloveslife

@simonloveslife,

If you plan on using local_code, then as of now there isn't a workaround other than to manipulate the YAML file itself, if you don't wish to modify your python code.

You can also override the config with the local value, as shown in this unit test

ChoiByungWook avatar Oct 04 '18 18:10 ChoiByungWook

@ChoiByungWook Thanks, I am wondering how should I modify my python code so I can get rid of the local_code, but the model still runs in local mode?

simonloveslife avatar Oct 04 '18 19:10 simonloveslife

After talking to Nacho and Dan, Here are two options to resolve this issue, the first one is what mentioned above, $ cat ~/.sagemaker/config.yaml local: local_code: True

The second option is assigning config to a local session and pass this session into the estimator.

local_session = LocalSession() lcoal_session.config = {'local': 'local_code': True }}

… estimator = Estimator(……, sagemaker_session=local_session)

simonloveslife avatar Oct 04 '18 21:10 simonloveslife

Hi, where is ~/.sagemaker/config.yaml? I don't seem to have this in my SM notebook instance.

austinmw avatar Feb 29 '20 19:02 austinmw