`BartForConditionalGeneration` has no attribute `shared`
Author: shivanraptor
Pull request: no

### System Info

- `transformers` version: 4.28.1
- Platform: Linux-5.5.19-050519-generic-x86_64-with-glibc2.27
- Python version: 3.9.7
- Huggingface_hub version: 0.21.4
- Safetensors version: 0.4.2
- PyTorch version (GPU?): 2.2.2+cu121 (True)
- Tensorflow version (GPU?): 2.14.0 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

### Who can help?

@patrickvonplaten @Narsil

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

I override `BartForConditionalGeneration` to map my custom Tokenizer's IDs to re-train / fine-tune a pre-trained model. Codes here:

```
class CantoneseModel(BartForConditionalGeneration):
    def __init__(self, config):
        super().__init__(config)
    
    def _prepare_decoder_inputs_lengths(self, shape):
        """Prepares lengths tensor for decoder."""
        if len(shape) < 2:
            raise ValueError("Expected at least 2 dimensions")
        batch_size, seq_length = shape[:2]
        effective_batch_size = max(batch_size // (torch.cuda.device_count() > 0), 1)
        length = torch.full((effective_batch_size,), seq_length, device=self.device)
        return length
    
    def forward(self, input_ids, **kwargs):
        input_shape = input_ids.size()
        src_key_padding_mask = self._prepare_decoder_inputs_lengths(input_shape)[0]

        input_ids = input_ids.long().cuda()
        input_embeds = self.shared(input_ids)
        
        # fix "token_type_ids" bug
        if 'token_type_ids' in kwargs:
            del kwargs['token_type_ids']
        
        return super().forward(input_ids, input_embeds = input_embeds, **kwargs)
```

and load my custom model using these codes:

```
model = CantoneseModel(BartConfig.from_pretrained('fnlp/bart-base-chinese')).half().cuda()
model.resize_token_embeddings(len(tokenizer))
model.config.vocab_size = len(tokenizer)
```
which the `tokenizer` is my custom tokenizer.

Here are the training arguments:

```
training_args = Seq2SeqTrainingArguments(
    # Accumulated Gradient 
    gradient_accumulation_steps = 4, 
    gradient_checkpointing = True,
    output_dir = output_model_name,
    evaluation_strategy = "epoch",
    optim = "adamw_torch",
    eval_steps = steps,
    save_strategy = "epoch",
    learning_rate = 2e-5,
    per_device_train_batch_size = batch_size,
    per_device_eval_batch_size = batch_size,
    weight_decay = 0.01,
    save_total_limit = 1,
    num_train_epochs = 30,
    predict_with_generate = True,
    remove_unused_columns = True,
    fp16 = True, # save memory
    metric_for_best_model = "bleu",
    load_best_model_at_end = True,
    report_to = "wandb",
    push_to_hub = True,
    save_safetensors = True
)

trainer = Seq2SeqTrainer(
    model = model,
    args = training_args,
    train_dataset = tokenized_train_set,
    eval_dataset = tokenized_eval_set,
    tokenizer = tokenizer,
    data_collator = data_collator,
    compute_metrics = compute_metrics,
    callbacks = [EarlyStoppingCallback(early_stopping_patience=3)],
)
```

When I execute `trainer.train()`, it shows:

> AttributeError: 'CantoneseModel' object has no attribute 'shared'

### Expected behavior

The training has no error (as if I don't override the `BartForConditionalGeneration` class, the error does not appear).

Comments:
Hi, thanks for raising an issue! 

This is a question best placed in our [forums](https://discuss.huggingface.co/). We try to reserve the github issues for feature requests and bug reports.

For the error, please share the full traceback, not just the error message, as this provides context which is often enough to resolve the issue, in particular showing from which line of code the error was triggered 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.