kzl / decision-transformer

Official codebase for Decision Transformer: Reinforcement Learning via Sequence Modeling.
MIT License
2.33k stars 440 forks source link

AttributeError: 'GPT2Config' object has no attribute 'n_ctx' #56

Closed NuvoleY closed 1 year ago

NuvoleY commented 1 year ago

Traceback (most recent call last): File "D:\Python\Test\test\T\decision-transformer-master\gym\experiment.py", line 312, in experiment('gym-experiment', variant=vars(args)) File "D:\Python\Test\test\T\decision-transformer-master\gym\experiment.py", line 213, in experiment model = DecisionTransformer( File "D:\Python\Test\test\T\decision-transformer-master\gym\decision_transformer\models\decision_transformer.py", line 39, in init self.transformer = GPT2Model(config) File "D:\Python\Test\test\T\decision-transformer-master\gym\decision_transformer\models\trajectory_gpt2.py", line 522, in init self.h = nn.ModuleList([Block(config.nctx, config, scale=True) for in range(config.n_layer)]) File "D:\Python\Test\test\T\decision-transformer-master\gym\decision_transformer\models\trajectory_gpt2.py", line 522, in self.h = nn.ModuleList([Block(config.nctx, config, scale=True) for in range(config.n_layer)]) File "E:\Python\python3.10.5\lib\site-packages\transformers\configuration_utils.py", line 260, in getattribute return super().getattribute(key) AttributeError: 'GPT2Config' object has no attribute 'n_ctx'

yangfan293 commented 1 year ago

Hello, I also met the same problem, may I ask you how to solve it?

NanBorui commented 9 months ago

May I know how you solved this problem

arks22 commented 9 months ago

@NanBorui

This issue arises due to a version mismatch in huggingface/transformers. The n_ctx attribute has been either removed or altered in the newer versions of transformers, which is causing errors in this repository that uses an older version.

As specified in conda_env.yml, installing transformers==4.5.1 should resolve this issue.

If that's not feasible, you might be able to solve it by manually altering n_ctx, referencing this commit:

https://github.com/huggingface/transformers/commit/5b45422b58da508dab8b18852609a279517b944d.

feifei-feifei-hub commented 6 months ago

When I install transformers==4.5.1, another mistake happened "packaging.version.InvalidVersion: Invalid version: '0.10.1,<0.11'". And when I change transformers version to 4.4.2, the problem of "packaging.version" solved, but the ['n_ctx'] mistake is still alive.

lcjr86 commented 6 months ago

@feifei-feifei-hub try version transformers=4.12.5

Patricia1019 commented 4 months ago

if you are using a higher version of Transformers, change n_ctx to n_positions can solve this problem