Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using configuration for xla_device #1

Merged
merged 1 commit into from
Apr 9, 2020
Merged

Using configuration for xla_device #1

merged 1 commit into from
Apr 9, 2020

Conversation

LysandreJik
Copy link
Collaborator

Using the model configuration file is usually preferred to adding new arguments on methods such as save_pretrained/from_pretrained.

There is no addition to the examples/run_glue_tpu.py file as the xla_device=True flag was already specified to the configuration file. That's all that's needed now 🙂

Here's a brief explanation of how that would work:

from transformers import BertConfig, BertModel

config = BertConfig.from_pretrained("bert-base-cased", xla_config=True)  # config.xla_device == True
config.save_pretrained("directory")
config = BertConfig.from_pretrained("directory")  # config.xla_device == True
config = BertConfig.from_pretrained("directory", xla_device=False)  # config.xla_device == False

Here's how you would save/load using an XLA device:

from transformers import BertConfig, BertModel

# With that configuration flag the model is loaded automatically on TPU
config = BertConfig.from_pretrained("bert-base-cased", xla_config=True)
model = BertModel.from_pretrained("bert-base-cased", config=config)

# Saved automatically on TPU
model.save_pretrained("directory")

# If we want to load without TPU
config = BertConfig.from_pretrained("directory", xla_config=False)
model = BertModel.from_pretrained("directory", config=config)

It can be done simply as well without explicitly using the config:

from transformers import BertModel

model = BertModel.from_pretrained("bert-base-cased", xla_device=True)
model.config.xla_device  # True

@LysandreJik LysandreJik requested a review from jysohn23 April 9, 2020 15:03
Copy link
Owner

@jysohn23 jysohn23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it better too. Thanks!

@jysohn23 jysohn23 merged commit 306851c into tpu Apr 9, 2020
@jysohn23 jysohn23 deleted the tpu-with-config branch April 9, 2020 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants