Domain adaptation (DA) aims to transfer the knowledge learned from a sourcedomain to an unlabeled target domain. Some recent works tackle source-freedomain adaptation (SFDA) where only a source pre-trained model is available foradaptation to the target domain. However, those methods do not consider keepingsource performance which is of high practical value in real world applications.In this paper, we propose a new domain adaptation paradigm called GeneralizedSource-free Domain Adaptation (G-SFDA), where the learned model needs toperform well on both the target and source domains, with only access to currentunlabeled target data during adaptation. First, we propose local structureclustering (LSC), aiming to cluster the target features with its semanticallysimilar neighbors, which successfully adapts the model to the target domain inthe absence of source data. Second, we propose sparse domain attention (SDA),it produces a binary domain specific attention to activate different featurechannels for different domains, meanwhile the domain attention will be utilizedto regularize the gradient during adaptation to keep source information. In theexperiments, for target performance our method is on par with or better thanexisting DA and SFDA methods, specifically it achieves state-of-the-artperformance (85.4%) on VisDA, and our method works well for all domains afteradapting to single or multiple target domains. Code is available inhttps://github.com/Albert0147/G-SFDA.